Installing the Hydra Role Management Gem and Creating Admins - UW-Libraries/druw GitHub Wiki
After getting your Hyrax VM set up, you can install the hydra-role-management gem as follows:
-
Shutdown your rails server (maybe not necessary but that's how I installed it)
-
Add the following to the end of your Gemfile:
gem 'hydra-role-management'
-
Install the gem
bundle install
-
Generate the roles
rails generate roles
-
Migrate the database
rails db:migrate
-
Open the file
app/models/ability.rb
in an editor and add the following code where indicated:def custom_permissions ... if current_user.admin? can [:create, :show, :add_user, :remove_user, :index, :edit, :update, :destroy], Role end end
The first administrator you create can only created via the command line as follows:
-
Open the rails console
rails c
-
The following code creates the Admin role and adds your user to it
admin = Role.create(name: "admin") u = User.find_by_user_key( "[email protected]" ) admin.users << u admin.save
-
Confirm that the user was made an admin
u.admin?
The above code should return a
true
value.
To add other users an administrator, it's pretty straightforward.
-
Make sure the user you want to make an admin has already created a regular user account.
-
Login as an administrator
-
Go to
http://[hyrax_url:port]/roles
-
Select a role and add users to that role.