restme 1.0.1 → 1.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34e6f83a9517ad4596b91a677ea60bc4520a6d074684ba31069a33967252e520
4
- data.tar.gz: 94a3e5fee24cd500c7b1904b048f76df2831f22363a463c1273603f56e996fde
3
+ metadata.gz: 20a6deb0be1cd7ca4a0835d7fc1211057a944237a4370ce576f3a6e8bc067738
4
+ data.tar.gz: 60fb44729f7721fc885224b2df4f7dcd3ec7ac07efaeacbee0ccd42dcece913c
5
5
  SHA512:
6
- metadata.gz: 42e31bc636a89203a07f9b068ba6916cf6b1df32e978d01bbc01a1f4168c825137c367a5bc6d73c3584b485f8768f32184a2eb026ccd5b78a22f5dcea1a08e74
7
- data.tar.gz: 4fc46af681505a061ea78d606410b8dcf7bc490ccf34deae1ec07f9ad36382bd232c9e550781a8bc55d67012ab8af104d0efa56f38ee0462e3fe6261613be1d1
6
+ metadata.gz: 633737ce0a993e839281b86d9a2d686f098a585d43b608aabb1c770b6b4a8f5c75c6faa0480e75c3c5a7d8089c01666aafd7c1d299415c4f0f391f8958ef209a
7
+ data.tar.gz: 9d859f78801920fca33bd80ab075e6f00e0a7d54e098dd5d2f66defa19481d66c23650f5a21b703b6640ed1e09fe2450c549168b63d0f41e9504ca38669038ea
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/restme.svg)](https://badge.fury.io/rb/restme)
4
4
 
5
- Adds support for new **Rails** controller actions such as pagination, filtering, sorting, and selecting specific model fields. Easily implement full CRUD functionality by importing Restme into your controller.
5
+ Adds support for new **Rails/Postgres** controller actions such as pagination, filtering, sorting, and selecting specific model fields. Easily implement full CRUD functionality by importing Restme into your controller.
6
6
 
7
7
  This gem manages your controller's responsibilities for:
8
8
  - Read Actions: Provide complete pagination, filtering, sorting, and field selection for records, all handled through query parameters (e.g., `http://127.0.0.1/products?name_equal=foo`).
@@ -11,13 +11,12 @@ This gem manages your controller's responsibilities for:
11
11
  ## Installation
12
12
 
13
13
 
14
-
14
+ GEMFILE:
15
15
  ```bash
16
- gem install restme
16
+ gem 'restme', '~> 1.0', '>= 1.0.1'
17
17
  ```
18
18
 
19
- OR
20
-
19
+ INSTALL:
21
20
  ```bash
22
21
  gem 'restme'
23
22
  ```
@@ -25,10 +24,7 @@ gem 'restme'
25
24
  ## Usage
26
25
 
27
26
  #### ℹ️ Current Version of gem require the following pré configs
28
-
29
- - If your controller defines an instance variable named `current_user`, Restme will automatically assign it to `model.current_user` during create and update actions—provided your model responds to the `current_user` method.
30
- - Your user model must have a role attribute (user.role).
31
- - Your controllers must be named using the plural form of the model (e.g., Product → ProductsController). Alternatively, you can manually set the model name by defining the MODEL_NAME constant (e.g., MODEL_NAME = "Shopping").
27
+ - Your controllers must be named using the plural form of the model (e.g., Product → ProductsController). Alternatively, you can manually set the model name by defining the MODEL_NAME constant (e.g., MODEL_NAME = "Product").
32
28
  - You must create a folder inside app named restfy to define controller rules for authorization, scoping, creation, updating, and field selection (see example below).
33
29
 
34
30
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../shared/user_role"
3
+ require_relative "../shared/restme_current_user_role"
4
4
  require_relative "../shared/current_model"
5
5
 
6
6
  module Restme
@@ -19,8 +19,8 @@ module Restme
19
19
  end
20
20
 
21
21
  def authorize?
22
- super_authorize? ||
23
- allowed_roles_actions[action_name.to_sym]&.include?(user_role.to_sym)
22
+ allowed_roles_actions[action_name.to_sym]
23
+ &.include?(restme_current_user_role&.to_sym)
24
24
  end
25
25
 
26
26
  def authorize_errors
@@ -35,17 +35,13 @@ module Restme
35
35
  end
36
36
 
37
37
  def allowed_roles_actions
38
- return {} unless authorize_rules_class.const_defined?(:ALLOWED_ROLES_ACTIONS)
38
+ return {} unless authorize_rules_class&.const_defined?(:ALLOWED_ROLES_ACTIONS)
39
39
 
40
40
  authorize_rules_class::ALLOWED_ROLES_ACTIONS
41
41
  end
42
42
 
43
- def super_authorize?
44
- restme_current_user&.super_admin?
45
- end
46
-
47
43
  def authorize_rules_class
48
- "#{controller_class.to_s.split("::").last}::Authorize::Rules".constantize
44
+ "#{controller_class.to_s.split("::").last}::Authorize::Rules".safe_constantize
49
45
  end
50
46
  end
51
47
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../shared/user_role"
3
+ require_relative "../shared/restme_current_user_role"
4
4
  require_relative "../shared/current_model"
5
5
  require_relative "../shared/controller_params"
6
6
 
@@ -64,13 +64,9 @@ module Restme
64
64
  def createable_scope?
65
65
  return true unless restme_current_user
66
66
 
67
- method_scope = "#{creatable_current_action}_#{user_role}_scope?"
67
+ method_scope = "#{creatable_current_action}_#{restme_current_user_role}_scope?"
68
68
 
69
- createable_super_admin_scope? || create_rules_class.try(method_scope) || false
70
- end
71
-
72
- def createable_super_admin_scope?
73
- restme_current_user.super_admin?
69
+ create_rules_class.try(method_scope) || false
74
70
  end
75
71
 
76
72
  def createable_object_errors_messages
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../shared/user_role"
3
+ require_relative "../shared/restme_current_user_role"
4
4
  require_relative "../shared/current_model"
5
5
  require_relative "../shared/controller_params"
6
6
  require_relative "filter/rules"
@@ -87,11 +87,11 @@ module Restme
87
87
  end
88
88
 
89
89
  def user_scope
90
- @user_scope ||= super_admin_scope || scope_rules_class.try(method_scope) || none_scope
90
+ @user_scope ||= none_user_scope || scope_rules_class.try(method_scope) || none_scope
91
91
  end
92
92
 
93
- def super_admin_scope
94
- klass.all if restme_current_user&.super_admin? || restme_current_user.blank?
93
+ def none_user_scope
94
+ klass.all if restme_current_user.blank?
95
95
  end
96
96
 
97
97
  def none_scope
@@ -99,7 +99,7 @@ module Restme
99
99
  end
100
100
 
101
101
  def method_scope
102
- "#{user_role}_scope"
102
+ "#{restme_current_user_role}_scope"
103
103
  end
104
104
 
105
105
  def scope_rules_class
@@ -4,8 +4,8 @@ module Restme
4
4
  module Shared
5
5
  # Returns the roles associated with the user, if any exist.
6
6
  module UserRole
7
- def user_role
8
- restme_current_user&.role
7
+ def restme_current_user_role
8
+ restme_current_user&.try(:role)
9
9
  end
10
10
  end
11
11
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "../shared/user_role"
3
+ require_relative "../shared/restme_current_user_role"
4
4
  require_relative "../shared/current_model"
5
5
  require_relative "../shared/controller_params"
6
6
 
@@ -74,13 +74,9 @@ module Restme
74
74
  def updateable_scope?
75
75
  return true unless restme_current_user
76
76
 
77
- method_scope = "#{updateable_current_action}_#{user_role}_scope?"
77
+ method_scope = "#{updateable_current_action}_#{restme_current_user_role}_scope?"
78
78
 
79
- updateable_super_admin_scope? || update_rules_class.try(method_scope) || false
80
- end
81
-
82
- def updateable_super_admin_scope?
83
- restme_current_user&.super_admin?
79
+ update_rules_class.try(method_scope) || false
84
80
  end
85
81
 
86
82
  def updateable_record_errors_messages
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Restme
4
- VERSION = "1.0.1"
4
+ VERSION = "1.0.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restme
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - everson-ever
@@ -45,7 +45,7 @@ files:
45
45
  - lib/restme/scope/sort/rules.rb
46
46
  - lib/restme/shared/controller_params.rb
47
47
  - lib/restme/shared/current_model.rb
48
- - lib/restme/shared/user_role.rb
48
+ - lib/restme/shared/restme_current_user_role.rb
49
49
  - lib/restme/update/rules.rb
50
50
  - lib/restme/version.rb
51
51
  - sig/restme.rbs