Skip to content

Commit

Permalink
refactoring for same regression in job versions
Browse files Browse the repository at this point in the history
In job versions, if you have an ACL token with a write policy
you should be able to revert a job, however, that was not the
case here. This is because we're using ember-can to check if
the user can run a job. That permission relies on policiesSupportRunning
which uses a function called namespaceIncludesCapability. We're going to
need to refactor any cases that use this function.
  • Loading branch information
ChaiWithJai committed Jul 15, 2021
1 parent d92261e commit 91f2793
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
6 changes: 6 additions & 0 deletions ui/app/controllers/jobs/job/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export default class VersionsController extends Controller.extend(WithNamespaceR

@alias('model') job;

queryParams = [
{
jobNamespace: { as: 'other-jobNamespace' },
},
];

@computed('error.level')
get errorLevelClass() {
return errorLevelToAlertClass[this.get('error.level')] || alertClassFallback;
Expand Down
20 changes: 11 additions & 9 deletions ui/app/routes/jobs/job/versions.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import Route from '@ember/routing/route';
import { collect } from '@ember/object/computed';
import { watchRecord, watchRelationship } from 'nomad-ui/utils/properties/watch';
import {
watchAll,
watchRecord,
watchQuery,
watchRelationship,
} from 'nomad-ui/utils/properties/watch';
import WithWatchers from 'nomad-ui/mixins/with-watchers';

export default class VersionsRoute extends Route.extend(WithWatchers) {
model() {
const job = this.modelFor('jobs.job');
return job && job.get('versions').then(() => job);
}

startWatchers(controller, model) {
if (model) {
controller.set('namespacesWatch', this.watchNamespaces.perform());
controller.set('modelWatch', this.watchJobs.perform({ namespace: controller.jobNamespace }));
controller.set('watcher', this.watch.perform(model));
controller.set('watchVersions', this.watchVersions.perform(model));
}
}

@watchAll('namespace') watchNamespaces;
@watchRecord('job') watch;
@watchQuery('job') watchJobs;
@watchRelationship('versions') watchVersions;

@collect('watch', 'watchVersions') watchers;
@collect('watch', 'watchJobs', 'watchVersions') watchers;
}
2 changes: 1 addition & 1 deletion ui/app/templates/components/job-version.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</span>
<div class="pull-right">
{{#unless this.isCurrent}}
{{#if (can "run job")}}
{{#if (can "run job" namespace=this.jobNamespace)}}
<TwoStepButton
data-test-revert-to
@classes={{hash
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/components/job-versions-stream.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
</li>
{{/if}}
<li data-test-version class="timeline-object">
<JobVersion @version={{record.version}} @verbose={{this.verbose}} @handleError={{@handleError}} />
<JobVersion @jobNamespace={{this.jobNamespace}} @version={{record.version}} @verbose={{this.verbose}} @handleError={{@handleError}} />
</li>
{{/each}}
2 changes: 1 addition & 1 deletion ui/app/templates/jobs/job/versions.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
</div>
{{/if}}

<JobVersionsStream @versions={{this.model.versions}} @verbose={{true}} @handleError={{action this.handleError}} />
<JobVersionsStream @jobNamespace={{this.jobNamespace}} @versions={{this.model.versions}} @verbose={{true}} @handleError={{action this.handleError}} />
</section>

0 comments on commit 91f2793

Please sign in to comment.