feat(lifecycle): add Pundit policies for rule/config/delivery
This commit is contained in:
parent
b29b35465b
commit
7d21530bc7
@ -0,0 +1,9 @@
|
||||
class Captain::Lifecycle::ConfigPolicy < ApplicationPolicy
|
||||
def show?
|
||||
true
|
||||
end
|
||||
|
||||
def update?
|
||||
@account_user.administrator?
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,9 @@
|
||||
class Captain::Lifecycle::DeliveryPolicy < ApplicationPolicy
|
||||
def index?
|
||||
true
|
||||
end
|
||||
|
||||
def show?
|
||||
true
|
||||
end
|
||||
end
|
||||
21
enterprise/app/policies/captain/lifecycle/rule_policy.rb
Normal file
21
enterprise/app/policies/captain/lifecycle/rule_policy.rb
Normal file
@ -0,0 +1,21 @@
|
||||
class Captain::Lifecycle::RulePolicy < ApplicationPolicy
|
||||
def index?
|
||||
true
|
||||
end
|
||||
|
||||
def show?
|
||||
true
|
||||
end
|
||||
|
||||
def create?
|
||||
@account_user.administrator?
|
||||
end
|
||||
|
||||
def update?
|
||||
@account_user.administrator?
|
||||
end
|
||||
|
||||
def destroy?
|
||||
@account_user.administrator?
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,32 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Captain::Lifecycle::RulePolicy, type: :policy do
|
||||
subject { described_class }
|
||||
|
||||
let(:account) { create(:account) }
|
||||
let(:admin) { create(:user, account: account, role: :administrator) }
|
||||
let(:agent) { create(:user, account: account, role: :agent) }
|
||||
let(:admin_context) { { user: admin, account: account, account_user: admin.account_users.first } }
|
||||
let(:agent_context) { { user: agent, account: account, account_user: agent.account_users.first } }
|
||||
let(:record) { Captain::Lifecycle::Rule.new(account: account) }
|
||||
|
||||
permissions :index?, :show? do
|
||||
context 'when user is administrator' do
|
||||
it { expect(subject).to permit(admin_context, record) }
|
||||
end
|
||||
|
||||
context 'when user is agent' do
|
||||
it { expect(subject).to permit(agent_context, record) }
|
||||
end
|
||||
end
|
||||
|
||||
permissions :create?, :update?, :destroy? do
|
||||
context 'when user is administrator' do
|
||||
it { expect(subject).to permit(admin_context, record) }
|
||||
end
|
||||
|
||||
context 'when user is agent' do
|
||||
it { expect(subject).not_to permit(agent_context, record) }
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user