lesli_shield 1.1.7 → 1.1.8
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/app/assets/stylesheets/lesli_shield/application.css +1082 -0
- data/app/assets/stylesheets/lesli_shield/invitations.css +1008 -0
- data/app/controllers/lesli_shield/invites_controller.rb +100 -49
- data/app/controllers/lesli_shield/profiles_controller.rb +9 -3
- data/app/controllers/lesli_shield/role/actions_controller.rb +134 -38
- data/app/controllers/lesli_shield/roles_controller.rb +114 -141
- data/app/controllers/lesli_shield/users_controller.rb +11 -4
- data/app/controllers/users/confirmations_controller.rb +2 -2
- data/app/controllers/users/invitations_controller.rb +101 -0
- data/app/controllers/users/passwords_controller.rb +1 -1
- data/app/controllers/users/registrations_controller.rb +2 -2
- data/app/controllers/users/sessions_controller.rb +3 -1
- data/app/jobs/lesli_shield/invitation_delivery_job.rb +123 -0
- data/app/mailers/lesli_shield/devise_mailer.rb +3 -3
- data/app/mailers/lesli_shield/invitation_mailer.rb +58 -0
- data/app/models/concerns/lesli_shield/role_management.rb +70 -0
- data/app/models/concerns/lesli_shield/user_security.rb +22 -19
- data/app/models/lesli_shield/invite.rb +183 -12
- data/app/services/lesli_shield/invitation_audit.rb +34 -0
- data/app/services/lesli_shield/invitation_email_policy.rb +64 -0
- data/app/services/lesli_shield/invitation_service.rb +405 -0
- data/app/services/lesli_shield/invite_service.rb +34 -5
- data/app/services/lesli_shield/profile_service.rb +1 -0
- data/app/services/lesli_shield/role_action_service.rb +37 -92
- data/app/services/lesli_shield/role_audit.rb +42 -0
- data/app/services/lesli_shield/role_permission_service.rb +347 -0
- data/app/services/lesli_shield/role_privilege_deployment_service.rb +79 -0
- data/app/services/lesli_shield/role_privilege_service.rb +69 -105
- data/app/services/lesli_shield/role_service.rb +431 -0
- data/app/services/lesli_shield/user_registration_service.rb +1 -1
- data/app/services/lesli_shield/user_validator_service.rb +9 -9
- data/app/views/devise/confirmations/new.html.erb +5 -5
- data/app/views/devise/confirmations/show.html.erb +3 -3
- data/app/views/devise/passwords/edit.html.erb +7 -7
- data/app/views/devise/passwords/new.html.erb +7 -7
- data/app/views/devise/registrations/new.html.erb +13 -13
- data/app/views/devise/sessions/new.html.erb +8 -8
- data/app/views/devise/shared/_demo.html.erb +3 -3
- data/app/views/devise/shared/_links.html.erb +8 -11
- data/app/views/lesli_shield/invites/_form.html.erb +64 -7
- data/app/views/lesli_shield/invites/_invite.html.erb +55 -2
- data/app/views/lesli_shield/invites/_invite_actions.html.erb +34 -0
- data/app/views/lesli_shield/invites/_status_badge.html.erb +13 -0
- data/app/views/lesli_shield/invites/index.html.erb +119 -63
- data/app/views/lesli_shield/invites/new.html.erb +11 -36
- data/app/views/lesli_shield/invites/show.html.erb +13 -52
- data/app/views/lesli_shield/profiles/_information-form.html.erb +11 -0
- data/app/views/lesli_shield/profiles/show.html.erb +1 -4
- data/app/views/lesli_shield/role/actions/_custom_actions.html.erb +24 -0
- data/app/views/lesli_shield/role/actions/_deployment_status.html.erb +14 -0
- data/app/views/lesli_shield/role/actions/_matrix.html.erb +69 -0
- data/app/views/lesli_shield/role/actions/_permissions.html.erb +95 -0
- data/app/views/lesli_shield/role/actions/_toggle.html.erb +34 -0
- data/app/views/lesli_shield/role/actions/index.html.erb +14 -10
- data/app/views/lesli_shield/roles/_deployment_badge.html.erb +15 -0
- data/app/views/lesli_shield/roles/_empty_state.html.erb +20 -0
- data/app/views/lesli_shield/roles/_field_errors.html.erb +5 -0
- data/app/views/lesli_shield/roles/_filters.html.erb +66 -0
- data/app/views/lesli_shield/roles/_form.html.erb +149 -18
- data/app/views/lesli_shield/roles/_management_menu.html.erb +37 -0
- data/app/views/lesli_shield/roles/_pagination.html.erb +43 -0
- data/app/views/lesli_shield/roles/_role_list.html.erb +116 -0
- data/app/views/lesli_shield/roles/_status_badge.html.erb +11 -0
- data/app/views/lesli_shield/roles/_type_badge.html.erb +9 -0
- data/app/views/lesli_shield/roles/index.html.erb +15 -38
- data/app/views/lesli_shield/roles/new.html.erb +11 -0
- data/app/views/lesli_shield/roles/show.html.erb +79 -7
- data/app/views/lesli_shield/users/_information-form.html.erb +6 -0
- data/app/views/users/invitations/show.html.erb +142 -0
- data/app/views/users/invitations/unavailable.html.erb +19 -0
- data/config/locales/devise.en.yml +8 -0
- data/config/locales/devise.es.yml +8 -0
- data/config/locales/translations.en.yml +313 -78
- data/config/locales/translations.es.yml +313 -78
- data/config/routes.rb +10 -3
- data/db/migrate/v1/0801120110_create_lesli_shield_invites.rb +40 -6
- data/lib/lesli_shield/engine.rb +4 -0
- data/lib/lesli_shield/router.rb +10 -0
- data/lib/lesli_shield/version.rb +2 -2
- data/lib/tasks/lesli_shield_tasks.rake +1 -1
- data/readme.md +13 -1
- metadata +35 -5
- data/app/mailers/lesli_shield/invitation.html.erb +0 -23
- data/app/views/lesli_shield/invites/edit.html.erb +0 -12
- data/app/views/lesli_shield/role/actions/_form.html.erb +0 -75
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
module LesliShield
|
|
2
2
|
class InvitesController < ApplicationController
|
|
3
|
-
before_action :set_invite, only: %i[
|
|
3
|
+
before_action :set_invite, only: %i[show resend cancel]
|
|
4
|
+
before_action :set_assignable_roles, only: %i[new create]
|
|
4
5
|
|
|
5
6
|
# GET /invites
|
|
6
7
|
def index
|
|
7
|
-
@
|
|
8
|
+
@status_filter = InviteService.status_filter(params[:status])
|
|
9
|
+
invite_service = LesliShield::InviteService.new(current_user, query)
|
|
10
|
+
@invites = respond_with_pagination(invite_service.index(params))
|
|
8
11
|
end
|
|
9
12
|
|
|
10
13
|
# GET /invites/1
|
|
@@ -13,68 +16,116 @@ module LesliShield
|
|
|
13
16
|
|
|
14
17
|
# GET /invites/new
|
|
15
18
|
def new
|
|
16
|
-
@invite =
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# GET /invites/1/edit
|
|
20
|
-
def edit
|
|
19
|
+
@invite = current_account_invites.new
|
|
21
20
|
end
|
|
22
21
|
|
|
23
22
|
# POST /invites
|
|
24
23
|
def create
|
|
25
|
-
@invite =
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
else
|
|
40
|
-
respond_with_lesli(
|
|
41
|
-
turbo: stream_notification_danger(@invite.errors.full_messages.to_sentence)
|
|
42
|
-
)
|
|
43
|
-
end
|
|
24
|
+
@invite = invitation_service.create_and_send!(invite_params)
|
|
25
|
+
|
|
26
|
+
success(I18n.t("lesli_shield.invites.created_successfully"))
|
|
27
|
+
respond_with_invitation_redirect(@invite)
|
|
28
|
+
rescue ActiveRecord::RecordInvalid => exception
|
|
29
|
+
@invite = exception.record
|
|
30
|
+
respond_with_lesli(
|
|
31
|
+
turbo: stream_notification_danger(
|
|
32
|
+
@invite.errors.full_messages.to_sentence
|
|
33
|
+
),
|
|
34
|
+
json: { errors: @invite.errors },
|
|
35
|
+
html: "lesli_shield/invites/new",
|
|
36
|
+
status: :unprocessable_content
|
|
37
|
+
)
|
|
44
38
|
end
|
|
45
39
|
|
|
46
|
-
#
|
|
47
|
-
def
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
:turbo => stream_notification_danger(@invite.errors.full_messages.to_sentence)
|
|
59
|
-
)
|
|
60
|
-
end
|
|
40
|
+
# POST /invites/1/resend
|
|
41
|
+
def resend
|
|
42
|
+
@invite = invitation_service.resend!(@invite)
|
|
43
|
+
|
|
44
|
+
success(I18n.t("lesli_shield.invites.resent_successfully"))
|
|
45
|
+
respond_with_invitation_redirect(@invite)
|
|
46
|
+
rescue Invite::InvalidStatusTransition,
|
|
47
|
+
ActiveRecord::RecordInvalid => exception
|
|
48
|
+
respond_with_lesli(
|
|
49
|
+
turbo: stream_notification_danger(error_message(exception)),
|
|
50
|
+
redirect: invite_path(@invite)
|
|
51
|
+
)
|
|
61
52
|
end
|
|
62
53
|
|
|
63
|
-
#
|
|
64
|
-
def
|
|
65
|
-
|
|
66
|
-
|
|
54
|
+
# PATCH /invites/1/cancel
|
|
55
|
+
def cancel
|
|
56
|
+
@invite = invitation_service.cancel!(@invite)
|
|
57
|
+
|
|
58
|
+
success(I18n.t("lesli_shield.invites.cancelled_successfully"))
|
|
59
|
+
respond_with_invitation_redirect(@invite)
|
|
60
|
+
rescue Invite::InvalidStatusTransition,
|
|
61
|
+
ActiveRecord::RecordInvalid => exception
|
|
62
|
+
respond_with_lesli(
|
|
63
|
+
turbo: stream_notification_danger(error_message(exception)),
|
|
64
|
+
redirect: invite_path(@invite)
|
|
65
|
+
)
|
|
67
66
|
end
|
|
68
67
|
|
|
69
68
|
private
|
|
70
|
-
|
|
69
|
+
|
|
71
70
|
def set_invite
|
|
72
|
-
|
|
71
|
+
# Scoping the lookup makes an invitation from another account
|
|
72
|
+
# indistinguishable from a resource that does not exist.
|
|
73
|
+
@invite = current_account_invites.find(params.expect(:id))
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def set_assignable_roles
|
|
77
|
+
@assignable_roles = current_user.account.roles
|
|
78
|
+
.where(active: true)
|
|
79
|
+
.where(permission_level: (..current_user.max_level_permission))
|
|
80
|
+
.order(permission_level: :desc, name: :asc)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def current_account_invites
|
|
84
|
+
current_user.account.shield.invites
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def invitation_service
|
|
88
|
+
@invitation_service ||= InvitationService.new(current_user)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def error_message(exception)
|
|
92
|
+
return exception.record.errors.full_messages.to_sentence if
|
|
93
|
+
exception.respond_to?(:record)
|
|
94
|
+
|
|
95
|
+
exception.message
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def respond_with_invitation_redirect(invitation)
|
|
99
|
+
destination = invite_path(invitation)
|
|
100
|
+
|
|
101
|
+
if Lesli::ResponderInterface.const_defined?(
|
|
102
|
+
:NATIVE_TURBO_REDIRECTS,
|
|
103
|
+
false
|
|
104
|
+
)
|
|
105
|
+
return respond_with_lesli(redirect: destination)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Compatibility with Lesli versions released before native Turbo
|
|
109
|
+
# redirects were part of ResponderInterface. This branch can be
|
|
110
|
+
# removed when Shield's minimum Lesli version includes that API.
|
|
111
|
+
respond_to do |format|
|
|
112
|
+
format.html do
|
|
113
|
+
redirect_to destination, status: :see_other
|
|
114
|
+
end
|
|
115
|
+
format.turbo_stream do
|
|
116
|
+
redirect_to destination, status: :see_other
|
|
117
|
+
end
|
|
118
|
+
format.json { head :ok }
|
|
119
|
+
end
|
|
73
120
|
end
|
|
74
121
|
|
|
75
|
-
# Only allow a list of trusted parameters through.
|
|
76
122
|
def invite_params
|
|
77
|
-
params.require(:invite).permit(
|
|
123
|
+
params.require(:invite).permit(
|
|
124
|
+
:email,
|
|
125
|
+
:full_name,
|
|
126
|
+
:notes,
|
|
127
|
+
:role_id
|
|
128
|
+
)
|
|
78
129
|
end
|
|
79
130
|
end
|
|
80
131
|
end
|
|
@@ -9,6 +9,7 @@ module LesliShield
|
|
|
9
9
|
first_name
|
|
10
10
|
last_name
|
|
11
11
|
telephone
|
|
12
|
+
time_zone
|
|
12
13
|
].freeze
|
|
13
14
|
|
|
14
15
|
skip_before_action :authorize_request
|
|
@@ -24,13 +25,17 @@ module LesliShield
|
|
|
24
25
|
|
|
25
26
|
if @profile.successful?
|
|
26
27
|
respond_with_lesli(
|
|
27
|
-
turbo: stream_notification_success("
|
|
28
|
+
turbo: stream_notification_success(t("lesli_shield.profiles.updated")),
|
|
28
29
|
json: profile_payload,
|
|
29
30
|
redirect: profile_path
|
|
30
31
|
)
|
|
31
32
|
else
|
|
32
33
|
respond_with_lesli(
|
|
33
|
-
turbo:
|
|
34
|
+
turbo: [
|
|
35
|
+
stream_notification_danger(@profile.errors_as_sentence),
|
|
36
|
+
turbo_stream.replace("shield-profile-information-form",
|
|
37
|
+
partial: "lesli_shield/profiles/information-form")
|
|
38
|
+
],
|
|
34
39
|
json: { errors: @profile.errors },
|
|
35
40
|
html: :show,
|
|
36
41
|
status: :unprocessable_content
|
|
@@ -52,7 +57,8 @@ module LesliShield
|
|
|
52
57
|
:email,
|
|
53
58
|
:first_name,
|
|
54
59
|
:last_name,
|
|
55
|
-
:telephone
|
|
60
|
+
:telephone,
|
|
61
|
+
:time_zone
|
|
56
62
|
)
|
|
57
63
|
end
|
|
58
64
|
|
|
@@ -1,58 +1,154 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module LesliShield
|
|
2
4
|
class Role::ActionsController < ApplicationController
|
|
3
|
-
before_action :set_role
|
|
4
|
-
before_action :
|
|
5
|
+
before_action :set_role
|
|
6
|
+
before_action :set_permission_filters
|
|
5
7
|
|
|
6
|
-
def index
|
|
7
|
-
|
|
8
|
+
def index
|
|
9
|
+
load_permission_matrix
|
|
8
10
|
end
|
|
9
11
|
|
|
10
|
-
def
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
stream_notification_success("Role privileges added successfully!"),
|
|
16
|
-
turbo_stream.replace('shield-role-actions-form', partial: 'lesli_shield/role/actions/form')
|
|
17
|
-
]
|
|
18
|
-
)
|
|
19
|
-
else
|
|
20
|
-
respond_with_lesli(
|
|
21
|
-
:turbo => stream_notification_danger(@role_action.errors_as_sentence)
|
|
22
|
-
)
|
|
23
|
-
end
|
|
12
|
+
def create
|
|
13
|
+
persist_permission!(
|
|
14
|
+
action_id: params.require(:action_id),
|
|
15
|
+
enabled: true
|
|
16
|
+
)
|
|
24
17
|
end
|
|
25
18
|
|
|
26
19
|
def destroy
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
20
|
+
persist_permission!(action_id: params[:id], enabled: false)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def persist_permission!(action_id:, enabled:)
|
|
26
|
+
role_permission_service.set!(
|
|
27
|
+
role: @role,
|
|
28
|
+
action_id: action_id,
|
|
29
|
+
enabled: enabled
|
|
30
|
+
)
|
|
31
|
+
respond_with_lesli(
|
|
32
|
+
turbo: permission_update_streams,
|
|
33
|
+
json: {
|
|
34
|
+
role_id: @role.id,
|
|
35
|
+
action_id: action_id.to_i,
|
|
36
|
+
enabled: enabled
|
|
37
|
+
},
|
|
38
|
+
redirect: permission_index_path
|
|
39
|
+
)
|
|
40
|
+
rescue RolePermissionService::Error => exception
|
|
41
|
+
respond_with_lesli(
|
|
42
|
+
turbo: stream_notification_danger(exception.message),
|
|
43
|
+
json: { message: exception.message },
|
|
44
|
+
redirect: permission_index_path,
|
|
45
|
+
status: :unprocessable_content
|
|
46
|
+
)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def set_role
|
|
50
|
+
@role = role_service.find!(params[:role_id], manageable: true)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def set_permission_filters
|
|
54
|
+
@engine_slug = params[:engine_slug].presence
|
|
55
|
+
@search = params[:search].to_s.strip
|
|
56
|
+
|
|
57
|
+
if @engine_slug && !role_permission_service.engine_available?(@engine_slug)
|
|
58
|
+
raise ActiveRecord::RecordNotFound
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Only Turbo needs refreshed HTML. Redirects and JSON responses do not
|
|
63
|
+
# need to load the permission catalog after saving a single checkbox.
|
|
64
|
+
def permission_update_streams
|
|
65
|
+
return unless request.format.turbo_stream?
|
|
66
|
+
|
|
67
|
+
@role.reload
|
|
68
|
+
load_permission_matrix
|
|
69
|
+
|
|
70
|
+
[
|
|
71
|
+
stream_notification_success(
|
|
72
|
+
I18n.t("lesli_shield.roles.permissions_update_success")
|
|
73
|
+
),
|
|
74
|
+
turbo_stream.replace(
|
|
75
|
+
"shield-role-permissions",
|
|
76
|
+
partial: "lesli_shield/role/actions/permissions"
|
|
77
|
+
),
|
|
78
|
+
turbo_stream.replace(
|
|
79
|
+
"role-permission-deployment-status",
|
|
80
|
+
partial: "lesli_shield/role/actions/deployment_status"
|
|
34
81
|
)
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
82
|
+
]
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def role_service
|
|
86
|
+
@role_service ||= RoleService.new(current_user)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def role_permission_service
|
|
90
|
+
@role_permission_service ||= RolePermissionService.new(current_user)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def load_permission_matrix
|
|
94
|
+
@permission_matrix = role_permission_service.matrix(@role)
|
|
95
|
+
@permission_engines = @permission_matrix.map do |engine|
|
|
96
|
+
{
|
|
97
|
+
slug: engine[:engine].tr("_", "-"),
|
|
98
|
+
label: engine[:label],
|
|
99
|
+
count: engine[:resources].sum { |resource| resource[:actions].size }
|
|
100
|
+
}
|
|
101
|
+
end
|
|
102
|
+
if @engine_slug
|
|
103
|
+
@permission_matrix = @permission_matrix.select do |engine|
|
|
104
|
+
engine[:engine].tr("_", "-") == @engine_slug
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
if @search.present?
|
|
109
|
+
@permission_matrix = filter_permission_matrix(
|
|
110
|
+
@permission_matrix,
|
|
111
|
+
@search
|
|
38
112
|
)
|
|
39
113
|
end
|
|
40
114
|
end
|
|
41
115
|
|
|
42
|
-
|
|
116
|
+
def filter_permission_matrix(matrix, search)
|
|
117
|
+
query = search.downcase
|
|
43
118
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
119
|
+
matrix.filter_map do |engine|
|
|
120
|
+
resources = engine[:resources].filter_map do |resource|
|
|
121
|
+
actions = resource[:actions].select do |action|
|
|
122
|
+
permission_matches?(engine, resource, action, query)
|
|
123
|
+
end
|
|
124
|
+
resource.merge(actions: actions) if actions.any?
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
engine.merge(resources: resources) if resources.any?
|
|
128
|
+
end
|
|
129
|
+
end
|
|
47
130
|
|
|
48
|
-
def
|
|
49
|
-
|
|
131
|
+
def permission_matches?(engine, resource, action, query)
|
|
132
|
+
[
|
|
133
|
+
engine[:engine],
|
|
134
|
+
engine[:label],
|
|
135
|
+
resource[:identifier],
|
|
136
|
+
resource[:label],
|
|
137
|
+
resource[:route],
|
|
138
|
+
action[:identifier],
|
|
139
|
+
action[:label],
|
|
140
|
+
action[:display_label],
|
|
141
|
+
action[:action]
|
|
142
|
+
].any? { |value| value.to_s.downcase.include?(query) }
|
|
50
143
|
end
|
|
51
144
|
|
|
52
|
-
def
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
145
|
+
def permission_index_path
|
|
146
|
+
options = { search: @search.presence }
|
|
147
|
+
if @engine_slug
|
|
148
|
+
return engine_role_actions_path(@role, engine_slug: @engine_slug, **options)
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
role_actions_path(@role, **options)
|
|
56
152
|
end
|
|
57
153
|
end
|
|
58
154
|
end
|