-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bugfix, ui] Allow running jobs from a namespace-limited token #13659
Merged
Merged
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d03b99c
Allow running jobs from a namespace-limited token
philrenaud f14d703
qpNamespace cleanup
philrenaud 81c1a62
Looks like parse can deal with a * namespace
philrenaud b6ea5da
A little diff cleanup
philrenaud 0b22998
Defensive destructuring
philrenaud cd1eea1
Removing accidental friendly-fire on can-scale
philrenaud 66a4edc
Testfix: Job run buttons from jobs index
philrenaud e9717a7
Testfix: activeRegion job adapter string
philrenaud 7939bb8
Testfix: unit tests for job abilities correctly reflect the any-names…
philrenaud fce54f9
Testfix: job editor test looks for requests with namespace applied on…
philrenaud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import AbstractAbility from './abstract'; | ||
import { computed } from '@ember/object'; | ||
import { computed, get } from '@ember/object'; | ||
import { or } from '@ember/object/computed'; | ||
|
||
export default class Job extends AbstractAbility { | ||
|
@@ -27,9 +27,30 @@ export default class Job extends AbstractAbility { | |
) | ||
canDispatch; | ||
|
||
@computed('[email protected]') | ||
policyNamespacesIncludePermissions(policies = [], permissions = []) { | ||
// For each policy record, extract all policies of all namespaces | ||
const allNamespacePolicies = policies | ||
.toArray() | ||
.map((policy) => get(policy, 'rulesJSON.Namespaces')) | ||
.flat() | ||
.map(({ Capabilities }) => { | ||
return Capabilities; | ||
}) | ||
.flat() | ||
.compact(); | ||
|
||
// Check for requested permissions | ||
return allNamespacePolicies.some((policy) => { | ||
return permissions.includes(policy); | ||
}); | ||
} | ||
|
||
@computed('token.selfTokenPolicies.[]') | ||
get policiesSupportRunning() { | ||
return this.namespaceIncludesCapability('submit-job'); | ||
return this.policyNamespacesIncludePermissions( | ||
this.token.selfTokenPolicies, | ||
['submit-job'] | ||
); | ||
} | ||
|
||
@computed('[email protected]') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,56 @@ | ||
import Controller from '@ember/controller'; | ||
import { inject as service } from '@ember/service'; | ||
import { computed } from '@ember/object'; | ||
import { scheduleOnce } from '@ember/runloop'; | ||
import { serialize } from 'nomad-ui/utils/qp-serialize'; | ||
import { get, set } from '@ember/object'; | ||
|
||
export default class RunController extends Controller { | ||
@service router; | ||
@service system; | ||
@service store; | ||
|
||
queryParams = [ | ||
{ | ||
qpNamespace: 'namespace', | ||
}, | ||
]; | ||
|
||
onSubmit(id, namespace) { | ||
this.router.transitionTo('jobs.job', `${id}@${namespace || 'default'}`); | ||
} | ||
@computed('qpNamespace') | ||
get optionsNamespaces() { | ||
const availableNamespaces = this.store | ||
.peekAll('namespace') | ||
.map((namespace) => ({ | ||
key: namespace.name, | ||
label: namespace.name, | ||
})); | ||
|
||
availableNamespaces.unshift({ | ||
key: '*', | ||
label: 'All (*)', | ||
}); | ||
|
||
// Unset the namespace selection if it was server-side deleted | ||
if (!availableNamespaces.mapBy('key').includes(this.qpNamespace)) { | ||
scheduleOnce('actions', () => { | ||
// eslint-disable-next-line ember/no-side-effects | ||
set(this, 'qpNamespace', '*'); | ||
}); | ||
} | ||
|
||
return availableNamespaces; | ||
} | ||
|
||
setFacetQueryParam(queryParam, selection) { | ||
this.set(queryParam, serialize(selection)); | ||
const model = get(this, 'model'); | ||
set( | ||
model, | ||
'namespace', | ||
this.store.peekAll('namespace').find((ns) => ns.id === this.qpNamespace) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,21 @@ | ||
<Breadcrumb @crumb={{hash label="Run" args=(array "jobs.run")}} /> | ||
{{page-title "Run a job"}} | ||
<section class="section"> | ||
<div class="toolbar"> | ||
<div class="toolbar-item is-right-aligned is-mobile-full-width"> | ||
<div class="button-bar"> | ||
{{#if this.system.shouldShowNamespaces}} | ||
<SingleSelectDropdown | ||
data-test-namespace-facet | ||
@label="Namespace" | ||
@options={{this.optionsNamespaces}} | ||
@selection={{this.qpNamespace}} | ||
@onSelect={{action this.setFacetQueryParam "qpNamespace"}} | ||
/> | ||
{{/if}} | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<JobEditor @job={{this.model}} @context="new" @onSubmit={{action this.onSubmit}} /> | ||
</section> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgive the naming conventions (qpNamespace, queryParam, etc.) - will revise. Was pullig from jobs/volumes routes.