-
Notifications
You must be signed in to change notification settings - Fork 102
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
changed decorator files and updated migrations #62
Open
rishabhguptarishi
wants to merge
3
commits into
master
Choose a base branch
from
update_version_one
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module SpreeAdminRolesAndAccess | ||
module RoleDecorator | ||
|
||
def self.prepended(base) | ||
base.has_many :roles_permission_sets, dependent: :destroy | ||
base.has_many :permission_sets, through: :roles_permission_sets | ||
base.has_many :permissions, through: :permission_sets | ||
|
||
# DEPRECATED: Use permission sets instead. Only here for aiding migration for existing users | ||
base.has_and_belongs_to_many :legacy_permissions, join_table: 'spree_roles_permissions', class_name: 'Spree::Permission' | ||
|
||
base.validates :name, uniqueness: true, allow_blank: true | ||
base.validates :permission_sets, length: { minimum: 1, too_short: :atleast_one_permission_set_is_required }, on: :update | ||
base.scope :default_role, lambda { where(is_default: true) } | ||
end | ||
|
||
def has_permission?(permission_title) | ||
permissions.pluck(:title).include?(permission_title) | ||
end | ||
|
||
end | ||
end | ||
|
||
Spree::Role.prepend SpreeAdminRolesAndAccess::RoleDecorator |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module SpreeAdminRolesAndAccess | ||
module UserDecorator | ||
def self.prepended(base) | ||
base.alias_attribute :roles, :spree_roles | ||
end | ||
end | ||
end | ||
|
||
Spree.user_class.prepend SpreeAdminRolesAndAccess::UserDecorator |
29 changes: 29 additions & 0 deletions
29
lib/controllers/backend/spree/admin/base_controller_decorator.rb
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Spree::Admin | ||
module BaseControllerDecorator | ||
def authorize_admin | ||
begin | ||
if params[:id] | ||
record = model_class.where(PARAM_ATTRIBUTE[controller_name] => params[:id]).first | ||
elsif new_action? | ||
record = model_class.new | ||
else | ||
record = model_class | ||
end | ||
raise if record.blank? | ||
rescue | ||
record = "#{params[:controller]}" | ||
end | ||
authorize! :admin, record | ||
authorize_with_attributes! params[:action].to_sym, record, params[controller_name.singularize] | ||
end | ||
|
||
private | ||
def unauthorized | ||
redirect_unauthorized_access | ||
end | ||
|
||
def new_action? | ||
NEW_ACTIONS.include?(params[:action].to_sym) | ||
end | ||
end | ||
Spree::Admin::BaseController.prepend Spree::Admin::BaseControllerDecorator |
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 |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
let(:permission17) { Spree::Permission.create(title: 'can-create-spree/products', priority: 3) } | ||
let(:permission_set) { Spree::PermissionSet.create!(name: 'test') } | ||
|
||
let(:user) { Spree::User.create!(email: '[email protected]', password: '123456') } | ||
let(:user) { Spree.user_class.create!(email: '[email protected]', password: '123456') } | ||
let(:role) { Spree::Role.where(name: 'user').first_or_create! } | ||
let(:roles) { [role] } | ||
|
||
|
@@ -125,8 +125,8 @@ | |
it_should_behave_like 'access denied' | ||
it_should_behave_like 'no index allowed' | ||
it_should_behave_like 'default admin permissions' | ||
it { expect(new_ability).to_not be_able_to :create, Spree::User, :role_ids } | ||
it { expect(new_ability).to_not be_able_to :update, Spree::User, :role_ids } | ||
it { expect(new_ability).to_not be_able_to :create, Spree.user_class, :role_ids } | ||
it { expect(new_ability).to_not be_able_to :update, Spree.user_class, :role_ids } | ||
end | ||
|
||
context 'with warehouse_admin user' do | ||
|
@@ -166,11 +166,11 @@ | |
let(:resource) { Object.new } | ||
let(:resource_shipment) { Spree::Shipment.new } | ||
let(:resource_product) { Spree::Product.new } | ||
let(:resource_user) { Spree::User.new } | ||
let(:resource_user) { Spree.user_class.new } | ||
let(:resource_order) { Spree::Order.new } | ||
let(:fakedispatch_user) { Spree::User.new } | ||
let(:fakedispatch_user) { Spree.user_class.new } | ||
let(:admin_role) { Spree::Role.where(name: 'admin').first_or_create! } | ||
let(:user1) { Spree::User.new } | ||
let(:user1) { Spree.user_class.new } | ||
let(:ability) { Spree::Ability.new(user) } | ||
|
||
context 'with admin user' do | ||
|
@@ -262,7 +262,7 @@ | |
it_should_behave_like 'access granted' | ||
end | ||
context 'requested by other user' do | ||
let(:resource) { Spree::User.new } | ||
let(:resource) { Spree.user_class.new } | ||
it_should_behave_like 'create only' | ||
end | ||
end | ||
|
@@ -276,7 +276,7 @@ | |
end | ||
|
||
context 'requested by other user' do | ||
before(:each) { resource.user = Spree::User.new } | ||
before(:each) { resource.user = Spree.user_class.new } | ||
it_should_behave_like 'create only' | ||
end | ||
|
||
|
@@ -325,12 +325,12 @@ | |
end | ||
|
||
it 'should receive new on Spree::User when there is no user passed' do | ||
expect(Spree::User).to receive(:new).and_return(user) | ||
expect(Spree.user_class).to receive(:new).and_return(user) | ||
Spree::Ability.new(nil) | ||
end | ||
|
||
it 'should not receive new on Spree::User when there is no user passed' do | ||
expect(Spree::User).to_not receive(:new) | ||
expect(Spree.user_class).to_not receive(:new) | ||
Spree::Ability.new(user) | ||
end | ||
|
||
|
@@ -359,10 +359,10 @@ | |
|
||
subject { ability } | ||
|
||
it { expect(subject).to be_able_to :create, Spree::User.new } | ||
it { expect(subject).to be_able_to :update, Spree::User.new } | ||
it { expect(subject).to_not be_able_to :create, Spree::User.new, :role_ids } | ||
it { expect(subject).to_not be_able_to :update, Spree::User.new, :role_ids } | ||
it { expect(subject).to be_able_to :create, Spree.user_class.new } | ||
it { expect(subject).to be_able_to :update, Spree.user_class.new } | ||
it { expect(subject).to_not be_able_to :create, Spree.user_class.new, :role_ids } | ||
it { expect(subject).to_not be_able_to :update, Spree.user_class.new, :role_ids } | ||
end | ||
end | ||
|
||
|
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
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.
Lets discuss