action_sentinel_group 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +33 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +21 -0
- data/README.md +94 -0
- data/Rakefile +12 -0
- data/lib/action_sentinel_group/configuration.rb +49 -0
- data/lib/action_sentinel_group/model.rb +26 -0
- data/lib/action_sentinel_group/permissions.rb +64 -0
- data/lib/action_sentinel_group/version.rb +5 -0
- data/lib/action_sentinel_group.rb +32 -0
- data/lib/generators/action_sentinel_group/install_generator.rb +99 -0
- data/lib/generators/action_sentinel_group/templates/initializer/action_sentinel_group.rb +19 -0
- data/lib/generators/action_sentinel_group/templates/migrations/create_groups_migration.rb +9 -0
- data/lib/generators/action_sentinel_group/templates/migrations/create_user_groups_migration.rb +12 -0
- data/lib/generators/action_sentinel_group/templates/models/group_model.rb +4 -0
- data/lib/generators/action_sentinel_group/templates/models/user_group_model.rb +4 -0
- metadata +150 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8aad62dd5fdc24469d713e3185b6bdbe2b203a42b32bd6dcd777538b7c0f6714
|
4
|
+
data.tar.gz: be16545203d28132ca001491a7df1fef4ecb3bcd5accae56bd47748298479d44
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2bc5981ad5b03df04ebbf4459130b875ee5dbba0f89e911e052a02c7f445ca3e8880e4af2d401953a381c027073d58ecf3a60e6187a03a111116b2be44c58657
|
7
|
+
data.tar.gz: 943383fe344e7b763a65f2ad1df5aa9449d1c91016dbe56a54a6146a84485ac21b4163239ca5582174c93c2913e2f0c3e4be9d7d54aeaca788928e814dd8db56
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
Exclude:
|
4
|
+
- "lib/generators/**/templates/**/*"
|
5
|
+
NewCops: disable
|
6
|
+
|
7
|
+
Style/Documentation:
|
8
|
+
Enabled: true
|
9
|
+
Exclude:
|
10
|
+
- "lib/generators/action_sentinel_group/**"
|
11
|
+
- "spec/support/*"
|
12
|
+
|
13
|
+
Style/StringLiterals:
|
14
|
+
Enabled: true
|
15
|
+
EnforcedStyle: double_quotes
|
16
|
+
|
17
|
+
Style/StringLiteralsInInterpolation:
|
18
|
+
Enabled: true
|
19
|
+
EnforcedStyle: double_quotes
|
20
|
+
|
21
|
+
Layout/LineLength:
|
22
|
+
Max: 120
|
23
|
+
|
24
|
+
Metrics/BlockLength:
|
25
|
+
Enabled: true
|
26
|
+
Exclude:
|
27
|
+
- "spec/**/*"
|
28
|
+
- "action_sentinel_group.gemspec"
|
29
|
+
|
30
|
+
Naming/HeredocDelimiterNaming:
|
31
|
+
Enabled: true
|
32
|
+
Exclude:
|
33
|
+
- "action_sentinel_group.gemspec"
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--exclude lib/generators/action_sentinel_group/templates/
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Denis Stael
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
# ActionSentinelGroup
|
2
|
+
|
3
|
+
Control of group access permissions to controller actions using [ActionSentinel](https://github.com/denisstael/action_sentinel).
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
### 1. Add the gem into your project
|
7
|
+
|
8
|
+
Add this to your Gemfile and run `bundle install`.
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'action_sentinel_group'
|
12
|
+
```
|
13
|
+
|
14
|
+
Or install it yourself as:
|
15
|
+
```sh
|
16
|
+
gem install action_sentinel_group
|
17
|
+
```
|
18
|
+
|
19
|
+
### 2. Generate Models
|
20
|
+
|
21
|
+
Use the ActionSentinelGroup generator to create the required models and its migrations. This generator expects that you already have a user model.
|
22
|
+
|
23
|
+
You must specify the name of the user model and the name of the model that will represent the group of users. For example, if the name of your user model is `User` and you want a group model called `Group`, you can call:
|
24
|
+
```
|
25
|
+
rails g action_sentinel_group:install User Group
|
26
|
+
```
|
27
|
+
|
28
|
+
If your database uses UUID for the primary and foreign keys, you can pass the `--uuid` option:
|
29
|
+
|
30
|
+
```
|
31
|
+
rails g action_sentinel_group:install User Group --uuid
|
32
|
+
```
|
33
|
+
|
34
|
+
The generator will create the group model with the name that you provided (in this example it will be `Group`), it will also create a model called `UserGroup` (the junction between your user model name and the group model), create the migrations and will insert into your User class the required methods to check the user's groups access permissions.
|
35
|
+
|
36
|
+
It will invoke the [generator from ActionSentinel](https://github.com/denisstael/action_sentinel#2-generate-accesspermission-model) to create `AccessPermission` model and insert into Group model the required methods to manage access permissions.
|
37
|
+
|
38
|
+
Finally, it will create an initializer file with the required configurations.
|
39
|
+
|
40
|
+
### 3. Run the migrations
|
41
|
+
|
42
|
+
You can check the migrations created into your migrations folder, and add custom fields before running them if necessary.
|
43
|
+
```
|
44
|
+
rails db:migrate
|
45
|
+
```
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
### Managing permissions to the group
|
50
|
+
|
51
|
+
You can add manage permissions to a group at the same way that is informed by [ActionSentinel](https://github.com/denisstael/action_sentinel#usage):
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
# Adding permissions to access create and update actions in UsersController
|
55
|
+
group.add_permissions_to 'create', 'update', 'users'
|
56
|
+
|
57
|
+
# Removing permissions to access create and update actions in UsersController
|
58
|
+
group.remove_permissions_to 'create', 'update', 'users'
|
59
|
+
|
60
|
+
# Checking if the group have permission to access create action in UsersController
|
61
|
+
group.has_permission_to? 'create', 'users'
|
62
|
+
```
|
63
|
+
|
64
|
+
### Check permissions for a user of the group
|
65
|
+
|
66
|
+
You can associate a user to a group that have permissions to acces actions of some controllers, and you can check if the user have the pemission to access some action of a controller, in the same way that you check the group permission:
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
# Associating the user with the group
|
70
|
+
UserGroup.create(user_id: user.id, group_id: group.id)
|
71
|
+
|
72
|
+
# Giving permission to the group to action 'create' of a controller called PostsController
|
73
|
+
group.add_permissions_to('create', 'posts')
|
74
|
+
|
75
|
+
# Checking if the user has permission to access the action 'create' of a controller called PostsController
|
76
|
+
user.has_permission_to?('create', 'posts')
|
77
|
+
```
|
78
|
+
|
79
|
+
## Authorization
|
80
|
+
|
81
|
+
To controllers authorization and another configurations about authorization methods, you can follow the instructions provided by the documentation of ActionSentinel gem:
|
82
|
+
|
83
|
+
- [Include authorization in ApplicationController](https://github.com/denisstael/action_sentinel#4-include-authorization-in-applicationcontroller)
|
84
|
+
- [Authorization method](https://github.com/denisstael/action_sentinel#authorization)
|
85
|
+
- [Action User](https://github.com/denisstael/action_sentinel#action-user)
|
86
|
+
- [Rescuing an UnauthorizedAction in ApplicationController](https://github.com/denisstael/action_sentinel#rescuing-an-unauthorizedaction-in-applicationcontroller)
|
87
|
+
|
88
|
+
## Contributing
|
89
|
+
|
90
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/denisstael/action_sentinel_group.
|
91
|
+
|
92
|
+
## License
|
93
|
+
|
94
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionSentinelGroup
|
4
|
+
# The Configuration class holds the configuration options for ActionSentinelGroup
|
5
|
+
class Configuration
|
6
|
+
# The name of the user model (default: "User")
|
7
|
+
#
|
8
|
+
# @return [String] The name of the user model
|
9
|
+
attr_reader :user_model_name
|
10
|
+
|
11
|
+
# The name of the group model (default: "Group")
|
12
|
+
#
|
13
|
+
# @return [String] The name of the group model
|
14
|
+
attr_reader :group_model_name
|
15
|
+
|
16
|
+
# The name of the user group model (default: "UserGroup")
|
17
|
+
#
|
18
|
+
# @return [String] The name of the user group model
|
19
|
+
attr_reader :user_group_model_name
|
20
|
+
|
21
|
+
# Initializes a new Configuration instance with default values.
|
22
|
+
def initialize
|
23
|
+
@user_model_name = "User"
|
24
|
+
@group_model_name = "Group"
|
25
|
+
@user_group_model_name = "UserGroup"
|
26
|
+
end
|
27
|
+
|
28
|
+
# Sets the name of the user model after camelizing and singularizing it.
|
29
|
+
#
|
30
|
+
# @param user_model_name [String] The name of the user model
|
31
|
+
def user_model_name=(user_model_name)
|
32
|
+
@user_model_name = user_model_name.camelize.singularize
|
33
|
+
end
|
34
|
+
|
35
|
+
# Sets the name of the group model after camelizing and singularizing it.
|
36
|
+
#
|
37
|
+
# @param group_model_name [String] The name of the group model
|
38
|
+
def group_model_name=(group_model_name)
|
39
|
+
@group_model_name = group_model_name.camelize.singularize
|
40
|
+
end
|
41
|
+
|
42
|
+
# Sets the name of the user group model after camelizing and singularizing it.
|
43
|
+
#
|
44
|
+
# @param user_group_model_name [String] The name of the user group model
|
45
|
+
def user_group_model_name=(user_group_model_name)
|
46
|
+
@user_group_model_name = user_group_model_name.camelize.singularize
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_sentinel_group/permissions"
|
4
|
+
|
5
|
+
module ActionSentinelGroup
|
6
|
+
#
|
7
|
+
# Module to be included in ActionSentinel
|
8
|
+
module Model
|
9
|
+
# rubocop:disable Naming/PredicateName
|
10
|
+
|
11
|
+
# Includes the ActionSentinelGroup::Permissions module in the calling model class
|
12
|
+
# to allow checking permissions for controller actions.
|
13
|
+
#
|
14
|
+
# @example:
|
15
|
+
#
|
16
|
+
# class User < ApplicationRecord
|
17
|
+
# has_group_permissions
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# @see ActionSentinelGroup::Permissions
|
21
|
+
def has_group_permissions
|
22
|
+
include ActionSentinelGroup::Permissions
|
23
|
+
end
|
24
|
+
# rubocop:enable Naming/PredicateName
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActionSentinelGroup
|
4
|
+
# Provides methods for check access permissions of a user model related to groups.
|
5
|
+
#
|
6
|
+
# This module is designed to be included in user models that need to check access permissions.
|
7
|
+
# It introduces methods for checking permissions associated with a specific controller and actions.
|
8
|
+
#
|
9
|
+
# @example Including Permissions in a Model
|
10
|
+
# class User < ApplicationRecord
|
11
|
+
# include ActionSentinelGroup::Permissions
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# user = User.new
|
15
|
+
# user.has_permission_to?('create', 'users')
|
16
|
+
#
|
17
|
+
module Permissions
|
18
|
+
# rubocop:disable Metrics/AbcSize, Naming/PredicateName
|
19
|
+
|
20
|
+
# Checks if the user has permission to perform a specific action on a controller.
|
21
|
+
#
|
22
|
+
# @param action [String] The action to check permission for.
|
23
|
+
# @param controller_path [String] The path of the controller to check permission for.
|
24
|
+
# @return [Boolean] Returns true if the user has permission, otherwise false.
|
25
|
+
def has_permission_to?(action, controller_path)
|
26
|
+
query = AccessPermission
|
27
|
+
.joins(group_table_name.singularize.to_sym => user_groups_table_name.to_sym)
|
28
|
+
.where(user_groups_table_name.to_sym => { "#{user_table_name.singularize}_id".to_sym => id })
|
29
|
+
.where(controller_path: controller_path)
|
30
|
+
|
31
|
+
query = if %w[sqlite sqlite3].include? self.class.connection.adapter_name.downcase
|
32
|
+
query.where("actions LIKE ?", "%#{action}%")
|
33
|
+
else
|
34
|
+
query.where(':action = ANY("access_permissions"."actions")', action: action)
|
35
|
+
end
|
36
|
+
|
37
|
+
query.exists?
|
38
|
+
end
|
39
|
+
# rubocop:enable Metrics/AbcSize, Naming/PredicateName
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# Returns the name of the user table.
|
44
|
+
#
|
45
|
+
# @return [String] The user table name.
|
46
|
+
def user_table_name
|
47
|
+
ActionSentinelGroup.configuration.user_model_name.underscore.pluralize
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns the name of the group table.
|
51
|
+
#
|
52
|
+
# @return [String] The group table name.
|
53
|
+
def group_table_name
|
54
|
+
ActionSentinelGroup.configuration.group_model_name.underscore.pluralize
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns the name of the user groups table.
|
58
|
+
#
|
59
|
+
# @return [String] The user groups table name.
|
60
|
+
def user_groups_table_name
|
61
|
+
ActionSentinelGroup.configuration.user_group_model_name.underscore.pluralize
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_sentinel"
|
4
|
+
require "action_sentinel_group/version"
|
5
|
+
require "action_sentinel_group/configuration"
|
6
|
+
require "action_sentinel_group/model"
|
7
|
+
|
8
|
+
# The ActionSentinelGroup module is an extension of ActionSentinel gem
|
9
|
+
# that provides a way to group users and provide group access permissions
|
10
|
+
module ActionSentinelGroup
|
11
|
+
class << self
|
12
|
+
# Accessor for the configuration instance
|
13
|
+
attr_accessor :configuration
|
14
|
+
|
15
|
+
# Configures the ActionSentinelGroup settings
|
16
|
+
#
|
17
|
+
# @example:
|
18
|
+
#
|
19
|
+
# ActionSentinelGroup.configure do |config|
|
20
|
+
# config.user_model_name = "User"
|
21
|
+
# end
|
22
|
+
def configure
|
23
|
+
self.configuration ||= Configuration.new
|
24
|
+
yield(configuration)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
configure {}
|
29
|
+
end
|
30
|
+
|
31
|
+
# Include ActionSentinelGroup::Model in ActionSentinel
|
32
|
+
ActionSentinel.include ActionSentinelGroup::Model
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators"
|
4
|
+
require "rails/generators/active_record"
|
5
|
+
|
6
|
+
module ActionSentinelGroup
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
include Rails::Generators::Migration
|
9
|
+
|
10
|
+
source_root File.expand_path("templates", __dir__)
|
11
|
+
|
12
|
+
argument :user_model_name, type: :string, desc: "Name of the model that is being used as user"
|
13
|
+
argument :group_model_name, type: :string, desc: "Name of the model that will represent a group of users"
|
14
|
+
|
15
|
+
class_option :uuid, type: :boolean, default: false, desc: "Use UUID type as primary/foreign key"
|
16
|
+
|
17
|
+
def self.next_migration_number(path)
|
18
|
+
ActiveRecord::Generators::Base.next_migration_number(path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def generate
|
22
|
+
model_file = File.join("app", "models", "#{user_model_name.underscore.singularize}.rb")
|
23
|
+
|
24
|
+
if File.exist?(model_file) || revoke_process?
|
25
|
+
create_models
|
26
|
+
create_migrations
|
27
|
+
inject_group_association_into_user_model(model_file)
|
28
|
+
create_initializer
|
29
|
+
invoke_action_sentinel_generator
|
30
|
+
else
|
31
|
+
logger.error("The file #{model_file} does not appear to exist")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def logger
|
38
|
+
Logger.new($stdout)
|
39
|
+
end
|
40
|
+
|
41
|
+
def revoke_process?
|
42
|
+
behavior == :revoke
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_models
|
46
|
+
template "models/group_model.rb", "app/models/#{group_model_name.underscore}.rb"
|
47
|
+
template "models/user_group_model.rb", "app/models/#{user_group_model_name.underscore}.rb"
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_migrations
|
51
|
+
migration_template "migrations/create_groups_migration.rb", "db/migrate/create_#{groups_table_name}.rb"
|
52
|
+
migration_template "migrations/create_user_groups_migration.rb", "db/migrate/create_#{user_group_table_name}.rb"
|
53
|
+
end
|
54
|
+
|
55
|
+
def inject_group_association_into_user_model(model_file)
|
56
|
+
if File.exist?(model_file)
|
57
|
+
inject_into_class(model_file, user_model_name) do
|
58
|
+
"\thas_group_permissions\n" \
|
59
|
+
"\thas_many :#{user_group_table_name}\n" \
|
60
|
+
"\thas_many :#{group_model_name.pluralize.underscore}, through: :#{user_group_table_name}\n"
|
61
|
+
end
|
62
|
+
else
|
63
|
+
logger.info("The file #{model_file} does not appear to exist")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def create_initializer
|
68
|
+
template "initializer/action_sentinel_group.rb", "config/initializers/action_sentinel_group.rb"
|
69
|
+
end
|
70
|
+
|
71
|
+
def invoke_action_sentinel_generator
|
72
|
+
invoke "action_sentinel:access_permission", [group_model_name, options]
|
73
|
+
end
|
74
|
+
|
75
|
+
def user_group_model_name
|
76
|
+
"#{user_model_name}#{group_model_name}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def user_group_table_name
|
80
|
+
"#{user_model_name.underscore}_#{group_model_name.underscore.pluralize}"
|
81
|
+
end
|
82
|
+
|
83
|
+
def groups_table_name
|
84
|
+
group_model_name.underscore.pluralize.to_s
|
85
|
+
end
|
86
|
+
|
87
|
+
def migration_version
|
88
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
89
|
+
end
|
90
|
+
|
91
|
+
def primary_key_type
|
92
|
+
options.uuid? ? ", id: :uuid" : ""
|
93
|
+
end
|
94
|
+
|
95
|
+
def foreign_key_type
|
96
|
+
options.uuid? ? ", type: :uuid" : ""
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Use this initializer to configure ActionSentinelGroup based on your models.
|
4
|
+
#
|
5
|
+
# It is very important that the configured models are the same as those used as
|
6
|
+
# User, Group and their relationship. Otherwise the gem may not work correctly.
|
7
|
+
ActionSentinelGroup.configure do |config|
|
8
|
+
# Name of the model that is being used as User.
|
9
|
+
# The default value is "User".
|
10
|
+
config.user_model_name = "<%= user_model_name.camelize.singularize %>"
|
11
|
+
|
12
|
+
# Name of the model that will be used as Group.
|
13
|
+
# The default value is "Group".
|
14
|
+
config.group_model_name = "<%= group_model_name.camelize.singularize %>"
|
15
|
+
|
16
|
+
# Name of the model that forms the relationship between the User and Group model.
|
17
|
+
# The default value is "UserGroup".
|
18
|
+
config.user_group_model_name = "<%= user_group_model_name.camelize.singularize %>"
|
19
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class Create<%= groups_table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :<%= group_model_name.underscore.pluralize %><%= primary_key_type %> do |t|
|
4
|
+
t.string :name, null: false
|
5
|
+
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/lib/generators/action_sentinel_group/templates/migrations/create_user_groups_migration.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
class Create<%= user_group_table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
|
2
|
+
def change
|
3
|
+
create_table :<%= user_group_table_name %><%= primary_key_type %> do |t|
|
4
|
+
t.references :<%= user_model_name.underscore %>, null: false<%= foreign_key_type %>, foreign_key: { on_delete: :cascade }
|
5
|
+
t.references :<%= group_model_name.underscore %>, null: false<%= foreign_key_type %>, foreign_key: { on_delete: :cascade }
|
6
|
+
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
|
10
|
+
add_index :<%= user_group_table_name %>, %i[<%= user_model_name.underscore %>_id <%= group_model_name.underscore %>_id], unique: true
|
11
|
+
end
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: action_sentinel_group
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Denis Stael
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: action_sentinel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.3.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.3.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activerecord
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.2'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: railties
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.2'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.2'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.21'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.21'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.4.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.4.2
|
97
|
+
description: " Group access authorization control, based on controllers actions
|
98
|
+
access permissions using ActionSentinel.\n"
|
99
|
+
email:
|
100
|
+
- denissantistael@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".yardopts"
|
108
|
+
- CHANGELOG.md
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- lib/action_sentinel_group.rb
|
114
|
+
- lib/action_sentinel_group/configuration.rb
|
115
|
+
- lib/action_sentinel_group/model.rb
|
116
|
+
- lib/action_sentinel_group/permissions.rb
|
117
|
+
- lib/action_sentinel_group/version.rb
|
118
|
+
- lib/generators/action_sentinel_group/install_generator.rb
|
119
|
+
- lib/generators/action_sentinel_group/templates/initializer/action_sentinel_group.rb
|
120
|
+
- lib/generators/action_sentinel_group/templates/migrations/create_groups_migration.rb
|
121
|
+
- lib/generators/action_sentinel_group/templates/migrations/create_user_groups_migration.rb
|
122
|
+
- lib/generators/action_sentinel_group/templates/models/group_model.rb
|
123
|
+
- lib/generators/action_sentinel_group/templates/models/user_group_model.rb
|
124
|
+
homepage: https://github.com/denisstael/action_sentinel_group
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata:
|
128
|
+
homepage_uri: https://github.com/denisstael/action_sentinel_group
|
129
|
+
source_code_uri: https://github.com/denisstael/action_sentinel_group
|
130
|
+
changelog_uri: https://github.com/denisstael/action_sentinel_group/blob/main/CHANGELOG.md
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 2.6.0
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubygems_version: 3.3.7
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: Control of group access permissions to controller actions using ActionSentinel.
|
150
|
+
test_files: []
|