lato_spaces 3.1.24 → 3.3.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/README.md +156 -13
- data/app/controllers/concerns/lato_spaces/groupable.rb +23 -10
- data/app/controllers/lato_spaces/application_controller.rb +32 -26
- data/app/controllers/lato_spaces/groups_controller.rb +21 -10
- data/app/controllers/lato_spaces/memberships_controller.rb +25 -11
- data/app/helpers/lato_spaces/application_helper.rb +6 -0
- data/app/helpers/lato_spaces/groups_helper.rb +1 -1
- data/app/helpers/lato_spaces/memberships_helper.rb +19 -5
- data/app/models/concerns/lato_spaces/associable.rb +15 -6
- data/app/models/concerns/lato_spaces/associable_required.rb +10 -15
- data/app/models/concerns/lato_spaces/associable_unique.rb +2 -12
- data/app/models/lato_spaces/association.rb +22 -0
- data/app/models/lato_spaces/membership.rb +53 -22
- data/app/views/lato_spaces/application/index.html.erb +28 -18
- data/app/views/lato_spaces/groups/create.html.erb +2 -5
- data/app/views/lato_spaces/groups/show.html.erb +9 -8
- data/app/views/lato_spaces/groups/update.html.erb +4 -6
- data/app/views/lato_spaces/memberships/_form.html.erb +4 -1
- data/app/views/lato_spaces/memberships/create.html.erb +3 -5
- data/app/views/layouts/lato_spaces/_group-informations_content.html.erb +3 -3
- data/config/locales/en.yml +54 -2
- data/config/locales/it.yml +52 -4
- data/db/migrate/20261110120000_add_unique_indexes_to_lato_spaces.rb +33 -0
- data/lib/lato_spaces/config.rb +3 -3
- data/lib/lato_spaces/version.rb +1 -1
- metadata +14 -10
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
module LatoSpaces::AssociableRequired
|
|
2
2
|
extend ActiveSupport::Concern
|
|
3
3
|
|
|
4
|
+
# NOTE: LatoSpaces::Association destroys items including this module when
|
|
5
|
+
# their association is destroyed (e.g. on group destruction).
|
|
6
|
+
|
|
4
7
|
attr_writer :lato_spaces_group_id
|
|
5
8
|
|
|
6
9
|
included do
|
|
@@ -8,26 +11,18 @@ module LatoSpaces::AssociableRequired
|
|
|
8
11
|
##
|
|
9
12
|
|
|
10
13
|
validates :lato_spaces_group_id, presence: true, on: :create
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
after_create_commit do
|
|
16
|
-
unless lato_spaces_associations.create(lato_spaces_group_id: lato_spaces_group_id)
|
|
17
|
-
Rails.logger.error "Failed to create LatoSpaces association for #{self.class.name} with ID #{id} and group ID #{lato_spaces_group_id}"
|
|
14
|
+
validate on: :create do
|
|
15
|
+
if lato_spaces_group_id.present? && !LatoSpaces::Group.exists?(id: lato_spaces_group_id)
|
|
16
|
+
errors.add(:lato_spaces_group_id, :invalid)
|
|
18
17
|
end
|
|
19
18
|
end
|
|
20
19
|
|
|
21
|
-
#
|
|
20
|
+
# Hooks
|
|
22
21
|
##
|
|
23
22
|
|
|
24
|
-
#
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
unless association.item.destroy
|
|
28
|
-
Rails.logger.error "Failed to destroy #{association.item.class.name} with ID #{association.item_id} after LatoSpaces association destruction"
|
|
29
|
-
end
|
|
30
|
-
end
|
|
23
|
+
# Runs inside the create transaction: a failure rolls back the item.
|
|
24
|
+
after_create do
|
|
25
|
+
lato_spaces_associations.create!(lato_spaces_group_id: lato_spaces_group_id)
|
|
31
26
|
end
|
|
32
27
|
end
|
|
33
28
|
end
|
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
module LatoSpaces::AssociableUnique
|
|
2
2
|
extend ActiveSupport::Concern
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
##
|
|
7
|
-
|
|
8
|
-
# listen LatoSpaces::Association create event to avoid duplicate associations
|
|
9
|
-
LatoSpaces::Association.before_create do |association|
|
|
10
|
-
if association.item&.lato_spaces_associations&.length&.positive?
|
|
11
|
-
throw(:abort)
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
4
|
+
# Marker concern: LatoSpaces::Association rejects a second association
|
|
5
|
+
# for items including this module.
|
|
15
6
|
end
|
|
16
|
-
|
|
@@ -10,5 +10,27 @@ module LatoSpaces
|
|
|
10
10
|
##
|
|
11
11
|
|
|
12
12
|
validates :lato_spaces_group_id, uniqueness: { scope: [:item_id, :item_type] }
|
|
13
|
+
|
|
14
|
+
# Items using LatoSpaces::AssociableUnique can belong to a single group.
|
|
15
|
+
validate on: :create do
|
|
16
|
+
next unless item.is_a?(LatoSpaces::AssociableUnique)
|
|
17
|
+
next unless LatoSpaces::Association.where(item_type: item_type, item_id: item_id).exists?
|
|
18
|
+
|
|
19
|
+
errors.add(:item, :already_associated)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Hooks
|
|
23
|
+
##
|
|
24
|
+
|
|
25
|
+
# Items using LatoSpaces::AssociableRequired can not live without a group:
|
|
26
|
+
# destroying their association destroys them. The check is done per item,
|
|
27
|
+
# so models using only LatoSpaces::Associable are never affected.
|
|
28
|
+
after_destroy_commit do
|
|
29
|
+
next unless item.is_a?(LatoSpaces::AssociableRequired)
|
|
30
|
+
|
|
31
|
+
unless item.destroy
|
|
32
|
+
Rails.logger.error "Failed to destroy #{item_type} with ID #{item_id} after LatoSpaces association destruction"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
13
35
|
end
|
|
14
36
|
end
|
|
@@ -3,6 +3,7 @@ module LatoSpaces
|
|
|
3
3
|
include LatoSpacesMembershipApplication
|
|
4
4
|
|
|
5
5
|
attr_accessor :email
|
|
6
|
+
attr_accessor :invitations_disabled # when true, unregistered emails are rejected instead of invited
|
|
6
7
|
attr_accessor :user_infos, :actions # lato index
|
|
7
8
|
|
|
8
9
|
# Relations
|
|
@@ -16,34 +17,58 @@ module LatoSpaces
|
|
|
16
17
|
##
|
|
17
18
|
|
|
18
19
|
scope :lato_index_order, ->(column, order) do
|
|
19
|
-
|
|
20
|
+
direction = order.to_s.casecmp?('desc') ? 'DESC' : 'ASC'
|
|
21
|
+
return left_joins(:lato_user, :lato_invitation).order(Arel.sql("lato_users.last_name #{direction}, lato_users.first_name #{direction}, lato_users.email #{direction}, lato_invitations.email #{direction}")) if column == :user_infos
|
|
20
22
|
|
|
21
|
-
order(
|
|
23
|
+
order(column => direction)
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
scope :lato_index_search, ->(search) do
|
|
25
27
|
left_joins(:lato_user, :lato_invitation).where("lower(lato_users.first_name) LIKE :search OR lower(lato_users.last_name) LIKE :search OR lower(lato_users.email) LIKE :search OR lower(lato_invitations.email) LIKE :search", search: "%#{search.downcase.strip}%")
|
|
26
28
|
end
|
|
27
29
|
|
|
30
|
+
# Validations
|
|
31
|
+
##
|
|
32
|
+
|
|
33
|
+
validate on: :create do
|
|
34
|
+
next if lato_user_id.present? || lato_invitation_id.present?
|
|
35
|
+
|
|
36
|
+
if email.blank?
|
|
37
|
+
errors.add(:email, :blank)
|
|
38
|
+
elsif invitations_disabled
|
|
39
|
+
errors.add(:email, :invitation_not_permitted)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
validate on: :create do
|
|
44
|
+
group_memberships = LatoSpaces::Membership.where(lato_spaces_group_id: lato_spaces_group_id)
|
|
45
|
+
taken = (lato_user_id.present? && group_memberships.exists?(lato_user_id: lato_user_id)) ||
|
|
46
|
+
(lato_invitation_id.present? && group_memberships.exists?(lato_invitation_id: lato_invitation_id))
|
|
47
|
+
errors.add(:email, :already_member) if taken
|
|
48
|
+
end
|
|
49
|
+
|
|
28
50
|
# Hooks
|
|
29
51
|
##
|
|
30
52
|
|
|
31
|
-
#
|
|
53
|
+
# resolve email to an existing user or invitation
|
|
54
|
+
before_validation on: :create do
|
|
55
|
+
self.email = email.to_s.strip.downcase.presence
|
|
56
|
+
next if lato_user_id.present? || lato_invitation_id.present? || email.blank?
|
|
57
|
+
|
|
58
|
+
self.lato_user = Lato::User.find_by(email: email)
|
|
59
|
+
self.lato_invitation = Lato::Invitation.find_by(email: email) unless lato_user
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# create (and send) the invitation only once validations passed
|
|
32
63
|
before_create do
|
|
33
|
-
if
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
invitation ||= Lato::Invitation.create(email: email)
|
|
40
|
-
unless invitation
|
|
41
|
-
errors.add(:email, 'There was an error with the invitation.')
|
|
42
|
-
throw(:abort)
|
|
43
|
-
end
|
|
44
|
-
self.lato_invitation_id = invitation.id
|
|
45
|
-
end
|
|
64
|
+
next if lato_user_id.present? || lato_invitation_id.present?
|
|
65
|
+
|
|
66
|
+
invitation = Lato::Invitation.create(email: email)
|
|
67
|
+
unless invitation.persisted?
|
|
68
|
+
errors.add(:base, invitation.errors.full_messages.to_sentence.presence || :invitation_error)
|
|
69
|
+
throw(:abort)
|
|
46
70
|
end
|
|
71
|
+
self.lato_invitation = invitation
|
|
47
72
|
end
|
|
48
73
|
|
|
49
74
|
# External hooks
|
|
@@ -51,8 +76,12 @@ module LatoSpaces
|
|
|
51
76
|
|
|
52
77
|
# listen Lato::Invitation save event to update memberships
|
|
53
78
|
Lato::Invitation.after_save do |invitation|
|
|
54
|
-
if invitation.lato_user_id.
|
|
55
|
-
|
|
79
|
+
next if invitation.lato_user_id.blank?
|
|
80
|
+
|
|
81
|
+
LatoSpaces::Membership.where(lato_invitation_id: invitation.id).each do |space_member|
|
|
82
|
+
if LatoSpaces::Membership.exists?(lato_spaces_group_id: space_member.lato_spaces_group_id, lato_user_id: invitation.lato_user_id)
|
|
83
|
+
space_member.destroy!
|
|
84
|
+
else
|
|
56
85
|
space_member.update!(lato_user_id: invitation.lato_user_id, lato_invitation_id: nil)
|
|
57
86
|
end
|
|
58
87
|
end
|
|
@@ -71,10 +100,12 @@ module LatoSpaces
|
|
|
71
100
|
# Helpers
|
|
72
101
|
##
|
|
73
102
|
|
|
74
|
-
|
|
75
|
-
|
|
103
|
+
# show_name: false hides the registered user's full name (only the email is shown)
|
|
104
|
+
def user_infos_label(show_name: true)
|
|
105
|
+
return (show_name ? lato_user.full_name : lato_user.email) if lato_user.present?
|
|
76
106
|
return lato_invitation.email if lato_invitation.present?
|
|
77
|
-
|
|
107
|
+
|
|
108
|
+
I18n.t('lato_spaces.unknown_member')
|
|
78
109
|
end
|
|
79
110
|
|
|
80
111
|
# Operations
|
|
@@ -91,7 +122,7 @@ module LatoSpaces
|
|
|
91
122
|
|
|
92
123
|
def send_invite
|
|
93
124
|
if lato_invitation.blank? || lato_user.present?
|
|
94
|
-
errors.add(:base,
|
|
125
|
+
errors.add(:base, :already_joined)
|
|
95
126
|
return false
|
|
96
127
|
end
|
|
97
128
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<%= lato_page_head I18n.t('lato_spaces.spaces') do %>
|
|
2
|
-
<p class="lead"><%=
|
|
2
|
+
<p class="lead"><%= t('lato_spaces.welcome_html', user: @session.user.first_name) %></p>
|
|
3
3
|
<% end %>
|
|
4
4
|
|
|
5
5
|
<%= turbo_frame_tag 'index' do %>
|
|
@@ -18,34 +18,44 @@
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
groups = groups.sort_by { |g| [g[:is_preferred] ? 0 : 1, g[:name].downcase] }
|
|
21
|
+
can_create = @session.user.lato_spaces_admin || LatoSpaces.config.permit_group_creation
|
|
21
22
|
%>
|
|
22
23
|
|
|
24
|
+
<% if groups.empty? && !can_create %>
|
|
25
|
+
<div class="alert alert-info" role="status"><%= I18n.t('lato_spaces.no_groups') %></div>
|
|
26
|
+
<% end %>
|
|
27
|
+
|
|
23
28
|
<div class="row">
|
|
24
29
|
<% groups.each do |group| %>
|
|
25
|
-
<div class="col
|
|
26
|
-
<div class="card h-100 border border-4
|
|
27
|
-
<%= link_to lato_spaces.setgroup_path(group[:id]), class: "position-absolute top-0 left-0 w-100 h-100", data: { turbo_method: :post } do %><% end %>
|
|
30
|
+
<div class="col-12 col-md-6 col-lg-4 col-xl-3 mb-3">
|
|
31
|
+
<div class="card h-100 border border-4 <%= group[:is_selected] ? 'border-success' : 'border-light' %>" <%= 'aria-current="true"'.html_safe if group[:is_selected] %>>
|
|
28
32
|
<div class="card-body">
|
|
29
33
|
<div class="d-flex align-items-center justify-content-between d-lg-block">
|
|
30
34
|
<div class="d-flex align-items-center d-lg-block text-center">
|
|
31
|
-
<i class="<%= LatoSpaces.config.group_icon %> fs-1 me-2 me-lg-0"></i><br>
|
|
35
|
+
<i class="<%= LatoSpaces.config.group_icon %> fs-1 me-2 me-lg-0" aria-hidden="true"></i><br>
|
|
32
36
|
<span class="fw-bold"><%= group[:name] %></span>
|
|
37
|
+
<% if group[:is_selected] %>
|
|
38
|
+
<span class="badge text-bg-success ms-1"><%= I18n.t('lato_spaces.selected') %></span>
|
|
39
|
+
<% end %>
|
|
40
|
+
<% if group[:is_preferred] && LatoSpaces.config.permit_group_preferred %>
|
|
41
|
+
<span class="badge text-bg-warning ms-1"><%= I18n.t('lato_spaces.preferred') %></span>
|
|
42
|
+
<% end %>
|
|
33
43
|
</div>
|
|
34
|
-
<div class="d-flex justify-content-center align-items-center mt-lg-2
|
|
44
|
+
<div class="d-flex justify-content-center align-items-center mt-lg-2">
|
|
35
45
|
<% if @session.user.lato_spaces_admin || LatoSpaces.config.permit_group_management %>
|
|
36
|
-
<%= link_to lato_spaces.groups_show_path(group[:id]), class: "btn btn-light me-1", data: { turbo_frame: '_top' } do %>
|
|
37
|
-
<i class="bi bi-gear"></i>
|
|
46
|
+
<%= link_to lato_spaces.groups_show_path(group[:id]), class: "btn btn-light me-1", title: I18n.t('lato_spaces.aria.manage_group', name: group[:name]), aria: { label: I18n.t('lato_spaces.aria.manage_group', name: group[:name]) }, data: { turbo_frame: '_top' } do %>
|
|
47
|
+
<i class="bi bi-gear" aria-hidden="true"></i>
|
|
38
48
|
<% end %>
|
|
39
49
|
<% end %>
|
|
40
50
|
|
|
41
51
|
<% if LatoSpaces.config.permit_group_preferred %>
|
|
42
|
-
<%=
|
|
43
|
-
<i class="bi bi-star<%= group[:is_preferred] ? '-fill' : '' %>"></i>
|
|
52
|
+
<%= button_to lato_spaces.setpreferred_path(group[:id]), class: "btn btn-#{group[:is_preferred] ? 'warning' : 'light'} ms-1 me-1", title: I18n.t('lato_spaces.aria.prefer_group', name: group[:name]), aria: { label: I18n.t('lato_spaces.aria.prefer_group', name: group[:name]), pressed: group[:is_preferred] ? 'true' : 'false' } do %>
|
|
53
|
+
<i class="bi bi-star<%= group[:is_preferred] ? '-fill' : '' %>" aria-hidden="true"></i>
|
|
44
54
|
<% end %>
|
|
45
55
|
<% end %>
|
|
46
56
|
|
|
47
|
-
<%=
|
|
48
|
-
<i class="bi bi-check-circle<%= group[:is_selected] ? '-fill' : '' %>"></i>
|
|
57
|
+
<%= button_to lato_spaces.setgroup_path(group[:id]), class: "btn btn-#{group[:is_selected] ? 'success' : 'primary'} ms-1", form: { data: { turbo_frame: '_top' } }, title: I18n.t('lato_spaces.aria.select_group', name: group[:name]), aria: { label: I18n.t('lato_spaces.aria.select_group', name: group[:name]) } do %>
|
|
58
|
+
<i class="bi bi-check-circle<%= group[:is_selected] ? '-fill' : '' %>" aria-hidden="true"></i>
|
|
49
59
|
<% end %>
|
|
50
60
|
</div>
|
|
51
61
|
</div>
|
|
@@ -55,22 +65,22 @@
|
|
|
55
65
|
<% end %>
|
|
56
66
|
|
|
57
67
|
<% if @session.user.lato_spaces_admin %>
|
|
58
|
-
<div class="col
|
|
59
|
-
<%= link_to lato_spaces.groups_path, class: 'card border border-4 border-primary bg-primary text-white text-decoration-none h-100' do %>
|
|
68
|
+
<div class="col-12 col-md-6 col-lg-4 col-xl-3 mb-3">
|
|
69
|
+
<%= link_to lato_spaces.groups_path, class: 'card border border-4 border-primary bg-primary text-white text-decoration-none h-100', data: { turbo_frame: '_top' } do %>
|
|
60
70
|
<div class="card-body d-flex flex-column justify-content-center align-items-center">
|
|
61
71
|
<div class="text-center">
|
|
62
|
-
<i class="bi bi-sliders fs-1"></i><br>
|
|
72
|
+
<i class="bi bi-sliders fs-1" aria-hidden="true"></i><br>
|
|
63
73
|
<span class="fw-bold"><%= I18n.t('lato_spaces.cta_manage_groups') %></span>
|
|
64
74
|
</div>
|
|
65
75
|
</div>
|
|
66
76
|
<% end %>
|
|
67
77
|
</div>
|
|
68
78
|
<% elsif LatoSpaces.config.permit_group_creation %>
|
|
69
|
-
<div class="col
|
|
79
|
+
<div class="col-12 col-md-6 col-lg-4 col-xl-3 mb-3">
|
|
70
80
|
<%= link_to lato_spaces.groups_create_path, class: 'card border border-4 border-primary bg-primary text-white text-decoration-none h-100', data: { lato_action_target: 'trigger', turbo_frame: dom_id(LatoSpaces::Group.new, 'form'), action_title: I18n.t('lato_spaces.new_group') } do %>
|
|
71
81
|
<div class="card-body d-flex flex-column justify-content-center align-items-center">
|
|
72
82
|
<div class="text-center">
|
|
73
|
-
<i class="bi bi-plus-circle fs-1"></i><br>
|
|
83
|
+
<i class="bi bi-plus-circle fs-1" aria-hidden="true"></i><br>
|
|
74
84
|
<span class="fw-bold"><%= I18n.t('lato_spaces.cta_new_group') %></span>
|
|
75
85
|
</div>
|
|
76
86
|
</div>
|
|
@@ -78,4 +88,4 @@
|
|
|
78
88
|
</div>
|
|
79
89
|
<% end %>
|
|
80
90
|
</div>
|
|
81
|
-
<% end %>
|
|
91
|
+
<% end %>
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
<%= lato_page_head I18n.t('lato_spaces.new_group'),
|
|
2
|
-
{ label: I18n.t('lato_spaces.spaces'), path: lato_spaces.root_path },
|
|
3
|
-
{ label: I18n.t('lato_spaces.groups'), path: lato_spaces.groups_path }
|
|
4
|
-
] %>
|
|
1
|
+
<%= lato_page_head I18n.t('lato_spaces.new_group'), lato_spaces_breadcrumbs %>
|
|
5
2
|
|
|
6
3
|
<div class="card">
|
|
7
4
|
<div class="card-body">
|
|
8
5
|
<%= render "form", group: @group %>
|
|
9
6
|
</div>
|
|
10
|
-
</div>
|
|
7
|
+
</div>
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
{ label: I18n.t('lato_spaces.groups'), path: lato_spaces.groups_path }
|
|
4
|
-
] %>
|
|
1
|
+
<%# h: lato_page_head renders the title as raw HTML %>
|
|
2
|
+
<%= lato_page_head h(@group.name), lato_spaces_breadcrumbs %>
|
|
5
3
|
|
|
6
4
|
<div class="card mb-4">
|
|
7
5
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
8
6
|
<h2 class="fs-4 mb-0"><%= I18n.t('lato_spaces.group_informations') %></h2>
|
|
9
|
-
<div class="
|
|
10
|
-
<%=
|
|
11
|
-
|
|
7
|
+
<div class="d-flex gap-1">
|
|
8
|
+
<%= button_to I18n.t('lato_spaces.cta_select'), lato_spaces.setgroup_path(@group), class: 'btn btn-sm btn-success', form: { data: { turbo_frame: '_top' } }, aria: { label: I18n.t('lato_spaces.aria.select_group', name: @group.name) } %>
|
|
9
|
+
<div class="btn-group btn-group-sm" role="group">
|
|
10
|
+
<%= link_to I18n.t('lato_spaces.cta_edit'), lato_spaces.groups_update_path(@group), class: 'btn btn-primary', data: { lato_action_target: 'trigger', turbo_frame: dom_id(@group, 'form'), action_title: I18n.t('lato_spaces.edit_group') } %>
|
|
11
|
+
<%= link_to I18n.t('lato_spaces.cta_delete'), lato_spaces.groups_destroy_action_path(@group), class: 'btn btn-danger', data: { turbo_confirm: I18n.t('lato_spaces.confirm.group_destroy', name: @group.name, members: @group.lato_spaces_memberships.count, items: @group.lato_spaces_associations.count), turbo_method: :delete } %>
|
|
12
|
+
</div>
|
|
12
13
|
</div>
|
|
13
14
|
</div>
|
|
14
15
|
<div class="card-body">
|
|
@@ -31,4 +32,4 @@
|
|
|
31
32
|
}
|
|
32
33
|
%>
|
|
33
34
|
</div>
|
|
34
|
-
</div>
|
|
35
|
+
</div>
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
<%= lato_page_head I18n.t('lato_spaces.edit_group'),
|
|
2
|
-
{ label:
|
|
3
|
-
|
|
4
|
-
{ label: @group.name, path: lato_spaces.groups_show_path(@group) }
|
|
5
|
-
] %>
|
|
1
|
+
<%= lato_page_head I18n.t('lato_spaces.edit_group'), lato_spaces_breadcrumbs(
|
|
2
|
+
{ label: @group.name_was, path: lato_spaces.groups_show_path(@group) }
|
|
3
|
+
) %>
|
|
6
4
|
|
|
7
5
|
<div class="card">
|
|
8
6
|
<div class="card-body">
|
|
9
7
|
<%= render "form", group: @group %>
|
|
10
8
|
</div>
|
|
11
|
-
</div>
|
|
9
|
+
</div>
|
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
<div class="mb-3">
|
|
7
7
|
<%= lato_form_item_label form, :email %>
|
|
8
|
-
<%= lato_form_item_input_email form, :email, required: true %>
|
|
8
|
+
<%= lato_form_item_input_email form, :email, required: true, aria: { describedby: 'membership-email-help' } %>
|
|
9
|
+
<div id="membership-email-help" class="form-text">
|
|
10
|
+
<%= Lato.config.auth_disable_signup && !@session.user.lato_spaces_admin ? I18n.t('lato_spaces.membership_email_help_registered_only') : I18n.t('lato_spaces.membership_email_help') %>
|
|
11
|
+
</div>
|
|
9
12
|
</div>
|
|
10
13
|
|
|
11
14
|
<%= render 'layouts/lato_spaces/membership-form-extra_content', form: form %>
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
<%= lato_page_head I18n.t('lato_spaces.new_membership'),
|
|
2
|
-
{ label: I18n.t('lato_spaces.spaces'), path: lato_spaces.root_path },
|
|
3
|
-
{ label: I18n.t('lato_spaces.groups'), path: lato_spaces.groups_path },
|
|
1
|
+
<%= lato_page_head I18n.t('lato_spaces.new_membership'), lato_spaces_breadcrumbs(
|
|
4
2
|
{ label: @group.name, path: lato_spaces.groups_show_path(@group) }
|
|
5
|
-
|
|
3
|
+
) %>
|
|
6
4
|
|
|
7
5
|
<div class="card">
|
|
8
6
|
<div class="card-body">
|
|
9
7
|
<%= render "form", membership: @membership %>
|
|
10
8
|
</div>
|
|
11
|
-
</div>
|
|
9
|
+
</div>
|
|
@@ -7,12 +7,12 @@ group ||= LatoSpaces::Group.new
|
|
|
7
7
|
<table class="table">
|
|
8
8
|
<tbody>
|
|
9
9
|
<tr>
|
|
10
|
-
<th
|
|
10
|
+
<th scope="row"><%= I18n.t('lato_spaces.total_members') %></th>
|
|
11
11
|
<td><%= group.lato_spaces_memberships.count %></td>
|
|
12
12
|
</tr>
|
|
13
13
|
<tr>
|
|
14
|
-
<th
|
|
14
|
+
<th scope="row"><%= I18n.t('lato_spaces.total_items') %></th>
|
|
15
15
|
<td><%= group.lato_spaces_associations.count %></td>
|
|
16
16
|
</tr>
|
|
17
17
|
</tbody>
|
|
18
|
-
</table>
|
|
18
|
+
</table>
|
data/config/locales/en.yml
CHANGED
|
@@ -4,7 +4,7 @@ en:
|
|
|
4
4
|
spaces: Spaces
|
|
5
5
|
group: Group
|
|
6
6
|
groups: Groups
|
|
7
|
-
|
|
7
|
+
welcome_html: Hi <b>%{user}</b>! Please <b>select the group</b> you want to work on.
|
|
8
8
|
cta_manage_groups: Manage groups
|
|
9
9
|
new_group: New group
|
|
10
10
|
edit_group: Edit group
|
|
@@ -17,8 +17,60 @@ en:
|
|
|
17
17
|
cta_edit: Edit
|
|
18
18
|
cta_delete: Delete
|
|
19
19
|
cta_resend: Resend
|
|
20
|
+
cta_select: Select group
|
|
20
21
|
new_membership: New membership
|
|
22
|
+
no_groups: You are not a member of any group yet. Ask an administrator to add you to a group.
|
|
23
|
+
selected: Selected
|
|
24
|
+
preferred: Preferred
|
|
25
|
+
unknown_member: Unknown
|
|
26
|
+
invitation_pending: Invitation pending (sent %{time} ago)
|
|
27
|
+
total_members: Total members
|
|
28
|
+
total_items: Total items
|
|
29
|
+
membership_email_help: If the email does not belong to a registered user, an invitation email is sent.
|
|
30
|
+
membership_email_help_registered_only: Only registered users can be added. Ask an administrator to invite new users.
|
|
31
|
+
aria:
|
|
32
|
+
view_group: View group %{name}
|
|
33
|
+
manage_group: Manage group %{name}
|
|
34
|
+
prefer_group: Set %{name} as preferred group
|
|
35
|
+
select_group: Select group %{name}
|
|
36
|
+
resend_invitation: Resend invitation to %{name}
|
|
37
|
+
remove_member: Remove %{name} from the group
|
|
38
|
+
confirm:
|
|
39
|
+
group_destroy: Delete group "%{name}"? Its %{members} memberships and %{items} data associations will be removed, and records that require a group will be destroyed. This cannot be undone.
|
|
40
|
+
membership_destroy: Remove %{name} from this group?
|
|
41
|
+
membership_leave: You are about to leave this group and lose access to its data. Continue?
|
|
42
|
+
invite_resend: Resend the invitation email to %{name}?
|
|
43
|
+
flash:
|
|
44
|
+
group_selected: Group selected.
|
|
45
|
+
group_select_error: Error on changing group.
|
|
46
|
+
preferred_error: Error on changing preferred group.
|
|
47
|
+
access_denied: You have not access to this section.
|
|
48
|
+
group_created: Group was successfully created.
|
|
49
|
+
group_updated: Group was successfully updated.
|
|
50
|
+
group_destroyed: Group was successfully destroyed.
|
|
51
|
+
group_destroy_error: Group was not destroyed.
|
|
52
|
+
membership_created: User was successfully added to the group.
|
|
53
|
+
membership_invited: User was invited to the group. They join it after accepting the invitation.
|
|
54
|
+
membership_last_member: The last member can not be removed from the group.
|
|
55
|
+
membership_destroyed: Membership was successfully destroyed.
|
|
56
|
+
membership_destroy_error: Membership was not destroyed.
|
|
57
|
+
invite_sent: Invite was successfully sent.
|
|
58
|
+
invite_error: Invite was not sent.
|
|
21
59
|
activerecord:
|
|
22
60
|
attributes:
|
|
61
|
+
lato_spaces/group:
|
|
62
|
+
name: Name
|
|
63
|
+
actions: Actions
|
|
23
64
|
lato_spaces/membership:
|
|
24
|
-
|
|
65
|
+
email: Email
|
|
66
|
+
user_infos: User
|
|
67
|
+
actions: Actions
|
|
68
|
+
errors:
|
|
69
|
+
models:
|
|
70
|
+
lato_spaces/membership:
|
|
71
|
+
invitation_not_permitted: does not belong to a registered user and invitations are disabled
|
|
72
|
+
already_member: already belongs to a member of this group
|
|
73
|
+
invitation_error: There was an error with the invitation.
|
|
74
|
+
already_joined: This user is already a member of this space.
|
|
75
|
+
lato_spaces/association:
|
|
76
|
+
already_associated: already belongs to a group
|
data/config/locales/it.yml
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
it:
|
|
2
2
|
lato_spaces:
|
|
3
|
-
space:
|
|
4
|
-
spaces:
|
|
3
|
+
space: Spazio
|
|
4
|
+
spaces: Spazi
|
|
5
5
|
group: Gruppo
|
|
6
6
|
groups: Gruppi
|
|
7
|
-
|
|
7
|
+
welcome_html: Ciao <b>%{user}</b>!<b> Seleziona il gruppo</b> con cui vuoi lavorare.
|
|
8
8
|
cta_manage_groups: Gestisci gruppi
|
|
9
9
|
new_group: Nuovo gruppo
|
|
10
10
|
edit_group: Modifica gruppo
|
|
@@ -17,12 +17,60 @@ it:
|
|
|
17
17
|
cta_edit: Modifica
|
|
18
18
|
cta_delete: Cancella
|
|
19
19
|
cta_resend: Reinvia
|
|
20
|
+
cta_select: Seleziona gruppo
|
|
20
21
|
new_membership: Nuova iscrizione
|
|
22
|
+
no_groups: Non sei ancora membro di nessun gruppo. Chiedi a un amministratore di aggiungerti a un gruppo.
|
|
23
|
+
selected: Selezionato
|
|
24
|
+
preferred: Preferito
|
|
25
|
+
unknown_member: Sconosciuto
|
|
26
|
+
invitation_pending: Invito in attesa (inviato %{time} fa)
|
|
27
|
+
total_members: Membri totali
|
|
28
|
+
total_items: Elementi totali
|
|
29
|
+
membership_email_help: Se l'email non appartiene a un utente registrato, viene inviata un'email di invito.
|
|
30
|
+
membership_email_help_registered_only: Puoi aggiungere solo utenti registrati. Chiedi a un amministratore di invitare nuovi utenti.
|
|
31
|
+
aria:
|
|
32
|
+
view_group: Visualizza il gruppo %{name}
|
|
33
|
+
manage_group: Gestisci il gruppo %{name}
|
|
34
|
+
prefer_group: Imposta %{name} come gruppo preferito
|
|
35
|
+
select_group: Seleziona il gruppo %{name}
|
|
36
|
+
resend_invitation: Reinvia l'invito a %{name}
|
|
37
|
+
remove_member: Rimuovi %{name} dal gruppo
|
|
38
|
+
confirm:
|
|
39
|
+
group_destroy: Cancellare il gruppo "%{name}"? Verranno rimossi %{members} membri e %{items} associazioni di dati, e i record che richiedono un gruppo verranno cancellati. L'operazione è irreversibile.
|
|
40
|
+
membership_destroy: Rimuovere %{name} da questo gruppo?
|
|
41
|
+
membership_leave: Stai per uscire da questo gruppo e perderai l'accesso ai suoi dati. Continuare?
|
|
42
|
+
invite_resend: Reinviare l'email di invito a %{name}?
|
|
43
|
+
flash:
|
|
44
|
+
group_selected: Gruppo selezionato.
|
|
45
|
+
group_select_error: Errore durante il cambio di gruppo.
|
|
46
|
+
preferred_error: Errore durante il cambio del gruppo preferito.
|
|
47
|
+
access_denied: Non hai accesso a questa sezione.
|
|
48
|
+
group_created: Gruppo creato con successo.
|
|
49
|
+
group_updated: Gruppo aggiornato con successo.
|
|
50
|
+
group_destroyed: Gruppo cancellato con successo.
|
|
51
|
+
group_destroy_error: Il gruppo non è stato cancellato.
|
|
52
|
+
membership_created: Utente aggiunto al gruppo con successo.
|
|
53
|
+
membership_invited: Utente invitato nel gruppo. Entrerà nel gruppo dopo aver accettato l'invito.
|
|
54
|
+
membership_last_member: L'ultimo membro non può essere rimosso dal gruppo.
|
|
55
|
+
membership_destroyed: Iscrizione cancellata con successo.
|
|
56
|
+
membership_destroy_error: L'iscrizione non è stata cancellata.
|
|
57
|
+
invite_sent: Invito inviato con successo.
|
|
58
|
+
invite_error: L'invito non è stato inviato.
|
|
21
59
|
activerecord:
|
|
22
60
|
attributes:
|
|
23
61
|
lato_spaces/group:
|
|
24
62
|
name: Nome
|
|
25
63
|
actions: Azioni
|
|
26
64
|
lato_spaces/membership:
|
|
65
|
+
email: Email
|
|
27
66
|
user_infos: Utente
|
|
28
|
-
actions: Azioni
|
|
67
|
+
actions: Azioni
|
|
68
|
+
errors:
|
|
69
|
+
models:
|
|
70
|
+
lato_spaces/membership:
|
|
71
|
+
invitation_not_permitted: non appartiene a un utente registrato e gli inviti sono disabilitati
|
|
72
|
+
already_member: appartiene già a un membro di questo gruppo
|
|
73
|
+
invitation_error: Si è verificato un errore con l'invito.
|
|
74
|
+
already_joined: Questo utente è già membro di questo spazio.
|
|
75
|
+
lato_spaces/association:
|
|
76
|
+
already_associated: appartiene già a un gruppo
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class AddUniqueIndexesToLatoSpaces < ActiveRecord::Migration[7.1]
|
|
2
|
+
# Existing duplicates are removed before adding the unique indexes.
|
|
3
|
+
# Duplicates are redundant rows: the kept row is the preferred one (memberships) or the oldest.
|
|
4
|
+
def up
|
|
5
|
+
deduplicate(:lato_spaces_memberships, %w[lato_spaces_group_id lato_user_id], 'preferred DESC, id ASC')
|
|
6
|
+
deduplicate(:lato_spaces_memberships, %w[lato_spaces_group_id lato_invitation_id], 'id ASC')
|
|
7
|
+
deduplicate(:lato_spaces_associations, %w[lato_spaces_group_id item_type item_id], 'id ASC')
|
|
8
|
+
|
|
9
|
+
add_index :lato_spaces_memberships, %i[lato_spaces_group_id lato_user_id], unique: true, name: 'index_lato_spaces_memberships_on_group_and_user'
|
|
10
|
+
add_index :lato_spaces_memberships, %i[lato_spaces_group_id lato_invitation_id], unique: true, name: 'index_lato_spaces_memberships_on_group_and_invitation'
|
|
11
|
+
add_index :lato_spaces_associations, %i[lato_spaces_group_id item_type item_id], unique: true, name: 'index_lato_spaces_associations_on_group_and_item'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def down
|
|
15
|
+
remove_index :lato_spaces_memberships, name: 'index_lato_spaces_memberships_on_group_and_user'
|
|
16
|
+
remove_index :lato_spaces_memberships, name: 'index_lato_spaces_memberships_on_group_and_invitation'
|
|
17
|
+
remove_index :lato_spaces_associations, name: 'index_lato_spaces_associations_on_group_and_item'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
# Raw SQL on purpose: model callbacks (e.g. AssociableRequired item destruction) must not run.
|
|
23
|
+
def deduplicate(table, columns, keep_order)
|
|
24
|
+
not_null = columns.map { |column| "#{column} IS NOT NULL" }.join(' AND ')
|
|
25
|
+
duplicates = select_rows("SELECT #{columns.join(', ')} FROM #{table} WHERE #{not_null} GROUP BY #{columns.join(', ')} HAVING COUNT(*) > 1")
|
|
26
|
+
|
|
27
|
+
duplicates.each do |values|
|
|
28
|
+
conditions = columns.zip(values).map { |column, value| "#{column} = #{connection.quote(value)}" }.join(' AND ')
|
|
29
|
+
ids = select_values("SELECT id FROM #{table} WHERE #{conditions} ORDER BY #{keep_order}")
|
|
30
|
+
execute("DELETE FROM #{table} WHERE id IN (#{ids.drop(1).map { |id| connection.quote(id) }.join(', ')})")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/lato_spaces/config.rb
CHANGED
|
@@ -4,14 +4,14 @@ module LatoSpaces
|
|
|
4
4
|
##
|
|
5
5
|
class Config
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# Name of a host route helper (no arguments) used as redirect after set group, e.g. :dashboard_path.
|
|
8
8
|
attr_accessor :setgroup_redirect_path
|
|
9
9
|
|
|
10
|
-
# Auto-select first group
|
|
10
|
+
# Auto-select preferred group (or first group by name) when the user opens the Spaces root page without a selected group.
|
|
11
11
|
# NOTE: Requires to set `setgroup_redirect_path` to work properly.
|
|
12
12
|
attr_accessor :setgroup_auto_after_login
|
|
13
13
|
|
|
14
|
-
# Auto-select first group
|
|
14
|
+
# Auto-select preferred group (or first group by name) when the user opens the Spaces root page without a selected group.only if user has a single group.
|
|
15
15
|
# NOTE: Requires to set `setgroup_redirect_path` to work properly.
|
|
16
16
|
attr_accessor :setgroup_auto_after_login_if_single
|
|
17
17
|
|
data/lib/lato_spaces/version.rb
CHANGED