moduler 0.4.0 → 0.6.0
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/builds/moduler/tailwind.css +155 -1
- data/app/assets/javascripts/moduler/controllers/attachments_controller.js +30 -0
- data/app/assets/javascripts/moduler/controllers/dependent_select_controller.js +19 -0
- data/app/assets/javascripts/moduler/controllers/select_all_controller.js +15 -0
- data/app/components/moduler/filter_component.html.erb +9 -1
- data/app/components/moduler/filter_component.rb +12 -0
- data/app/components/moduler/form/attachments_component.html.erb +32 -0
- data/app/components/moduler/form/attachments_component.rb +28 -0
- data/app/components/moduler/form/checkboxes_component.html.erb +19 -0
- data/app/components/moduler/form/checkboxes_component.rb +13 -0
- data/app/components/moduler/form/file_component.html.erb +14 -0
- data/app/components/moduler/form/file_component.rb +11 -0
- data/app/components/moduler/form/select_component.html.erb +1 -1
- data/app/components/moduler/form/select_component.rb +5 -0
- data/app/components/moduler/form/wysiwyg_component.rb +1 -1
- data/app/controllers/concerns/moduler/authentication.rb +2 -2
- data/app/controllers/concerns/moduler/require_document_acceptance.rb +31 -0
- data/app/controllers/concerns/moduler/restrict_administrator_access.rb +32 -0
- data/app/controllers/moduler/administration/application_controller.rb +3 -0
- data/app/controllers/moduler/administration/articles_controller.rb +1 -1
- data/app/controllers/moduler/administration/documents_controller.rb +56 -0
- data/app/controllers/moduler/administration/emails/deliveries_controller.rb +42 -0
- data/app/controllers/moduler/administration/emails_controller.rb +68 -0
- data/app/controllers/moduler/administration/memberships_controller.rb +62 -0
- data/app/controllers/moduler/administration/organizations_controller.rb +51 -0
- data/app/controllers/moduler/administration/preferences_controller.rb +57 -0
- data/app/controllers/moduler/administration/roles_controller.rb +56 -0
- data/app/controllers/moduler/administration/users_controller.rb +2 -2
- data/app/controllers/moduler/application_controller.rb +3 -1
- data/app/controllers/moduler/articles_controller.rb +4 -2
- data/app/controllers/moduler/document_acceptances_controller.rb +25 -0
- data/app/controllers/moduler/profile/sent_emails_controller.rb +18 -0
- data/app/controllers/moduler/profile/sessions/revocation_controller.rb +3 -0
- data/app/controllers/moduler/profile/sessions_controller.rb +3 -0
- data/app/controllers/moduler/profile_controller.rb +6 -1
- data/app/controllers/moduler/sessions_controller.rb +16 -6
- data/app/controllers/moduler/users_controller.rb +3 -0
- data/app/filters/email_delivery_filter.rb +35 -0
- data/app/filters/organization_query_filter.rb +23 -0
- data/app/jobs/moduler/email_delivery_job.rb +14 -0
- data/app/lib/moduler/form_builder.rb +17 -3
- data/app/mailers/moduler/application_mailer.rb +27 -1
- data/app/mailers/moduler/email_mailer.rb +14 -0
- data/app/models/moduler/article.rb +2 -0
- data/app/models/moduler/document.rb +17 -0
- data/app/models/moduler/email.rb +59 -0
- data/app/models/moduler/membership.rb +25 -0
- data/app/models/moduler/organization.rb +13 -0
- data/app/models/moduler/preference.rb +44 -0
- data/app/models/moduler/role.rb +26 -0
- data/app/models/moduler/sent_email.rb +13 -0
- data/app/models/moduler/user.rb +21 -1
- data/app/models/moduler/user_document.rb +8 -0
- data/app/models/moduler/user_email.rb +15 -0
- data/app/policies/moduler/administration/document_policy.rb +25 -0
- data/app/policies/moduler/administration/email_policy.rb +26 -0
- data/app/policies/moduler/administration/membership_policy.rb +29 -0
- data/app/policies/moduler/administration/organization_policy.rb +25 -0
- data/app/policies/moduler/administration/preference_policy.rb +29 -0
- data/app/policies/moduler/administration/role_policy.rb +25 -0
- data/app/services/moduler/document_acceptance.rb +43 -0
- data/app/views/layouts/moduler/mailer.html.erb +30 -0
- data/app/views/layouts/moduler/mailer.text.erb +1 -0
- data/app/views/moduler/administration/articles/_article.html.erb +2 -0
- data/app/views/moduler/administration/articles/_form.html.erb +1 -0
- data/app/views/moduler/administration/documents/_document.html.erb +19 -0
- data/app/views/moduler/administration/documents/_form.html.erb +23 -0
- data/app/views/moduler/administration/documents/edit.html.erb +1 -0
- data/app/views/moduler/administration/documents/index.html.erb +13 -0
- data/app/views/moduler/administration/documents/new.html.erb +1 -0
- data/app/views/moduler/administration/emails/_email.html.erb +33 -0
- data/app/views/moduler/administration/emails/_form.html.erb +23 -0
- data/app/views/moduler/administration/emails/deliveries/new.html.erb +58 -0
- data/app/views/moduler/administration/emails/edit.html.erb +1 -0
- data/app/views/moduler/administration/emails/index.html.erb +13 -0
- data/app/views/moduler/administration/emails/new.html.erb +1 -0
- data/app/views/moduler/administration/memberships/_form.html.erb +38 -0
- data/app/views/moduler/administration/memberships/_membership.html.erb +23 -0
- data/app/views/moduler/administration/memberships/edit.html.erb +1 -0
- data/app/views/moduler/administration/memberships/index.html.erb +14 -0
- data/app/views/moduler/administration/memberships/new.html.erb +1 -0
- data/app/views/moduler/administration/organizations/_form.html.erb +13 -0
- data/app/views/moduler/administration/organizations/_organization.html.erb +23 -0
- data/app/views/moduler/administration/organizations/edit.html.erb +1 -0
- data/app/views/moduler/administration/organizations/index.html.erb +13 -0
- data/app/views/moduler/administration/organizations/new.html.erb +1 -0
- data/app/views/moduler/administration/preferences/_form.html.erb +16 -0
- data/app/views/moduler/administration/preferences/_preference.html.erb +24 -0
- data/app/views/moduler/administration/preferences/edit.html.erb +1 -0
- data/app/views/moduler/administration/preferences/index.html.erb +13 -0
- data/app/views/moduler/administration/preferences/new.html.erb +1 -0
- data/app/views/moduler/administration/roles/_form.html.erb +24 -0
- data/app/views/moduler/administration/roles/_role.html.erb +15 -0
- data/app/views/moduler/administration/roles/edit.html.erb +1 -0
- data/app/views/moduler/administration/roles/index.html.erb +14 -0
- data/app/views/moduler/administration/roles/new.html.erb +1 -0
- data/app/views/moduler/administration/users/_user.html.erb +4 -0
- data/app/views/moduler/administration/users/edit.html.erb +2 -0
- data/app/views/moduler/administration/users/new.html.erb +2 -0
- data/app/views/moduler/common/_header.html.erb +2 -7
- data/app/views/moduler/common/administration/_sidebar.html.erb +10 -0
- data/app/views/moduler/common/profile/_sidebar.html.erb +1 -0
- data/app/views/moduler/document_acceptances/new.html.erb +36 -0
- data/app/views/moduler/email_mailer/custom.html.erb +3 -0
- data/app/views/moduler/email_mailer/custom.text.erb +1 -0
- data/app/views/moduler/profile/edit.html.erb +1 -0
- data/app/views/moduler/profile/sent_emails/index.html.erb +26 -0
- data/config/locales/moduler/administration/articles/en.yml +5 -0
- data/config/locales/moduler/administration/documents/en.yml +35 -0
- data/config/locales/moduler/administration/emails/en.yml +75 -0
- data/config/locales/moduler/administration/memberships/en.yml +35 -0
- data/config/locales/moduler/administration/organizations/en.yml +26 -0
- data/config/locales/moduler/administration/preferences/en.yml +44 -0
- data/config/locales/moduler/administration/roles/en.yml +32 -0
- data/config/locales/moduler/administration/users/en.yml +12 -1
- data/config/locales/moduler/common/en.yml +7 -1
- data/config/locales/moduler/components/en.yml +5 -0
- data/config/locales/moduler/document_acceptances/en.yml +17 -0
- data/config/locales/moduler/models/en.yml +8 -0
- data/config/locales/moduler/profile/en.yml +2 -0
- data/config/locales/moduler/profile/sent_emails/en.yml +11 -0
- data/config/locales/moduler/sessions/en.yml +1 -0
- data/config/routes.rb +13 -0
- data/db/migrate/20261104120000_add_status_to_moduler_users.rb +6 -0
- data/db/migrate/20261104205837_create_moduler_documents.rb +10 -0
- data/db/migrate/20261104205950_create_moduler_user_documents.rb +12 -0
- data/db/migrate/20261111113522_create_moduler_organizations.rb +11 -0
- data/db/migrate/20261111150000_create_moduler_roles.rb +13 -0
- data/db/migrate/20261111160000_create_moduler_memberships.rb +13 -0
- data/db/migrate/20261111180000_add_name_to_moduler_users.rb +5 -0
- data/db/migrate/20261111190000_add_status_to_moduler_articles.rb +8 -0
- data/db/migrate/20261111200000_create_moduler_preferences.rb +13 -0
- data/db/migrate/20261111210000_create_moduler_emails.rb +15 -0
- data/db/migrate/20261111210001_create_moduler_user_emails.rb +13 -0
- data/db/migrate/20261111210002_create_moduler_sent_emails.rb +12 -0
- data/lib/moduler/configuration.rb +6 -0
- data/lib/moduler/version.rb +1 -1
- metadata +100 -2
|
@@ -46,7 +46,7 @@ module Moduler
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def permitted_parameters
|
|
49
|
-
params.expect(article: [ :path, :title, :description, :keywords, :content, images: [] ])
|
|
49
|
+
params.expect(article: [ :status, :path, :title, :description, :keywords, :content, images: [] ])
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def permitted_filter_parameters
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module Moduler
|
|
2
|
+
module Administration
|
|
3
|
+
class DocumentsController < ApplicationController
|
|
4
|
+
before_action -> { authorize([ :moduler, :administration, :document ]) }
|
|
5
|
+
before_action :set_document, only: %i[ edit update ]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
@filter, @documents = QueryFilter.new(Document.with_attached_file, permitted_filter_parameters).call
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new
|
|
12
|
+
@document = Document.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def create
|
|
16
|
+
@document = Document.new(permitted_parameters)
|
|
17
|
+
|
|
18
|
+
if @document.save
|
|
19
|
+
redirect_to moduler.administration_documents_path, notice: t(".notice")
|
|
20
|
+
else
|
|
21
|
+
render :new, status: :unprocessable_entity
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def edit; end
|
|
26
|
+
|
|
27
|
+
def update
|
|
28
|
+
if @document.update(permitted_update_parameters)
|
|
29
|
+
redirect_to moduler.administration_documents_path, notice: t(".notice")
|
|
30
|
+
else
|
|
31
|
+
render :edit, status: :unprocessable_entity
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def set_document
|
|
38
|
+
@document = Document.find(params[:id])
|
|
39
|
+
authorize(@document, policy_class: DocumentPolicy)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def permitted_parameters
|
|
43
|
+
params.expect(document: %i[ name kind file ])
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# The file is set only when the document is created and cannot be replaced.
|
|
47
|
+
def permitted_update_parameters
|
|
48
|
+
params.expect(document: %i[ name kind ])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def permitted_filter_parameters
|
|
52
|
+
(params.permit(filter: %i[ query ])[:filter] || {}).merge(params.permit(:page))
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Moduler
|
|
2
|
+
module Administration
|
|
3
|
+
module Emails
|
|
4
|
+
# Sending an email to users chosen from a filterable list.
|
|
5
|
+
class DeliveriesController < ApplicationController
|
|
6
|
+
before_action :set_email
|
|
7
|
+
|
|
8
|
+
def new
|
|
9
|
+
@filter, @users = EmailDeliveryFilter.new(candidates, permitted_filter_parameters).call
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def create
|
|
13
|
+
queued = @email.deliver_to(User.where(id: Array(params[:user_ids])))
|
|
14
|
+
|
|
15
|
+
redirect_to moduler.new_administration_email_delivery_path(@email), notice: t(".notice", count: queued)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def set_email
|
|
21
|
+
@email = Email.find(params[:email_id])
|
|
22
|
+
authorize(@email, :deliver?, policy_class: EmailPolicy)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Users with the id and sent_at of their queued email, if any.
|
|
26
|
+
def candidates
|
|
27
|
+
User
|
|
28
|
+
.joins(User.sanitize_sql_array([
|
|
29
|
+
"LEFT JOIN moduler_user_emails ON moduler_user_emails.moduler_user_id = moduler_users.id AND moduler_user_emails.moduler_email_id = ?",
|
|
30
|
+
@email.id
|
|
31
|
+
]))
|
|
32
|
+
.select("moduler_users.*", "moduler_user_emails.id AS user_email_id", "moduler_user_emails.sent_at AS user_email_sent_at")
|
|
33
|
+
.order(:email_address)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def permitted_filter_parameters
|
|
37
|
+
(params.permit(filter: %i[ query role sent per_page ])[:filter] || {}).merge(params.permit(:page))
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
module Moduler
|
|
2
|
+
module Administration
|
|
3
|
+
class EmailsController < ApplicationController
|
|
4
|
+
before_action -> { authorize([ :moduler, :administration, :email ]) }
|
|
5
|
+
before_action :set_email, only: %i[ edit update destroy ]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
@filter, @emails = QueryFilter.new(Email, permitted_filter_parameters).call
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new
|
|
12
|
+
@email = Email.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def create
|
|
16
|
+
@email = Email.new(permitted_parameters.except(:remove_attachment_ids))
|
|
17
|
+
|
|
18
|
+
if @email.save
|
|
19
|
+
redirect_to moduler.administration_emails_path, notice: t(".notice")
|
|
20
|
+
else
|
|
21
|
+
render :new, status: :unprocessable_entity
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def edit; end
|
|
26
|
+
|
|
27
|
+
# New attachments are added to the existing ones, and the attachments
|
|
28
|
+
# marked for removal are removed, once the email is saved.
|
|
29
|
+
def update
|
|
30
|
+
parameters = permitted_parameters
|
|
31
|
+
attachments = parameters.delete(:attachments)
|
|
32
|
+
remove_attachment_ids = parameters.delete(:remove_attachment_ids)
|
|
33
|
+
|
|
34
|
+
if @email.update(parameters)
|
|
35
|
+
@email.attachments.attach(attachments) if attachments.present?
|
|
36
|
+
@email.attachments_attachments.where(id: remove_attachment_ids).find_each(&:purge) if remove_attachment_ids.present?
|
|
37
|
+
|
|
38
|
+
redirect_to moduler.administration_emails_path, notice: t(".notice")
|
|
39
|
+
else
|
|
40
|
+
render :edit, status: :unprocessable_entity
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def destroy
|
|
45
|
+
@email.destroy!
|
|
46
|
+
|
|
47
|
+
redirect_to moduler.administration_emails_path, status: :see_other, notice: t(".notice")
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def set_email
|
|
53
|
+
@email = Email.find(params[:id])
|
|
54
|
+
authorize(@email, policy_class: EmailPolicy)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def permitted_parameters
|
|
58
|
+
params.expect(email: [ :subject, :sender, :kind, :event, :body, attachments: [], images: [], remove_attachment_ids: [] ]).tap do |parameters|
|
|
59
|
+
parameters[:attachments] = Array(parameters[:attachments]).compact_blank if parameters.key?(:attachments)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def permitted_filter_parameters
|
|
64
|
+
(params.permit(filter: %i[ query ])[:filter] || {}).merge(params.permit(:page))
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
module Moduler
|
|
2
|
+
module Administration
|
|
3
|
+
class MembershipsController < ApplicationController
|
|
4
|
+
before_action -> { authorize([ :moduler, :administration, :membership ]) }
|
|
5
|
+
before_action :set_membership, only: %i[ edit update destroy ]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
@filter, @memberships = OrganizationQueryFilter.new(Membership.includes(:user, :organization, :role), permitted_filter_parameters).call
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new
|
|
12
|
+
@membership = Membership.new(moduler_organization_id: params[:organization_id])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def create
|
|
16
|
+
@membership = Membership.new(permitted_parameters)
|
|
17
|
+
|
|
18
|
+
if @membership.save
|
|
19
|
+
redirect_to moduler.administration_memberships_path, notice: t(".notice")
|
|
20
|
+
else
|
|
21
|
+
render :new, status: :unprocessable_entity
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def edit; end
|
|
26
|
+
|
|
27
|
+
def update
|
|
28
|
+
if @membership.update(permitted_update_parameters)
|
|
29
|
+
redirect_to moduler.administration_memberships_path, notice: t(".notice")
|
|
30
|
+
else
|
|
31
|
+
render :edit, status: :unprocessable_entity
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def destroy
|
|
36
|
+
@membership.destroy!
|
|
37
|
+
|
|
38
|
+
redirect_to moduler.administration_memberships_path, status: :see_other, notice: t(".notice")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def set_membership
|
|
44
|
+
@membership = Membership.find(params[:id])
|
|
45
|
+
authorize(@membership, policy_class: MembershipPolicy)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def permitted_parameters
|
|
49
|
+
params.expect(membership: %i[ moduler_organization_id moduler_user_id moduler_role_id ])
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# The organization and user of a membership cannot be changed, only the role.
|
|
53
|
+
def permitted_update_parameters
|
|
54
|
+
params.expect(membership: %i[ moduler_role_id ])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def permitted_filter_parameters
|
|
58
|
+
(params.permit(filter: %i[ query organization_id ])[:filter] || {}).merge(params.permit(:page))
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Moduler
|
|
2
|
+
module Administration
|
|
3
|
+
class OrganizationsController < ApplicationController
|
|
4
|
+
before_action -> { authorize([ :moduler, :administration, :organization ]) }
|
|
5
|
+
before_action :set_organization, only: %i[ edit update ]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
@filter, @organizations = QueryFilter.new(Organization.all, permitted_filter_parameters).call
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new
|
|
12
|
+
@organization = Organization.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def create
|
|
16
|
+
@organization = Organization.new(permitted_parameters)
|
|
17
|
+
|
|
18
|
+
if @organization.save
|
|
19
|
+
redirect_to moduler.administration_organizations_path, notice: t(".notice")
|
|
20
|
+
else
|
|
21
|
+
render :new, status: :unprocessable_entity
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def edit; end
|
|
26
|
+
|
|
27
|
+
def update
|
|
28
|
+
if @organization.update(permitted_parameters)
|
|
29
|
+
redirect_to moduler.administration_organizations_path, notice: t(".notice")
|
|
30
|
+
else
|
|
31
|
+
render :edit, status: :unprocessable_entity
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def set_organization
|
|
38
|
+
@organization = Organization.find(params[:id])
|
|
39
|
+
authorize(@organization, policy_class: OrganizationPolicy)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def permitted_parameters
|
|
43
|
+
params.expect(organization: %i[ name ])
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def permitted_filter_parameters
|
|
47
|
+
(params.permit(filter: %i[ query ])[:filter] || {}).merge(params.permit(:page))
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
module Moduler
|
|
2
|
+
module Administration
|
|
3
|
+
class PreferencesController < ApplicationController
|
|
4
|
+
before_action -> { authorize([ :moduler, :administration, :preference ]) }
|
|
5
|
+
before_action :set_preference, only: %i[ edit update destroy ]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
@filter, @preferences = QueryFilter.new(Preference, permitted_filter_parameters).call
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new
|
|
12
|
+
@preference = Preference.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def create
|
|
16
|
+
@preference = Preference.new(permitted_parameters)
|
|
17
|
+
|
|
18
|
+
if @preference.save
|
|
19
|
+
redirect_to moduler.administration_preferences_path, notice: t(".notice")
|
|
20
|
+
else
|
|
21
|
+
render :new, status: :unprocessable_entity
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def edit; end
|
|
26
|
+
|
|
27
|
+
def update
|
|
28
|
+
if @preference.update(permitted_parameters)
|
|
29
|
+
redirect_to moduler.administration_preferences_path, notice: t(".notice")
|
|
30
|
+
else
|
|
31
|
+
render :edit, status: :unprocessable_entity
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def destroy
|
|
36
|
+
@preference.destroy!
|
|
37
|
+
|
|
38
|
+
redirect_to moduler.administration_preferences_path, status: :see_other, notice: t(".notice")
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
private
|
|
42
|
+
|
|
43
|
+
def set_preference
|
|
44
|
+
@preference = Preference.find(params[:id])
|
|
45
|
+
authorize(@preference, policy_class: PreferencePolicy)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def permitted_parameters
|
|
49
|
+
params.expect(preference: %i[ kind name value ])
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def permitted_filter_parameters
|
|
53
|
+
(params.permit(filter: %i[ query ])[:filter] || {}).merge(params.permit(:page))
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module Moduler
|
|
2
|
+
module Administration
|
|
3
|
+
class RolesController < ApplicationController
|
|
4
|
+
before_action -> { authorize([ :moduler, :administration, :role ]) }
|
|
5
|
+
before_action :set_role, only: %i[ edit update ]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
@filter, @roles = OrganizationQueryFilter.new(Role.includes(:organization), permitted_filter_parameters).call
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def new
|
|
12
|
+
@role = Role.new(moduler_organization_id: params[:organization_id])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def create
|
|
16
|
+
@role = Role.new(permitted_parameters)
|
|
17
|
+
|
|
18
|
+
if @role.save
|
|
19
|
+
redirect_to moduler.administration_roles_path, notice: t(".notice")
|
|
20
|
+
else
|
|
21
|
+
render :new, status: :unprocessable_entity
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def edit; end
|
|
26
|
+
|
|
27
|
+
def update
|
|
28
|
+
if @role.update(permitted_update_parameters)
|
|
29
|
+
redirect_to moduler.administration_roles_path, notice: t(".notice")
|
|
30
|
+
else
|
|
31
|
+
render :edit, status: :unprocessable_entity
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def set_role
|
|
38
|
+
@role = Role.find(params[:id])
|
|
39
|
+
authorize(@role, policy_class: RolePolicy)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def permitted_parameters
|
|
43
|
+
params.expect(role: [ :moduler_organization_id, :name, permissions: [] ])
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# The organization is set only when the role is created and cannot be changed.
|
|
47
|
+
def permitted_update_parameters
|
|
48
|
+
params.expect(role: [ :name, permissions: [] ])
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def permitted_filter_parameters
|
|
52
|
+
(params.permit(filter: %i[ query organization_id ])[:filter] || {}).merge(params.permit(:page))
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -41,11 +41,11 @@ module Moduler
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
def permitted_parameters
|
|
44
|
-
params.expect(user: %i[ email_address role password ])
|
|
44
|
+
params.expect(user: %i[ email_address name role status password ])
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
def permitted_update_parameters
|
|
48
|
-
params.expect(user: %i[ email_address role ])
|
|
48
|
+
params.expect(user: %i[ email_address name role status ])
|
|
49
49
|
end
|
|
50
50
|
|
|
51
51
|
def permitted_filter_parameters
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
module Moduler
|
|
2
2
|
class ApplicationController < ActionController::Base
|
|
3
3
|
include Authentication
|
|
4
|
+
include RestrictAdministratorAccess
|
|
5
|
+
include RequireDocumentAcceptance
|
|
4
6
|
include Pundit::Authorization
|
|
5
7
|
|
|
6
8
|
default_form_builder FormBuilder
|
|
@@ -16,7 +18,7 @@ module Moduler
|
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def not_authorized
|
|
19
|
-
redirect_to
|
|
21
|
+
redirect_to current_home_path, alert: t("moduler.flash.not_authorized")
|
|
20
22
|
end
|
|
21
23
|
end
|
|
22
24
|
end
|
|
@@ -3,13 +3,15 @@ module Moduler
|
|
|
3
3
|
layout "moduler/articles"
|
|
4
4
|
|
|
5
5
|
allow_unauthenticated_access
|
|
6
|
+
skip_document_acceptance
|
|
7
|
+
allow_administrator_access
|
|
6
8
|
|
|
7
9
|
def index
|
|
8
|
-
@articles = Article.order(created_at: :desc).page(params[:page])
|
|
10
|
+
@articles = Article.published.order(created_at: :desc).page(params[:page])
|
|
9
11
|
end
|
|
10
12
|
|
|
11
13
|
def show
|
|
12
|
-
@article = Article.find_by!(path: params[:path])
|
|
14
|
+
@article = Article.published.find_by!(path: params[:path])
|
|
13
15
|
end
|
|
14
16
|
end
|
|
15
17
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module Moduler
|
|
2
|
+
class DocumentAcceptancesController < ApplicationController
|
|
3
|
+
skip_document_acceptance
|
|
4
|
+
|
|
5
|
+
before_action :set_document_acceptance
|
|
6
|
+
|
|
7
|
+
def new; end
|
|
8
|
+
|
|
9
|
+
def create
|
|
10
|
+
if @document_acceptance.call
|
|
11
|
+
redirect_to moduler.root_path, notice: t(".notice")
|
|
12
|
+
else
|
|
13
|
+
flash.now[:alert] = @document_acceptance.errors.full_messages.to_sentence
|
|
14
|
+
|
|
15
|
+
render :new, status: :unprocessable_entity
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def set_document_acceptance
|
|
22
|
+
@document_acceptance = DocumentAcceptance.new(Current.user, params.dig(:document_acceptance, :document_ids))
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Moduler
|
|
2
|
+
module Profile
|
|
3
|
+
# Emails delivered to the signed-in user.
|
|
4
|
+
class SentEmailsController < ApplicationController
|
|
5
|
+
skip_document_acceptance
|
|
6
|
+
allow_administrator_access
|
|
7
|
+
|
|
8
|
+
def index
|
|
9
|
+
@sent_emails = Current.user.sent_emails.with_attached_attachments.order(created_at: :desc).page(params[:page]).per(20)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# The email as it was delivered.
|
|
13
|
+
def show
|
|
14
|
+
render html: Current.user.sent_emails.find(params[:id]).body.html_safe, layout: false
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -2,6 +2,9 @@ module Moduler
|
|
|
2
2
|
module Profile
|
|
3
3
|
module Sessions
|
|
4
4
|
class RevocationController < ApplicationController
|
|
5
|
+
skip_document_acceptance
|
|
6
|
+
allow_administrator_access
|
|
7
|
+
|
|
5
8
|
def destroy
|
|
6
9
|
Current.user.sessions.active.update_all(signed_out_at: Time.current)
|
|
7
10
|
cookies.delete(:session_id)
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
module Moduler
|
|
2
2
|
class ProfileController < ApplicationController
|
|
3
|
+
skip_document_acceptance
|
|
4
|
+
allow_administrator_access
|
|
5
|
+
|
|
3
6
|
def edit
|
|
4
7
|
@user = Current.user
|
|
5
8
|
end
|
|
@@ -20,8 +23,10 @@ module Moduler
|
|
|
20
23
|
|
|
21
24
|
private
|
|
22
25
|
|
|
26
|
+
# The current password is required only to change the password.
|
|
23
27
|
def permitted_parameters
|
|
24
|
-
params.expect(user: %i[ password_challenge password password_confirmation ])
|
|
28
|
+
parameters = params.expect(user: %i[ name password_challenge password password_confirmation ])
|
|
29
|
+
parameters[:password].blank? ? parameters.except(:password_challenge, :password, :password_confirmation) : parameters
|
|
25
30
|
end
|
|
26
31
|
end
|
|
27
32
|
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
module Moduler
|
|
2
2
|
class SessionsController < ApplicationController
|
|
3
3
|
allow_unauthenticated_access only: %i[ new create ]
|
|
4
|
+
skip_document_acceptance
|
|
5
|
+
allow_administrator_access
|
|
4
6
|
|
|
5
7
|
rate_limit to: 10, within: 3.minutes, only: :create,
|
|
6
8
|
with: -> { redirect_to moduler.new_session_path, alert: t("moduler.sessions.create.rate_limited") }
|
|
@@ -18,16 +20,14 @@ module Moduler
|
|
|
18
20
|
end
|
|
19
21
|
|
|
20
22
|
def create
|
|
21
|
-
|
|
23
|
+
user = User.authenticate_by(params.require(:user).permit(:email_address, :password))
|
|
24
|
+
|
|
25
|
+
if user&.active?
|
|
22
26
|
start_new_session_for user
|
|
23
27
|
|
|
24
28
|
redirect_to after_authentication_url
|
|
25
29
|
else
|
|
26
|
-
|
|
27
|
-
user.errors.add(:base, t("moduler.sessions.create.invalid_credentials"))
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
render :new
|
|
30
|
+
render_sign_in_error(user ? "inactive_account" : "invalid_credentials")
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -35,5 +35,15 @@ module Moduler
|
|
|
35
35
|
terminate_session
|
|
36
36
|
redirect_to moduler.new_session_path, status: :see_other
|
|
37
37
|
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def render_sign_in_error(key)
|
|
42
|
+
@user = User.new.tap do |user|
|
|
43
|
+
user.errors.add(:base, t("moduler.sessions.create.#{key}"))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
render :new
|
|
47
|
+
end
|
|
38
48
|
end
|
|
39
49
|
end
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
module Moduler
|
|
2
2
|
class UsersController < ApplicationController
|
|
3
3
|
allow_unauthenticated_access only: %i[ new create ]
|
|
4
|
+
skip_document_acceptance
|
|
5
|
+
allow_administrator_access
|
|
4
6
|
|
|
5
7
|
rate_limit to: 10, within: 3.minutes, only: :create,
|
|
6
8
|
with: -> { redirect_to moduler.new_user_path, alert: t("moduler.users.create.rate_limited") }
|
|
@@ -21,6 +23,7 @@ module Moduler
|
|
|
21
23
|
@user = User.new(permitted_parameters)
|
|
22
24
|
|
|
23
25
|
if @user.save
|
|
26
|
+
Email.deliver_event("user.signup", to: @user)
|
|
24
27
|
redirect_to moduler.new_session_path, notice: t("moduler.users.create.success")
|
|
25
28
|
else
|
|
26
29
|
render :new
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Filters the users an email can be sent to, see
|
|
2
|
+
# Moduler::Administration::Emails::DeliveriesController.
|
|
3
|
+
class EmailDeliveryFilter < ApplicationFilter
|
|
4
|
+
PER_PAGE = [ 25, 50, 100 ].freeze
|
|
5
|
+
|
|
6
|
+
attribute :query, :string
|
|
7
|
+
attribute :role, :string
|
|
8
|
+
attribute :sent, :string
|
|
9
|
+
attribute :per_page, :integer
|
|
10
|
+
attribute :page, :integer
|
|
11
|
+
|
|
12
|
+
validates :query, length: { maximum: 100 }
|
|
13
|
+
|
|
14
|
+
modifiers << proc do |scope, filter|
|
|
15
|
+
scope.page(filter.page).per(PER_PAGE.include?(filter.per_page) ? filter.per_page : PER_PAGE.first)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
modifiers << proc do |scope, filter|
|
|
19
|
+
if filter.query.present?
|
|
20
|
+
query = "%#{ActiveRecord::Base.sanitize_sql_like(filter.query)}%"
|
|
21
|
+
scope.where("moduler_users.email_address ILIKE :query OR moduler_users.name ILIKE :query", query: query)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
modifiers << proc do |scope, filter|
|
|
26
|
+
scope.where(role: filter.role) if Moduler::User.roles.key?(filter.role)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
modifiers << proc do |scope, filter|
|
|
30
|
+
case filter.sent
|
|
31
|
+
when "true" then scope.where.not(moduler_user_emails: { sent_at: nil })
|
|
32
|
+
when "false" then scope.where(moduler_user_emails: { sent_at: nil })
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
class OrganizationQueryFilter < ApplicationFilter
|
|
2
|
+
attribute :query, :string
|
|
3
|
+
attribute :organization_id, :string
|
|
4
|
+
attribute :page, :integer
|
|
5
|
+
|
|
6
|
+
validates :query, length: { maximum: 100 }
|
|
7
|
+
|
|
8
|
+
modifiers << proc do |scope, filter|
|
|
9
|
+
scope.page(filter.page).per(10)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
modifiers << proc do |scope, _filter|
|
|
13
|
+
scope.order(created_at: :desc)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
modifiers << proc do |scope, filter|
|
|
17
|
+
scope.search_by_query(filter.query) if filter.query.present?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
modifiers << proc do |scope, filter|
|
|
21
|
+
scope.where(moduler_organization_id: filter.organization_id) if filter.organization_id.present?
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Moduler
|
|
2
|
+
class EmailDeliveryJob < ApplicationJob
|
|
3
|
+
queue_as :default
|
|
4
|
+
|
|
5
|
+
discard_on ActiveJob::DeserializationError
|
|
6
|
+
|
|
7
|
+
def perform(user_email)
|
|
8
|
+
return if user_email.sent?
|
|
9
|
+
|
|
10
|
+
EmailMailer.with(email: user_email.email, user: user_email.user).custom.deliver_now
|
|
11
|
+
user_email.touch(:sent_at)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|