lato_spaces 3.1.13 → 3.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f791cf71fa264c395349b35419296adda1859ec3d778ac53a9bcc5c885056f6f
4
- data.tar.gz: dc0715dd620e34a856b5147271d6dc0d31b05708688f43069f24cecf4f8a84b3
3
+ metadata.gz: d80fe5ed332a254476c5acc18325b22ee09c530134c6a1abb8b0d233917d19cd
4
+ data.tar.gz: 719dc9bfde39bce04240db5e1b97d473ab1f0f7584efe92b247d68884a15fbd8
5
5
  SHA512:
6
- metadata.gz: 43e6b79b784871e895575e7840000117d23c155bb2827db927f90e7d89a4b630f15ec0b4fd7f883c22c8f46d0d1ab6ebd9dca4ff47a58d9ca58c84a038c1a15e
7
- data.tar.gz: 7de4af07b22e1a131e54685fb322b4924389afc0d4b4bea0dd001e4bec84b8419596dbe6801a1e994d16dab9e3f4547f8d755166279c5db66caf06d3e62aeca0
6
+ metadata.gz: c2adf07563efb795fa4aa868f212ecfb7dbfa4729080a3e0ac820aa3600f06a3c9e5e86212be0cceb18f34a633491ebe252f9b7078c308b556a10c90f2409ab1
7
+ data.tar.gz: 310292be92d8431b694fb263feb0a66f03d01e3a8c8d3291d3505a234fce9ba4c9050171bb764ddb0b4af87aedcbfd38473e6bf2cbb0f8cb1e48f27b19b22dc4
@@ -7,6 +7,7 @@ module LatoSpaces
7
7
  before_action { active_sidebar(:lato_spaces); active_navbar(:lato_spaces) }
8
8
 
9
9
  def index
10
+ @memberships = LatoSpaces::Membership.where(lato_user_id: @session.user_id).order(created_at: :desc)
10
11
  @groups = LatoSpaces::Group.joins(:lato_spaces_memberships).where(lato_spaces_memberships: { lato_user_id: @session.user_id }).order(name: :asc)
11
12
  end
12
13
 
@@ -24,6 +25,20 @@ module LatoSpaces
24
25
  end
25
26
  end
26
27
 
28
+ def setpreferred
29
+ membership = LatoSpaces::Membership.find_by(lato_user_id: @session.user_id, lato_spaces_group_id: params[:id])
30
+
31
+ respond_to do |format|
32
+ if membership&.set_preferred
33
+ format.html { redirect_to lato_spaces.root_path }
34
+ format.json { render json: {} }
35
+ else
36
+ format.html { redirect_to lato_spaces.root_path, alert: 'Error on changing preferred group.' }
37
+ format.json { render json: { error: 'Error on changing preferred group.' }, status: :unprocessable_entity }
38
+ end
39
+ end
40
+ end
41
+
27
42
  protected
28
43
 
29
44
  def authenticate_lato_spaces_admin
@@ -78,6 +78,15 @@ module LatoSpaces
78
78
  # Operations
79
79
  ##
80
80
 
81
+ def set_preferred
82
+ ActiveRecord::Base.transaction do
83
+ LatoSpaces::Membership.where(lato_user_id: lato_user_id).update_all(preferred: false)
84
+ update!(preferred: true)
85
+ end
86
+
87
+ true
88
+ end
89
+
81
90
  def send_invite
82
91
  if lato_invitation.blank? || lato_user.present?
83
92
  errors.add(:base, 'This user is already a member of this space.')
@@ -6,6 +6,7 @@
6
6
  <div class="row">
7
7
  <% @groups.each do |group| %>
8
8
  <% is_selected = @session.get(:spaces_group_id)&.to_i == group.id %>
9
+ <% is_preferred = @memberships.find { |m| m.lato_spaces_group_id == group.id }&.preferred %>
9
10
 
10
11
  <div class="col col-12 col-lg-6 col-lg-4 col-xl-3 mb-3">
11
12
  <div class="card h-100 border border-4 <%= is_selected ? 'border-success' : 'border-light' %>">
@@ -21,6 +22,13 @@
21
22
  <i class="bi bi-gear"></i>
22
23
  <% end %>
23
24
  <% end %>
25
+
26
+ <% if LatoSpaces.config.permit_group_preferred %>
27
+ <%= link_to lato_spaces.setpreferred_path(group), class: "btn btn-#{is_preferred ? 'warning' : 'light'} ms-1 me-1", data: { turbo_method: :post } do %>
28
+ <i class="bi bi-star<%= is_preferred ? '-fill' : '' %>"></i>
29
+ <% end %>
30
+ <% end %>
31
+
24
32
  <%= link_to lato_spaces.setgroup_path(group), class: "btn btn-#{is_selected ? 'success' : 'primary'} ms-1", data: { turbo_method: :post } do %>
25
33
  <i class="bi bi-check-circle<%= is_selected ? '-fill' : '' %>"></i>
26
34
  <% end %>
data/config/routes.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  LatoSpaces::Engine.routes.draw do
2
2
  root 'application#index'
3
3
  post 'setgroup/:id', to: 'application#setgroup', as: :setgroup
4
+ post 'setpreferred/:id', to: 'application#setpreferred', as: :setpreferred
4
5
 
5
6
  scope :groups do
6
7
  get '', to: 'groups#index', as: :groups
@@ -0,0 +1,5 @@
1
+ class AddPreferredToLatoSpacesMembership < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :lato_spaces_memberships, :preferred, :boolean, default: false
4
+ end
5
+ end
@@ -18,6 +18,9 @@ module LatoSpaces
18
18
 
19
19
  # Permit management of groups for users.
20
20
  attr_accessor :permit_group_management
21
+
22
+ # Permit users to choose a preferred group.
23
+ attr_accessor :permit_group_preferred
21
24
 
22
25
  def initialize
23
26
  @setgroup_redirect_path = nil
@@ -25,6 +28,7 @@ module LatoSpaces
25
28
  @group_params = %i[name]
26
29
  @permit_group_creation = false
27
30
  @permit_group_management = false
31
+ @permit_group_preferred = false
28
32
  end
29
33
  end
30
34
  end
@@ -1,3 +1,3 @@
1
1
  module LatoSpaces
2
- VERSION = "3.1.13"
2
+ VERSION = "3.1.14"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lato_spaces
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.13
4
+ version: 3.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregorio Galante
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-15 00:00:00.000000000 Z
11
+ date: 2023-12-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -83,6 +83,7 @@ files:
83
83
  - db/migrate/20231102082229_create_lato_spaces_groups.rb
84
84
  - db/migrate/20231102082236_create_lato_spaces_memberships.rb
85
85
  - db/migrate/20231129183145_create_lato_spaces_associations.rb
86
+ - db/migrate/20231215220127_add_preferred_to_lato_spaces_membership.rb
86
87
  - lib/lato_spaces.rb
87
88
  - lib/lato_spaces/config.rb
88
89
  - lib/lato_spaces/engine.rb