From 91f27931b059ad4305ced17fa2f3507f9309a3c9 Mon Sep 17 00:00:00 2001 From: Jai Bhagat Date: Wed, 14 Jul 2021 16:27:24 -0400 Subject: [PATCH] refactoring for same regression in job versions 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. --- ui/app/controllers/jobs/job/versions.js | 6 ++++++ ui/app/routes/jobs/job/versions.js | 20 ++++++++++--------- ui/app/templates/components/job-version.hbs | 2 +- .../components/job-versions-stream.hbs | 2 +- ui/app/templates/jobs/job/versions.hbs | 2 +- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/ui/app/controllers/jobs/job/versions.js b/ui/app/controllers/jobs/job/versions.js index 087100ea0396..9a7219901d7b 100644 --- a/ui/app/controllers/jobs/job/versions.js +++ b/ui/app/controllers/jobs/job/versions.js @@ -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; diff --git a/ui/app/routes/jobs/job/versions.js b/ui/app/routes/jobs/job/versions.js index 2923c321c77b..a904bc47ba18 100644 --- a/ui/app/routes/jobs/job/versions.js +++ b/ui/app/routes/jobs/job/versions.js @@ -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; } diff --git a/ui/app/templates/components/job-version.hbs b/ui/app/templates/components/job-version.hbs index fc219e964cda..2230ba11ad87 100644 --- a/ui/app/templates/components/job-version.hbs +++ b/ui/app/templates/components/job-version.hbs @@ -10,7 +10,7 @@
{{#unless this.isCurrent}} - {{#if (can "run job")}} + {{#if (can "run job" namespace=this.jobNamespace)}} {{/if}}
  • - +
  • {{/each}} diff --git a/ui/app/templates/jobs/job/versions.hbs b/ui/app/templates/jobs/job/versions.hbs index d6829bd849cd..30c583693a08 100644 --- a/ui/app/templates/jobs/job/versions.hbs +++ b/ui/app/templates/jobs/job/versions.hbs @@ -15,5 +15,5 @@
    {{/if}} - +