Skip to content
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

Add social settings access ability #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/models/spree/social_authentication_abilities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Spree::SocialAuthenticationAbilities

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing magic comment # frozen_string_literal: true.
Use nested module/class definitions instead of compact style.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing magic comment # frozen_string_literal: true.
Use nested module/class definitions instead of compact style.

include CanCan::Ability

def initialize(user)
if user.respond_to?(:has_spree_role?) && user.has_spree_role?('admin')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

can :manage, Spree::SocialConfiguration
end
end
end
2 changes: 1 addition & 1 deletion app/overrides/add_socials_to_admin_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
virtual_path: 'spree/admin/shared/sub_menu/_configuration',
name: 'add_social_providers_link_configuration_menu',
insert_bottom: '[data-hook="admin_configurations_sidebar_menu"]',
text: '<%= configurations_sidebar_menu_item Spree.t(:social_authentication_methods), spree.admin_authentication_methods_path %>'
text: '<%= configurations_sidebar_menu_item(Spree.t(:social_authentication_methods), spree.admin_authentication_methods_path) if can?(:manage, Spree::SocialConfiguration) %>'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Line is too long. [176/80]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Line is too long. [176/80]

)
2 changes: 2 additions & 0 deletions lib/spree_social/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def self.activate
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end

Spree::Ability.register_ability(Spree::SocialAuthenticationAbilities)
end

config.to_prepare(&method(:activate).to_proc)
Expand Down
19 changes: 19 additions & 0 deletions spec/models/spree/social_authentication_abilities_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'cancan/matchers'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing magic comment # frozen_string_literal: true.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing magic comment # frozen_string_literal: true.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


RSpec.describe Spree::SocialAuthenticationAbilities, type: :model do
describe 'social configuration settings' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

subject { described_class.new(user) }

context 'when is ordinal user' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

let(:user) { build_stubbed(:user) }

it { is_expected.not_to be_able_to(:manage, Spree::SocialConfiguration) }
end

context 'when is admin' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

let(:user) { build_stubbed(:admin_user) }

it { is_expected.to be_able_to(:manage, Spree::SocialConfiguration) }
end
end
end