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

Allow only enterprise managers to connect apps #12507

Merged
Merged
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
4 changes: 4 additions & 0 deletions app/helpers/admin/enterprises_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def select_only_item(producers)
producers.size == 1 ? producers.first.id : nil
end

def managed_by_user?(enterprise)
enterprise.in?(spree_current_user.enterprises)
end

def enterprise_side_menu_items(enterprise)
is_shop = enterprise.sells != "none"
show_properties = !!enterprise.is_primary_producer
Expand Down
4 changes: 3 additions & 1 deletion app/views/admin/enterprises/form/_connected_apps.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
%p= t ".tagline"
%div
- if enterprise.connected_apps.empty?
= button_to t(".enable"), admin_enterprise_connected_apps_path(enterprise.id), method: :post
= button_to t(".enable"), admin_enterprise_connected_apps_path(enterprise.id), method: :post, disabled: !managed_by_user?(enterprise)
-# This is only seen by super-admins:
%em= t(".need_to_be_manager") unless managed_by_user?(enterprise)
- elsif enterprise.connected_apps.connecting.present?
%button{ disabled: true }
%i.spinner.fa.fa-spin.fa-circle-o-notch
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,7 @@ en:
enable: "Allow data sharing"
disable: "Stop sharing"
loading: "Loading"
need_to_be_manager: "Only managers can connect apps."
Copy link
Member

Choose a reason for hiding this comment

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

Would this be a more helpful explanation? Helps work out how to solve the problem.

Suggested change
need_to_be_manager: "Only managers can connect apps."
need_to_be_manager: "You cannot connect an app because you are not a manager of this enterprise."

Copy link
Member Author

Choose a reason for hiding this comment

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

That would probably be more helpful. I kept it short because it fits better in that space. It's only seen by super-admins and therefore I wouldn't put too much effort into the message.

note: |
Your Open Food Network account is connected to Discover Regenerative.
Add or update information on your Discover Regenerative listing here.
Expand Down
10 changes: 10 additions & 0 deletions spec/system/admin/enterprises/connected_apps_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,14 @@
expect(page).not_to have_content "account is connected"
expect(page).not_to have_link "Manage listing"
end

it "can't be enabled by non-manager" do
login_as create(:admin_user)

visit "#{edit_admin_enterprise_path(enterprise)}#/connected_apps_panel"
expect(page).to have_content "Discover Regenerative"

expect(page).to have_button("Allow data sharing", disabled: true)
expect(page).to have_content "Only managers can connect apps."
end
end
Loading