Skip to content

Commit

Permalink
Add pundit policy for workflow_run show view
Browse files Browse the repository at this point in the history
  • Loading branch information
krauselukas committed Jan 24, 2022
1 parent f6670ee commit d998aea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/api/app/policies/workflow_run_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ def resolve

attr_reader :user, :scope, :opts
end

def show?
record.token.user == user
end
end
19 changes: 15 additions & 4 deletions src/api/spec/policies/workflow_run_policy_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
require 'rails_helper'

RSpec.describe WorkflowRunPolicy do
let(:token_user) { create(:confirmed_user, login: 'foo') }
let(:workflow_token) { create(:workflow_token, user: token_user) }
let!(:workflow_run) { create(:workflow_run, token: workflow_token) }

describe '#resolve' do
subject { WorkflowRunPolicy::Scope }

let(:token_user) { create(:confirmed_user, login: 'foo') }
let(:workflow_token) { create(:workflow_token, user: token_user) }
let!(:workflow_run) { create(:workflow_run, token: workflow_token) }

before do
User.session = token_user
end
Expand Down Expand Up @@ -36,4 +36,15 @@
end
end
end

permissions :show? do
subject { WorkflowRunPolicy }

let(:anonymous_user) { create(:user_nobody) }
let(:user_without_permission) { create(:confirmed_user) }

it { is_expected.to permit(token_user, workflow_run) }
it { is_expected.not_to permit(anonymous_user, workflow_run) }
it { is_expected.not_to permit(user_without_permission, workflow_run) }
end
end

0 comments on commit d998aea

Please sign in to comment.