hydra-role-management 0.2.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +5 -5
  2. data/.circleci/config.yml +88 -0
  3. data/.github_changelog_generator +2 -0
  4. data/.gitignore +3 -0
  5. data/.rspec +2 -0
  6. data/.rubocop.yml +51 -0
  7. data/CHANGELOG.md +151 -0
  8. data/CONTRIBUTING.md +69 -21
  9. data/Gemfile +42 -9
  10. data/LICENSE.md +14 -0
  11. data/README.md +63 -16
  12. data/Rakefile +15 -17
  13. data/SUPPORT.md +6 -0
  14. data/app/controllers/concerns/hydra/role_management/roles_behavior.rb +16 -13
  15. data/app/controllers/concerns/hydra/role_management/user_roles_behavior.rb +5 -2
  16. data/app/controllers/roles_controller.rb +3 -1
  17. data/app/controllers/user_roles_controller.rb +3 -2
  18. data/app/models/concerns/hydra/role_management/legacy_attribute_handling.rb +3 -0
  19. data/app/models/concerns/hydra/role_management/user_roles.rb +6 -4
  20. data/app/models/role.rb +10 -5
  21. data/app/views/roles/edit.html.erb +10 -10
  22. data/app/views/roles/index.html.erb +2 -2
  23. data/app/views/roles/new.html.erb +3 -3
  24. data/app/views/roles/show.html.erb +7 -7
  25. data/config/locales/role-management.en.yml +28 -0
  26. data/config/locales/role-management.es.yml +28 -0
  27. data/config/routes.rb +3 -2
  28. data/hydra-role-management.gemspec +22 -13
  29. data/lib/generators/roles/roles_generator.rb +40 -59
  30. data/lib/generators/roles/templates/hydra_role_management_rails3.rb +3 -1
  31. data/lib/generators/roles/templates/migrations/user_roles.rb +6 -4
  32. data/lib/hydra-role-management.rb +10 -3
  33. data/lib/hydra/role_management.rb +5 -2
  34. data/lib/hydra/role_management/version.rb +3 -1
  35. data/spec/controllers/roles_controller_spec.rb +39 -44
  36. data/spec/controllers/user_roles_controller_spec.rb +20 -20
  37. data/spec/lib/user_roles_spec.rb +21 -22
  38. data/spec/models/role_spec.rb +22 -21
  39. data/spec/routing/role_management_routes_spec.rb +29 -45
  40. data/spec/spec_helper.rb +14 -5
  41. data/spec/test_app_templates/app/models/sample.rb +8 -8
  42. data/spec/test_app_templates/app/models/solr_document.rb +3 -2
  43. data/spec/test_app_templates/config/initializers/hydra_config.rb +7 -6
  44. data/spec/test_app_templates/lib/generators/test_app_generator.rb +9 -12
  45. metadata +119 -13
  46. data/.travis.yml +0 -18
data/Gemfile CHANGED
@@ -1,15 +1,48 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'coveralls', require: false
2
6
 
3
7
  gemspec
4
8
 
5
- gem 'rspec-its'
9
+ # BEGIN ENGINE_CART BLOCK
10
+ # engine_cart: 1.1.0
11
+ # engine_cart stanza: 0.10.0
12
+ # the below comes from engine_cart, a gem used to test this Rails engine gem
13
+ # in the context of a Rails app.
14
+ file = File.expand_path('Gemfile', ENV['ENGINE_CART_DESTINATION'] ||
15
+ ENV['RAILS_ROOT'] || File.expand_path('.internal_test_app',
16
+ File.dirname(__FILE__)))
17
+ if File.exist?(file)
18
+ begin
19
+ eval_gemfile file
20
+ rescue Bundler::GemfileError => e
21
+ Bundler.ui.warn '[EngineCart] Skipping Rails application dependencies:'
22
+ Bundler.ui.warn e.message
23
+ end
24
+ else
25
+ Bundler.ui.warn "[EngineCart] Unmet dependencies in #{file}," \
26
+ ' using placeholder dependencies'
6
27
 
7
- # To avoid: 'Bundler could not find compatible versions for gem "sprockets":'
8
- gem 'sass', '~> 3.2.15'
9
- gem 'sprockets', '~> 2.11.0'
28
+ if ENV['RAILS_VERSION']
29
+ if ENV['RAILS_VERSION'] == 'edge'
30
+ gem 'rails', github: 'rails/rails'
31
+ ENV['ENGINE_CART_RAILS_OPTIONS'] = '--edge --skip-turbolinks'
32
+ else
33
+ gem 'rails', ENV['RAILS_VERSION']
34
+ end
35
+ end
10
36
 
11
- file = File.expand_path("Gemfile", ENV['ENGINE_CART_DESTINATION'] || ENV['RAILS_ROOT'] || File.expand_path("../spec/internal", __FILE__))
12
- if File.exists?(file)
13
- puts "Loading #{file} ..." if $DEBUG # `ruby -d` or `bundle -v`
14
- instance_eval File.read(file)
37
+ case ENV['RAILS_VERSION']
38
+ when /^4.2/
39
+ gem 'coffee-rails', '~> 4.1.0'
40
+ gem 'responders', '~> 2.0'
41
+ gem 'sass-rails', '>= 5.0'
42
+ when /^4.[01]/
43
+ gem 'sass-rails', '< 5.0'
44
+ when /^5.[12]/
45
+ gem 'sass-rails', '~> 5.0'
46
+ end
15
47
  end
48
+ # END ENGINE_CART BLOCK
@@ -0,0 +1,14 @@
1
+ Copyright 2015 Data Curation Experts
2
+ Additional copyright may be held by others, as reflected in the commit history.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
data/README.md CHANGED
@@ -1,27 +1,74 @@
1
- An engine gem to provide a RDBMS backed list of roles and their associated user. This replaces the hydra default role mapper.
1
+ # hydra-role-management
2
2
 
3
- This gem supports both Rails 3 and 4.
3
+ Code: [![CircleCI](https://circleci.com/gh/samvera/hydra-role-management.svg?style=svg)](https://circleci.com/gh/samvera/hydra-role-management) [![Gem Version](https://badge.fury.io/rb/hydra-role-management.svg)](https://badge.fury.io/rb/hydra-role-management) [![Coverage Status](https://coveralls.io/repos/github/samvera/hydra-role-management/badge.svg?branch=master)](https://coveralls.io/github/samvera/hydra-role-management?branch=master)
4
4
 
5
- ##Installing:
5
+ Docs: [![Contribution Guidelines](http://img.shields.io/badge/CONTRIBUTING-Guidelines-blue.svg)](./CONTRIBUTING.md) [![Apache 2.0 License](http://img.shields.io/badge/APACHE2-license-blue.svg)](./LICENSE.md)
6
6
 
7
- * Add: ```gem 'hydra-role-management'``` to your Gemfile and then ```bundle install```
8
- * ```rails generate roles```
9
- * ```rake db:migrate```
10
- * Add the following [cancan](https://github.com/ryanb/cancan) abilities:
7
+ Jump In: [![Slack Status](http://slack.samvera.org/badge.svg)](http://slack.samvera.org/)
8
+
9
+ # What is hydra-role-management?
10
+
11
+ An engine gem to provide a RDBMS backed list of roles and their associated user. This replaces the hydra default role mapper.
12
+
13
+ As of version 1.0, this gem only supports Rails 5.
14
+
15
+ ## Product Owner & Maintenance
16
+
17
+ **hydra-role-management** is a Core Component of the Samvera community. The documentation for what this means can be found [here](http://samvera.github.io/core_components.html#requirements-for-a-core-component).
18
+
19
+ ### Product Owner
20
+
21
+ [jrgriffiniii](https://github.com/jrgriffiniii)
22
+
23
+ # Help
24
+
25
+ The Samvera community is here to help. Please see our [support guide](./SUPPORT.md).
26
+
27
+ ## Installing:
28
+
29
+ - Add: `gem 'hydra-role-management'` to your Gemfile and then `bundle install`
30
+ - `rails generate roles`
31
+ - `rake db:migrate`
32
+ - Add the following [cancan](https://github.com/ryanb/cancan) abilities:
11
33
 
12
34
  ```
13
35
  # app/models/ability.rb
14
36
  if current_user.admin?
15
- can [:create, :show, :add_user, :remove_user, :index], Role
37
+ can [:create, :show, :add_user, :remove_user, :index, :edit, :update, :destroy], Role
16
38
  end
17
39
  ```
18
40
 
19
- ##Testing:
20
- Given the need to support both Rails 3 and 4, the test suite has been parameterized to test against any version of Rails.
41
+ ## Testing:
42
+
43
+ - Install a system javascript runtime or uncomment therubyracer in spec/support/Gemfile
44
+ - Ensure that the testing app does not exist: `bundle exec rake engine_cart:clean`
45
+ - Set Rails version you want to test against. For example:
46
+
47
+ - `export RAILS_VERSION=5.1.4`
48
+
49
+ - Ensure that the correct version of Rails is installed: `bundle update`
50
+
51
+ - Build test app: `bundle exec rake engine_cart:generate`
52
+
53
+ - And run tests: `bundle exec rake ci`
54
+
55
+ ## Releasing
56
+
57
+ 1. `bundle install`
58
+ 2. Increase the version number in `lib/hydra/role_management/version.rb`
59
+ 3. Increase the same version number in `.github_changelog_generator`
60
+ 4. Update `CHANGELOG.md` by running this command:
61
+
62
+ ```
63
+ github_changelog_generator --user samvera --project hydra-role-management --token YOUR_GITHUB_TOKEN_HERE
64
+ ```
65
+
66
+ 5. Commit these changes to the master branch
67
+
68
+ 6. Run `rake release`
69
+
70
+ # Acknowledgments
71
+
72
+ This software has been developed by and is brought to you by the Samvera community. Learn more at the [Samvera website](http://samvera.org/).
21
73
 
22
- * Install a system javascript runtime or uncomment therubyracer in spec/support/Gemfile
23
- * Ensure that the testing app does not exist: ```bundle exec rake clean```
24
- * Set Rails version you want to test against. For example:
25
- * ```RAILS_VERSION=3.2.13``` or ```RAILS_VERSION=4.0.0```
26
- * Ensure that the correct version of Rails is installed: ```bundle update```
27
- * Build test app and run tests: ```bundle exec rake spec```
74
+ ![Samvera Logo](https://wiki.duraspace.org/download/thumbnails/87459292/samvera-fall-font2-200w.png?version=1&modificationDate=1498550535816&api=v2)
data/Rakefile CHANGED
@@ -1,23 +1,21 @@
1
1
  #!/usr/bin/env rake
2
- require 'bundler/setup'
3
- require "bundler/gem_tasks"
2
+ # frozen_string_literal: true
4
3
 
5
- require 'rspec/core/rake_task'
4
+ require 'bundler/setup'
5
+ require 'bundler/gem_tasks'
6
6
  require 'engine_cart/rake_task'
7
+ require 'rspec/core/rake_task'
8
+ require 'rubocop/rake_task'
7
9
 
10
+ desc 'Run style checker'
11
+ RuboCop::RakeTask.new(:rubocop) do |task|
12
+ task.fail_on_error = true
13
+ end
8
14
 
9
- desc 'Default: run ci.'
10
- task :default => :ci
11
-
12
-
13
- desc "Make clean, generate test app, and run the tests"
14
- task :ci => [:clean, :generate, :spec]
15
-
16
- desc "Run the tests"
17
- RSpec::Core::RakeTask.new(:spec)
18
-
19
- desc "Create the test rails app"
20
- task :generate => 'engine_cart:generate'
15
+ desc 'Run the tests'
16
+ task ci: [:rubocop, 'engine_cart:generate'] do
17
+ RSpec::Core::RakeTask.new(:spec)
18
+ Rake::Task['spec'].invoke
19
+ end
21
20
 
22
- desc "Clean out the test rails app"
23
- task :clean => 'engine_cart:clean'
21
+ task default: :ci
@@ -0,0 +1,6 @@
1
+ If you would like to report an issue, first search [the list of issues](https://github.com/samvera/hydra-role-management/issues/) to see if someone else has already reported it, and then feel free to [create a new issue](https://github.com/samvera/hydra-role-management/issues/new).
2
+
3
+ If you have questions or need help, please email [the Samvera community tech list](https://groups.google.com/forum/#!forum/samvera-tech) or stop by the #dev channel in [the Samvera community Slack team](https://wiki.duraspace.org/pages/viewpage.action?pageId=87460391#Getintouch!-Slack).
4
+
5
+ You can learn more about the various Samvera communication channels on the [Get in touch!](https://wiki.duraspace.org/pages/viewpage.action?pageId=87460391) wiki page.
6
+
@@ -1,46 +1,49 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hydra
2
4
  module RoleManagement
5
+ # Module defining Controller actions for creating and managing Roles
3
6
  module RolesBehavior
4
7
  extend ActiveSupport::Concern
5
8
 
6
9
  included do
7
- load_and_authorize_resource
10
+ load_and_authorize_resource
8
11
  end
9
12
 
10
- def index
11
- end
13
+ def index; end
12
14
 
13
15
  def show
14
16
  redirect_to role_management.edit_role_path(@role) if can? :edit, @role
15
17
  end
16
18
 
17
- def new
18
- end
19
+ def new; end
19
20
 
20
- def edit
21
- end
21
+ def edit; end
22
22
 
23
23
  def create
24
24
  @role = Role.new(role_params)
25
25
  if @role.save
26
- redirect_to role_management.edit_role_path(@role), notice: 'Role was successfully created.'
26
+ redirect_to role_management.edit_role_path(@role),
27
+ notice: 'Role was successfully created.'
27
28
  else
28
- render action: "new"
29
+ render action: 'new'
29
30
  end
30
31
  end
31
32
 
32
33
  def update
33
34
  @role = Role.find(params[:id])
34
35
  if @role.update_attributes(role_params)
35
- redirect_to role_management.edit_role_path(@role), notice: 'Role was successfully updated.'
36
+ redirect_to role_management.edit_role_path(@role),
37
+ notice: 'Role was successfully updated.'
36
38
  else
37
- render action: "edit"
39
+ render action: 'edit'
38
40
  end
39
41
  end
40
42
 
41
43
  def destroy
42
- if (@role.destroy)
43
- redirect_to role_management.roles_path, notice: 'Role was successfully deleted.'
44
+ if @role.destroy
45
+ redirect_to role_management.roles_path,
46
+ notice: 'Role was successfully deleted.'
44
47
  else
45
48
  redirect_to role_management.roles_path
46
49
  end
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hydra
2
4
  module RoleManagement
5
+ # Module defining Controller actions for adding and managing Roles for Users
3
6
  module UserRolesBehavior
4
7
  extend ActiveSupport::Concern
5
8
 
@@ -15,7 +18,8 @@ module Hydra
15
18
  u.save!
16
19
  redirect_to role_management.role_path(@role)
17
20
  else
18
- redirect_to role_management.role_path(@role), :flash=> {:error=>"Unable to find the user #{params[:user_key]}"}
21
+ redirect_to role_management.role_path(@role),
22
+ flash: { error: "Invalid user #{params[:user_key]}" }
19
23
  end
20
24
  end
21
25
 
@@ -37,4 +41,3 @@ module Hydra
37
41
  end
38
42
  end
39
43
  end
40
-
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Controller for managing Roles
1
4
  class RolesController < ApplicationController
2
5
  include Hydra::RoleManagement::RolesBehavior
3
6
  end
4
-
@@ -1,5 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Controller for managing Roles for Users
1
4
  class UserRolesController < ApplicationController
2
5
  include Hydra::RoleManagement::UserRolesBehavior
3
6
  end
4
-
5
-
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hydra
2
4
  module RoleManagement
5
+ # Module for ensuring compatibility with Rails releases earlier than 4.0
3
6
  module LegacyAttributeHandling
4
7
  extend ActiveSupport::Concern
5
8
  included do
@@ -1,30 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Hydra
2
4
  module RoleManagement
5
+ # Module offering methods for user behavior managing roles and groups
3
6
  module UserRoles
4
7
  extend ActiveSupport::Concern
8
+
5
9
  included do
6
10
  has_and_belongs_to_many :roles
7
11
  end
8
12
 
9
13
  def groups
10
14
  g = roles.map(&:name)
11
- g += ['registered'] unless new_record? || guest?
15
+ g += ['registered'] unless new_record? || guest?
12
16
  g
13
17
  end
14
18
 
15
19
  def guest?
16
20
  if defined?(DeviseGuests)
17
- read_attribute :guest
21
+ self[:guest]
18
22
  else
19
23
  false
20
24
  end
21
25
  end
22
-
23
26
 
24
27
  def admin?
25
28
  roles.where(name: 'admin').exists?
26
29
  end
27
-
28
30
  end
29
31
  end
30
32
  end
@@ -1,9 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Class modeling Roles within the application
1
4
  class Role < ActiveRecord::Base
2
5
  has_and_belongs_to_many :users
3
6
 
4
- validates :name,
5
- uniqueness: true,
6
- format: { with: /\A[a-zA-Z0-9._-]+\z/,
7
- :message => "Only letters, numbers, hyphens, underscores and periods are allowed"}
8
-
7
+ validates :name,
8
+ uniqueness: true,
9
+ format: {
10
+ with: /\A[a-zA-Z0-9._-]+\z/,
11
+ message: 'Only letters, numbers, hyphens, ' \
12
+ 'underscores and periods are allowed'
13
+ }
9
14
  end
@@ -1,26 +1,26 @@
1
- <h2>Role:</h2>
1
+ <h2><%= t('role-management.edit.title') %></h2>
2
2
  <%= bootstrap_form_for @role, :url=>role_management.role_path(@role) do |f| %>
3
- <%= f.text_field :name, :label=> 'Role name' %>
3
+ <%= f.text_field :name, :label=> t('role-management.edit.field_name') %>
4
4
 
5
- <%= f.submit "Update" %>
5
+ <%= f.submit t('role-management.edit.update') %>
6
6
 
7
7
  <% end %>
8
8
  <% if can? :destroy, Role %>
9
- <%= button_to "Delete", role_management.role_path(@role), :method=>:delete, :class=>'btn btn-danger' %>
9
+ <%= button_to t('role-management.edit.delete'), role_management.role_path(@role), :method=>:delete, :class=>'btn btn-danger' %>
10
10
  <% end %>
11
- <h3>Accounts:</h3>
11
+ <h3><%= t('role-management.edit.accounts') %></h3>
12
12
  <ul>
13
13
  <% @role.users.each do |user| %>
14
14
  <li><%= user.user_key %>
15
15
  <% if can? :remove_user, Role %>
16
- <%= button_to "Remove User", role_management.role_user_path(@role, user), :method=>:delete, :class=>'btn btn-danger' %>
16
+ <%= button_to t('role-management.edit.remove'), role_management.role_user_path(@role, user.id), :method=>:delete, :class=>'btn btn-danger' %>
17
17
  <% end %>
18
18
  </li>
19
19
  <% end %>
20
20
  </ul>
21
- <h3>Add a new account:</h3>
21
+ <h3><%= t('role-management.edit.add_new_account') %></h3>
22
22
  <%= bootstrap_form_tag :url=> role_management.role_users_path(@role) do |f| %>
23
- <%= f.text_field 'user_key', :label=>'User' %>
24
- <%= f.submit "Add" %>
25
- <%= link_to "Cancel", role_management.roles_path, :class => 'btn btn-default' %>
23
+ <%= f.text_field 'user_key', :label=>t('role-management.edit.user') %>
24
+ <%= f.submit t('role-management.edit.add') %>
25
+ <%= link_to t('role-management.edit.cancel'), role_management.roles_path, :class => 'btn btn-default' %>
26
26
  <% end %>
@@ -1,4 +1,4 @@
1
- <h2>Roles</h2>
1
+ <h2><%= t('role-management.index.title') %></h2>
2
2
  <ul>
3
3
  <% @roles.each do |role| %>
4
4
  <li><%=link_to role.name, role_management.role_path(role) %></li>
@@ -6,6 +6,6 @@
6
6
  </ul>
7
7
 
8
8
  <% if can? :create, Role %>
9
- <%= button_to "Create a new role", role_management.new_role_path, method: :get, class: 'btn btn-primary' %>
9
+ <%= button_to t('role-management.index.create'), role_management.new_role_path, method: :get, class: 'btn btn-primary' %>
10
10
  <% end %>
11
11
 
@@ -1,6 +1,6 @@
1
1
  <%= bootstrap_form_for @role, :url=>role_management.roles_path do |f| %>
2
- <%= f.text_field :name, :label=> 'Role name' %>
3
- <%= f.submit "Add" %>
4
- <%= link_to "Cancel", role_management.roles_path, :class => 'btn btn-default' %>
2
+ <%= f.text_field :name, :label=> t('role-management.new.field_name') %>
3
+ <%= f.submit t('role-management.new.add') %>
4
+ <%= link_to t('role-management.new.cancel'), role_management.roles_path, :class => 'btn btn-default' %>
5
5
  <% end %>
6
6