Skip to content
This repository has been archived by the owner on May 28, 2023. It is now read-only.

Commit

Permalink
allow non-primary community admins to edit user roles and reactivate …
Browse files Browse the repository at this point in the history
…friends in their communities
  • Loading branch information
CZagrobelny committed Jun 18, 2021
1 parent 3e7a38f commit 555b994
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion app/controllers/admin/friends_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Admin::FriendsController < AdminController
before_action :require_access_to_region, only: [:reactivate]
before_action :require_access_to_region_or_non_primary_community_admin, only: [:reactivate]
before_action :restrict_access_to_archived_friend, only: [:edit, :update, :destroy]

def index
Expand Down Expand Up @@ -210,6 +210,13 @@ def update_friend_params
update_friend_params
end

def require_access_to_region_or_non_primary_community_admin
return if current_user.can_access_region?(current_region)
return if current_user.admin? && !current_community.primary?

not_found
end

def current_tab
# TODO: See if params[:tab] is ever an empty string, otherwise can remove the presence
params[:tab].presence || '#basic'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def update
@user = current_community.users.find(params[:id])
ActiveRecord::Base.transaction do
@user.update!(
current_user.can_access_region?(current_region) ? user_params : user_params_excluding_role
current_user.can_access_region?(current_region) || !current_community.primary? ? user_params : user_params_excluding_role
)
if current_user.can_access_region?(current_region) && password_params.present?
unless @user.reset_password(password_params[:password], password_params[:password])
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/friends/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<ul class='dropdown-menu'>
<li><%= link_to 'Delete', community_admin_friend_path(current_community.slug, friend), method: :delete, confirm: true %></li>
</ul>
<% elsif current_user.can_access_region?(current_region) %>
<% elsif current_user.can_access_region?(current_region) || (current_user.admin? && !current_community.primary?) %>
<%= link_to 'Reactivate', reactivate_community_admin_friend_path(friend.community.slug, friend), method: :patch %>
<% else %>
Archived
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/users/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<% end %>
</div>

<% if current_user.can_access_region?(current_region) %>
<% if current_user.can_access_region?(current_region) || !current_community.primary? %>
<% available_roles = current_community.primary? ? User::PRIMARY_ROLES : User::NON_PRIMARY_ROLES %>
<div class='form-group'>
<%= f.label :role, class: 'col-md-2 control-label required' %>
Expand Down

0 comments on commit 555b994

Please sign in to comment.