Installing the Hydra Role Management Gem and Creating Admins - UW-Libraries/druw GitHub Wiki

Installing the Hydra Role Management Gem and Creating Administrators

Installing the gem

After getting your Hyrax VM set up, you can install the hydra-role-management gem as follows:

  1. Shutdown your rails server (maybe not necessary but that's how I installed it)

  2. Add the following to the end of your Gemfile:

     gem 'hydra-role-management'
    
  3. Install the gem

     bundle install
    
  4. Generate the roles

     rails generate roles
    
  5. Migrate the database

     rails db:migrate
    
  6. 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
    

Creating your FIRST Administrator

The first administrator you create can only created via the command line as follows:

  1. Open the rails console

     rails c
    
  2. 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
    
  3. Confirm that the user was made an admin

     u.admin?
    

    The above code should return a true value.

Creating Subsequent Administrators

To add other users an administrator, it's pretty straightforward.

  1. Make sure the user you want to make an admin has already created a regular user account.

  2. Login as an administrator

  3. Go to http://[hyrax_url:port]/roles

  4. Select a role and add users to that role.

⚠️ **GitHub.com Fallback** ⚠️