restme 0.0.39 → 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 +4 -4
- data/README.md +5 -9
- data/docker-compose.yml +1 -1
- data/lib/restme/authorize/rules.rb +10 -13
- data/lib/restme/create/rules.rb +3 -7
- data/lib/restme/restme.rb +5 -1
- data/lib/restme/scope/rules.rb +6 -10
- data/lib/restme/shared/{user_role.rb → restme_current_user_role.rb} +2 -2
- data/lib/restme/update/rules.rb +3 -7
- data/lib/restme/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20a6deb0be1cd7ca4a0835d7fc1211057a944237a4370ce576f3a6e8bc067738
|
4
|
+
data.tar.gz: 60fb44729f7721fc885224b2df4f7dcd3ec7ac07efaeacbee0ccd42dcece913c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 633737ce0a993e839281b86d9a2d686f098a585d43b608aabb1c770b6b4a8f5c75c6faa0480e75c3c5a7d8089c01666aafd7c1d299415c4f0f391f8958ef209a
|
7
|
+
data.tar.gz: 9d859f78801920fca33bd80ab075e6f00e0a7d54e098dd5d2f66defa19481d66c23650f5a21b703b6640ed1e09fe2450c549168b63d0f41e9504ca38669038ea
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
[](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
|
16
|
+
gem 'restme', '~> 1.0', '>= 1.0.1'
|
17
17
|
```
|
18
18
|
|
19
|
-
|
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
|
|
data/docker-compose.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../shared/
|
3
|
+
require_relative "../shared/restme_current_user_role"
|
4
4
|
require_relative "../shared/current_model"
|
5
5
|
|
6
6
|
module Restme
|
@@ -10,16 +10,17 @@ module Restme
|
|
10
10
|
include ::Restme::Shared::CurrentModel
|
11
11
|
include ::Restme::Shared::UserRole
|
12
12
|
|
13
|
-
def
|
14
|
-
return true
|
15
|
-
return authorize_errors unless authorize?
|
13
|
+
def user_authorized?
|
14
|
+
return true if restme_current_user.blank? || authorize?
|
16
15
|
|
17
|
-
|
16
|
+
authorize_errors
|
17
|
+
|
18
|
+
false
|
18
19
|
end
|
19
20
|
|
20
21
|
def authorize?
|
21
|
-
|
22
|
-
|
22
|
+
allowed_roles_actions[action_name.to_sym]
|
23
|
+
&.include?(restme_current_user_role&.to_sym)
|
23
24
|
end
|
24
25
|
|
25
26
|
def authorize_errors
|
@@ -34,17 +35,13 @@ module Restme
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def allowed_roles_actions
|
37
|
-
return {} unless authorize_rules_class
|
38
|
+
return {} unless authorize_rules_class&.const_defined?(:ALLOWED_ROLES_ACTIONS)
|
38
39
|
|
39
40
|
authorize_rules_class::ALLOWED_ROLES_ACTIONS
|
40
41
|
end
|
41
42
|
|
42
|
-
def super_authorize?
|
43
|
-
restme_current_user&.super_admin?
|
44
|
-
end
|
45
|
-
|
46
43
|
def authorize_rules_class
|
47
|
-
"#{controller_class.to_s.split("::").last}::Authorize::Rules".
|
44
|
+
"#{controller_class.to_s.split("::").last}::Authorize::Rules".safe_constantize
|
48
45
|
end
|
49
46
|
end
|
50
47
|
end
|
data/lib/restme/create/rules.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../shared/
|
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}_#{
|
67
|
+
method_scope = "#{creatable_current_action}_#{restme_current_user_role}_scope?"
|
68
68
|
|
69
|
-
|
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
|
data/lib/restme/restme.rb
CHANGED
@@ -18,11 +18,15 @@ module Restme
|
|
18
18
|
def initialize_restme
|
19
19
|
use_current_user
|
20
20
|
|
21
|
-
|
21
|
+
restme_authorize_response unless user_authorized?
|
22
22
|
end
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
+
def restme_authorize_response
|
27
|
+
render json: restme_scope_errors, status: restme_scope_status
|
28
|
+
end
|
29
|
+
|
26
30
|
def use_current_user
|
27
31
|
@restme_current_user = try(:current_user)
|
28
32
|
end
|
data/lib/restme/scope/rules.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../shared/
|
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"
|
@@ -58,7 +58,7 @@ module Restme
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def model_scope
|
61
|
-
@model_scope ||=
|
61
|
+
@model_scope ||= custom_scope
|
62
62
|
end
|
63
63
|
|
64
64
|
def pagination
|
@@ -79,10 +79,6 @@ module Restme
|
|
79
79
|
@restme_scope_status ||= status
|
80
80
|
end
|
81
81
|
|
82
|
-
def without_item_in_scope?
|
83
|
-
!user_scope.exists?
|
84
|
-
end
|
85
|
-
|
86
82
|
def custom_scope
|
87
83
|
@filtered_scope = filterable_scope(user_scope)
|
88
84
|
@sorted_scope = sortable_scope(filtered_scope)
|
@@ -91,11 +87,11 @@ module Restme
|
|
91
87
|
end
|
92
88
|
|
93
89
|
def user_scope
|
94
|
-
@user_scope ||=
|
90
|
+
@user_scope ||= none_user_scope || scope_rules_class.try(method_scope) || none_scope
|
95
91
|
end
|
96
92
|
|
97
|
-
def
|
98
|
-
klass.all if restme_current_user
|
93
|
+
def none_user_scope
|
94
|
+
klass.all if restme_current_user.blank?
|
99
95
|
end
|
100
96
|
|
101
97
|
def none_scope
|
@@ -103,7 +99,7 @@ module Restme
|
|
103
99
|
end
|
104
100
|
|
105
101
|
def method_scope
|
106
|
-
"#{
|
102
|
+
"#{restme_current_user_role}_scope"
|
107
103
|
end
|
108
104
|
|
109
105
|
def scope_rules_class
|
data/lib/restme/update/rules.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../shared/
|
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}_#{
|
77
|
+
method_scope = "#{updateable_current_action}_#{restme_current_user_role}_scope?"
|
78
78
|
|
79
|
-
|
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
|
data/lib/restme/version.rb
CHANGED
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:
|
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/
|
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
|