-
Notifications
You must be signed in to change notification settings - Fork 1
Giving Users Custom Abilities
jkim-ru edited this page Jan 8, 2018
·
1 revision
With the migration from Hyrax Gem 1.0.4 to 2.0.0, I found the need to add back the ability of admins to be able to manage users. In order to do that, I added some code to the ability model here:
https://github.com/dibbs-vdc/ccql/blob/feature/59/hyrax-2-migration/app/models/ability.rb#L21-L23
if admin?
can [:manage], User
end
Then, if the user had the ability to manage a user, then I checked for that ability in the code. For example, I could show admin capabilities in the dashboard sidebar based on whether or not a user could manage another user:
<% if can? :manage, User %>
<%= menu.nav_link(hyrax.admin_users_path) do %>
<span class="fa fa-user"></span> <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.users') %></span>
<% end %>
<%= menu.nav_link(hyrax.admin_vdc_pending_registrations_path) do %>
<span class="fa fa-users"></span> <span class="sidebar-action-text"><%= t('hyrax.admin.sidebar.registration_approval') %></span>
<% end %>
<% end %>