From 1cfe7dc1f8b69ac5fa0059a4afcb4e727ec5f039 Mon Sep 17 00:00:00 2001 From: stage-rl Date: Tue, 12 Sep 2023 07:00:37 +0200 Subject: [PATCH 01/21] Users admin and admin sidebar menu --- .../admin/users/user_form_component.html.erb | 40 ++++ .../admin/users/user_form_component.rb | 5 + .../users/user_rename_component.html.erb | 28 +++ .../admin/users/user_rename_component.rb | 5 + .../admin/users/users_list_component.html.erb | 41 ++++ .../admin/users/users_list_component.rb | 5 + .../users/users_list_row_component.html.erb | 21 ++ .../admin/users/users_list_row_component.rb | 5 + .../icons/groups_component.html.erb | 3 + app/components/icons/groups_component.rb | 2 + app/components/icons/rules_component.html.erb | 4 +- app/components/icons/tags_component.html.erb | 4 +- app/components/icons/users_component.html.erb | 3 + app/components/icons/users_component.rb | 4 + app/controllers/admin/tags_controller.rb | 2 +- app/controllers/admin/users_controller.rb | 58 ++--- app/controllers/tags_controller.rb | 2 +- app/lib/sidebar_menu.rb | 22 +- app/policies/admin/tag_policy.rb | 2 +- app/policies/admin/user_policy.rb | 2 +- app/views/admin/tags/index.html.erb | 2 +- app/views/admin/users/_form.html.erb | 23 -- app/views/admin/users/_user.html.erb | 8 - app/views/admin/users/edit.html.erb | 6 +- app/views/admin/users/index.html.erb | 15 +- app/views/admin/users/new.html.erb | 6 +- app/views/admin/users/show.html.erb | 220 ------------------ 27 files changed, 201 insertions(+), 337 deletions(-) create mode 100644 app/components/admin/users/user_form_component.html.erb create mode 100644 app/components/admin/users/user_form_component.rb create mode 100644 app/components/admin/users/user_rename_component.html.erb create mode 100644 app/components/admin/users/user_rename_component.rb create mode 100644 app/components/admin/users/users_list_component.html.erb create mode 100644 app/components/admin/users/users_list_component.rb create mode 100644 app/components/admin/users/users_list_row_component.html.erb create mode 100644 app/components/admin/users/users_list_row_component.rb create mode 100644 app/components/icons/groups_component.html.erb create mode 100644 app/components/icons/groups_component.rb create mode 100644 app/components/icons/users_component.html.erb create mode 100644 app/components/icons/users_component.rb delete mode 100644 app/views/admin/users/_form.html.erb delete mode 100644 app/views/admin/users/_user.html.erb delete mode 100644 app/views/admin/users/show.html.erb diff --git a/app/components/admin/users/user_form_component.html.erb b/app/components/admin/users/user_form_component.html.erb new file mode 100644 index 000000000..12b8fcdd0 --- /dev/null +++ b/app/components/admin/users/user_form_component.html.erb @@ -0,0 +1,40 @@ +<%= tag.turbo_frame id: 'modal' do %> + +<% end %> diff --git a/app/components/admin/users/user_form_component.rb b/app/components/admin/users/user_form_component.rb new file mode 100644 index 000000000..24e76c410 --- /dev/null +++ b/app/components/admin/users/user_form_component.rb @@ -0,0 +1,5 @@ +class Admin::Users::UserFormComponent < ViewComponent::Base + def initialize(user) + @user = user + end +end diff --git a/app/components/admin/users/user_rename_component.html.erb b/app/components/admin/users/user_rename_component.html.erb new file mode 100644 index 000000000..ded43bb8f --- /dev/null +++ b/app/components/admin/users/user_rename_component.html.erb @@ -0,0 +1,28 @@ +
+ + +
diff --git a/app/components/admin/users/user_rename_component.rb b/app/components/admin/users/user_rename_component.rb new file mode 100644 index 000000000..bf315a750 --- /dev/null +++ b/app/components/admin/users/user_rename_component.rb @@ -0,0 +1,5 @@ +class Admin::Users::UserRenameComponent < ViewComponent::Base + def initialize(user) + @user = user + end +end diff --git a/app/components/admin/users/users_list_component.html.erb b/app/components/admin/users/users_list_component.html.erb new file mode 100644 index 000000000..d89c3d5f3 --- /dev/null +++ b/app/components/admin/users/users_list_component.html.erb @@ -0,0 +1,41 @@ +
+
+
+
Používatelia
+ <%= link_to new_admin_tenant_user_path, class:"px-3.5 py-2.5 bg-blue-600 rounded-md justify-center items-center gap-2.5 flex" do %> +

Vytvoriť používateľa

+ <% end %> +
+
+ <% @users.each do |user| %> + <%= render Admin::Users::UsersListRowComponent.new(user) %> + <% end %> +
+
+
+
+
+ <%= render Icons::InfoComponent.new %> +
+
+
Pridať používateľov
+
Existujúci používatelia môžu byť rozdelení do skupín, napríklad podľa zodpovednosti
+
+
+
Nastaviť používateľov
+
+
+
+
+ <%= render Icons::InfoComponent.new %> +
+
+
Určiť prístup skupín k správam
+
Jednotlivé skupiny používateľov (ako aj samotný používatelia) môžu mať rozdielny prístup k správam
+
+
+
Nastaviť prístup
+
+
+
+
diff --git a/app/components/admin/users/users_list_component.rb b/app/components/admin/users/users_list_component.rb new file mode 100644 index 000000000..2c64582fc --- /dev/null +++ b/app/components/admin/users/users_list_component.rb @@ -0,0 +1,5 @@ +class Admin::Users::UsersListComponent < ViewComponent::Base + def initialize(users) + @users = users + end +end diff --git a/app/components/admin/users/users_list_row_component.html.erb b/app/components/admin/users/users_list_row_component.html.erb new file mode 100644 index 000000000..42953530b --- /dev/null +++ b/app/components/admin/users/users_list_row_component.html.erb @@ -0,0 +1,21 @@ +
+
+ <%= @user.name[0] %> +
+
+
+ <%= render Admin::Users::UserRenameComponent.new(@user) %> +
+
+ <%= @user.email %> +
+
+
+ <%= link_to edit_admin_tenant_user_path(@user.tenant, @user), data: { turbo_frame: :modal } do %> + <%= render Common::EditButtonComponent.new %> + <% end %> + <%= button_to admin_tenant_user_path(@user.tenant, @user), method: :delete, data: { turbo_frame: :modal } do %> + <%= render Common::DeleteButtonComponent.new %> + <% end %> +
+
diff --git a/app/components/admin/users/users_list_row_component.rb b/app/components/admin/users/users_list_row_component.rb new file mode 100644 index 000000000..d3de3797f --- /dev/null +++ b/app/components/admin/users/users_list_row_component.rb @@ -0,0 +1,5 @@ +class Admin::Users::UsersListRowComponent < ViewComponent::Base + def initialize(user) + @user = user + end +end diff --git a/app/components/icons/groups_component.html.erb b/app/components/icons/groups_component.html.erb new file mode 100644 index 000000000..1b0ea3d9d --- /dev/null +++ b/app/components/icons/groups_component.html.erb @@ -0,0 +1,3 @@ + + + diff --git a/app/components/icons/groups_component.rb b/app/components/icons/groups_component.rb new file mode 100644 index 000000000..ffa816ea0 --- /dev/null +++ b/app/components/icons/groups_component.rb @@ -0,0 +1,2 @@ +class Icons::GroupsComponent < ViewComponent::Base +end diff --git a/app/components/icons/rules_component.html.erb b/app/components/icons/rules_component.html.erb index 7baee57a4..976dab4ff 100644 --- a/app/components/icons/rules_component.html.erb +++ b/app/components/icons/rules_component.html.erb @@ -1 +1,3 @@ -
Add Icons::Rules template here
+ + + diff --git a/app/components/icons/tags_component.html.erb b/app/components/icons/tags_component.html.erb index 32e6edb6f..ba4c1b833 100644 --- a/app/components/icons/tags_component.html.erb +++ b/app/components/icons/tags_component.html.erb @@ -1 +1,3 @@ -
Add Icons::Tags template here
+ + + diff --git a/app/components/icons/users_component.html.erb b/app/components/icons/users_component.html.erb new file mode 100644 index 000000000..c4ff2650a --- /dev/null +++ b/app/components/icons/users_component.html.erb @@ -0,0 +1,3 @@ + + + diff --git a/app/components/icons/users_component.rb b/app/components/icons/users_component.rb new file mode 100644 index 000000000..0b2eeb15d --- /dev/null +++ b/app/components/icons/users_component.rb @@ -0,0 +1,4 @@ +# frozen_string_literal: true + +class Icons::UsersComponent < ViewComponent::Base +end diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index e4ca85854..b2b9562cb 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -2,7 +2,7 @@ class Admin::TagsController < ApplicationController before_action :set_tag, only: %i[show edit update destroy] def index - authorize Tag + authorize [:admin, Tag] @tags = policy_scope([:admin, Tag]) end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 058d0ab57..890ab0511 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -1,16 +1,9 @@ class Admin::UsersController < ApplicationController - before_action :set_user, only: %i[show edit update destroy] + before_action :set_user, only: %i[edit update destroy] def index authorize([:admin, User]) - @users = policy_scope([:admin, User]) - end - - def show - @user = policy_scope([:admin, User]).find(params[:id]) - authorize([:admin, @user]) - @other_groups = other_groups - @other_tags = other_tags + @users = policy_scope([:admin, User]).where(tenant_id: Current.tenant.id) end def new @@ -26,38 +19,29 @@ def create @user = Current.tenant.users.new(user_params) authorize([:admin, @user]) - respond_to do |format| - if @user.save - format.html { redirect_to admin_tenant_url(Current.tenant), notice: 'User was successfully created.' } - format.json { render :show, status: :created, location: @user } - else - format.html { render :new, status: :unprocessable_entity } - format.json { render json: @user.errors, status: :unprocessable_entity } - end + if @user.save + flash[:notice] = 'User was successfully created' + render turbo_stream: turbo_stream.action(:redirect, admin_tenant_users_path(Current.tenant)) + else + render :new, status: :unprocessable_entity end end def update authorize([:admin, @user]) - respond_to do |format| - if @user.update(user_params) - format.html { redirect_to admin_tenant_url(Current.tenant), notice: 'User was successfully updated.' } - format.json { render :show, status: :ok, location: @user } - else - format.html { render :edit, status: :unprocessable_entity } - format.json { render json: @user.errors, status: :unprocessable_entity } - end + if @user.update(user_params) + flash[:notice] = 'User was successfully updated' + render turbo_stream: turbo_stream.action(:redirect, admin_tenant_users_path(Current.tenant)) + else + render :edit, status: :unprocessable_entity end end def destroy authorize([:admin, @user]) @user.destroy - - respond_to do |format| - format.html { redirect_to admin_tenant_url(Current.tenant), notice: 'User was successfully destroyed.' } - format.json { head :no_content } - end + flash[:notice] = 'User was successfully destroyed' + render turbo_stream: turbo_stream.action(:redirect, admin_tenant_users_path(Current.tenant)) end private @@ -69,18 +53,4 @@ def set_user def user_params params.require(:user).permit(:name, :email, :user_type) end - - def other_groups - @other_groups = - Group - .where(tenant_id: params[:tenant_id]) - .where.not(group_type: 'USER') - .where.not(id: Group.includes(:users).where(users: { id: @user.id })) - end - def other_tags - @other_tags = - Tag - .where(tenant_id: params[:tenant_id]) - .where.not(id: Tag.includes(:users).where(users: { id: @user.id })) - end end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index d353ce046..3a312b630 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -3,7 +3,7 @@ class TagsController < ApplicationController before_action :set_visible_tags def show - authorize @tag + authorize [:admin, @tag] end private diff --git a/app/lib/sidebar_menu.rb b/app/lib/sidebar_menu.rb index 72b1180de..7b85c93ed 100644 --- a/app/lib/sidebar_menu.rb +++ b/app/lib/sidebar_menu.rb @@ -13,8 +13,8 @@ def get_menu private def initial_structure(controller, action) - return default_message_thread_menu if %w[messages message_drafts].include?(controller) - return admin_main_menu if Current.user.admin? || Current.user.site_admin? + return default_message_thread_menu if controller.in? %w[messages message_drafts] + return admin_main_menu if (controller.in? %w[groups users tags automation_rules boxes]) && (Current.user.admin? || Current.user.site_admin?) default_main_menu end @@ -23,21 +23,21 @@ def default_main_menu [ TW::SidebarMenuItemComponent.new(name: 'Prehľad', url: root_path, icon: Icons::DashboardComponent.new), TW::SidebarMenuItemComponent.new(name: 'Správy', url: message_threads_path, icon: Icons::SchrankaComponent.new), - Layout::TagListComponent.new(tags: @parameters[:tags]) + Layout::TagListComponent.new(tags: @parameters[:tags]), + TW::SidebarMenuItemComponent.new(name: 'Nastavenia', url: admin_tenant_users_path(Current.tenant), icon: Icons::SettingsComponent.new) ] end def admin_main_menu [ - TW::SidebarMenuItemComponent.new(name: 'Prehľad', url: root_path, icon: Icons::DashboardComponent.new), - TW::SidebarMenuItemComponent.new(name: 'Správy', url: message_threads_path, icon: Icons::SchrankaComponent.new), - Layout::TagListComponent.new(tags: @parameters[:tags]), - TW::SidebarMenuDividerComponent.new(name: 'Nastavenia'), - TW::SidebarMenuItemComponent.new(name: 'Nastavenie pravidiel', url: settings_automation_rules_path, icon: Icons::SettingsComponent.new), - TW::SidebarMenuDividerComponent.new(name: 'Administrácia'), + Layout::BackToBoxComponent.new(), + TW::SidebarMenuDividerComponent.new(name: 'Produkt'), + TW::SidebarMenuItemComponent.new(name: 'Používatelia', url: admin_tenant_users_path(Current.tenant), icon: Icons::UsersComponent.new), + TW::SidebarMenuItemComponent.new(name: 'Pravidlá', url: settings_automation_rules_path, icon: Icons::RulesComponent.new), TW::SidebarMenuItemComponent.new(name: 'Schránky', url: boxes_path, icon: Icons::BoxesComponent.new), - TW::SidebarMenuItemComponent.new(name: 'Administrácia', url: admin_tenants_path, icon: Icons::AdminComponent.new), - TW::SidebarMenuItemComponent.new(name: 'Good Job Dashboard', url: good_job_path, icon: Icons::GoodJobComponent.new) + TW::SidebarMenuItemComponent.new(name: 'Skupiny', url: admin_tenant_groups_path(Current.tenant), icon: Icons::GroupsComponent.new), + TW::SidebarMenuItemComponent.new(name: 'Štítky', url: admin_tenant_tags_path(Current.tenant), icon: Icons::TagsComponent.new), + TW::SidebarMenuItemComponent.new(name: 'Good Job Dashboard', url: good_job_path, icon: Icons::GoodJobComponent.new), ] end diff --git a/app/policies/admin/tag_policy.rb b/app/policies/admin/tag_policy.rb index 40ff018c0..fa70bced6 100644 --- a/app/policies/admin/tag_policy.rb +++ b/app/policies/admin/tag_policy.rb @@ -14,7 +14,7 @@ def resolve end end - def index + def index? @user.site_admin? || @user.admin? end diff --git a/app/policies/admin/user_policy.rb b/app/policies/admin/user_policy.rb index a3ad63887..645c9467a 100644 --- a/app/policies/admin/user_policy.rb +++ b/app/policies/admin/user_policy.rb @@ -17,7 +17,7 @@ def resolve end end - def index + def index? @user.site_admin? || @user.admin? end diff --git a/app/views/admin/tags/index.html.erb b/app/views/admin/tags/index.html.erb index 1933ed2d5..3c61c751f 100644 --- a/app/views/admin/tags/index.html.erb +++ b/app/views/admin/tags/index.html.erb @@ -4,7 +4,7 @@ <% end %>

Tags

- <%= link_to 'New tag', new_admin_tag_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> + <%= link_to 'New tag', new_admin_tenant_tag_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
diff --git a/app/views/admin/users/_form.html.erb b/app/views/admin/users/_form.html.erb deleted file mode 100644 index c5d4004c1..000000000 --- a/app/views/admin/users/_form.html.erb +++ /dev/null @@ -1,23 +0,0 @@ -<%= form_with(model: [:admin, Current.tenant, user], class: "contents") do |form| %> - <% if user.errors.any? %> -
-

<%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:

-
    - <% user.errors.each do |error| %> -
  • <%= error.full_message %>
  • - <% end %> -
-
- <% end %> -
- <%= form.label :name %> - <%= form.text_field :name, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> -
-
- <%= form.label :email %> - <%= form.text_field :email, class: "block shadow rounded-md border border-gray-200 outline-none px-3 py-2 mt-2 w-full" %> -
-
- <%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> -
-<% end %> diff --git a/app/views/admin/users/_user.html.erb b/app/views/admin/users/_user.html.erb deleted file mode 100644 index d765135a7..000000000 --- a/app/views/admin/users/_user.html.erb +++ /dev/null @@ -1,8 +0,0 @@ - - <%= link_to user.name, admin_tenant_user_url(Current.tenant, @user) %> - - <%= user.email%> - - <%= link_to 'Edit this user', edit_admin_tenant_user_url(Current.tenant, @user), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> - - diff --git a/app/views/admin/users/edit.html.erb b/app/views/admin/users/edit.html.erb index 1ac5982af..3de486c10 100644 --- a/app/views/admin/users/edit.html.erb +++ b/app/views/admin/users/edit.html.erb @@ -1,5 +1 @@ -
-

Editing user

- <%= render "form", user: @user %> - <%= link_to "Back to users", :back, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
+<%= render Admin::Users::UserFormComponent.new(@user) %> diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erb index dfc2a671c..b454a0349 100644 --- a/app/views/admin/users/index.html.erb +++ b/app/views/admin/users/index.html.erb @@ -1,14 +1 @@ -
- <% if notice.present? %> -

<%= notice %>

- <% end %> - -
-

Users

- <%= link_to 'New user', new_user_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> -
- -
- <%= render @users %> -
-
+<%= render Admin::Users::UsersListComponent.new(@users) %> diff --git a/app/views/admin/users/new.html.erb b/app/views/admin/users/new.html.erb index cb63ee156..3de486c10 100644 --- a/app/views/admin/users/new.html.erb +++ b/app/views/admin/users/new.html.erb @@ -1,5 +1 @@ -
-

New user

- <%= render "form", user: @user %> - <%= link_to 'Back to users', :back , class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
+<%= render Admin::Users::UserFormComponent.new(@user) %> diff --git a/app/views/admin/users/show.html.erb b/app/views/admin/users/show.html.erb deleted file mode 100644 index 6ba0e5fbd..000000000 --- a/app/views/admin/users/show.html.erb +++ /dev/null @@ -1,220 +0,0 @@ -
-
-
-

User

-
-
-
- <% if notice.present? %> -

<%= notice %>

- <% end %> - <%= render @user %> - <%= link_to 'Edit this user', edit_admin_tenant_user_url(Current.tenant, @user), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
- <%= button_to 'Destroy this user', admin_tenant_user_path(@user), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %> -
- <%= link_to 'Back to tenant', admin_tenant_path(Current.tenant), class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
-
- -
-

Groups Membership

-
-
-
-
-
-
- - - - - - - - - - <%= render Admin::GroupMembershipTableRowComponent.with_collection(@user.group_memberships) %> - -
- - Name - - - - - - Type - - - - - Edit -
-
-
-
-
-
- -
-

Other Groups

-
-
-
-
-
-
- - - - - - - - - - <%= render Admin::GroupTableRowComponent.with_collection(@other_groups, user: @user, group_action: 'add') %> - -
- - Name - - - - - - Type - - - - - Edit -
-
-
-
-
-
- -
-

Tags Assigned

-
-
-
-
-
-
- - - - - - - - - - <%= render Admin::TagUserTableRowComponent.with_collection(@user.tag_users) %> - -
- - Name - - - - - - Type - - - - - Edit -
-
-
-
-
-
- -
-

Other Tags

-
-
-
-
-
-
- - - - - - - - - - <%= render Admin::TagTableRowComponent.with_collection(@other_tags, user: @user, tag_action: 'add') %> - -
- - Name - - - - - - Type - - - - - Edit -
-
-
-
-
-
-
-
From f0acf3bb951c954498b73a14d4ae650e235f8b02 Mon Sep 17 00:00:00 2001 From: stage-rl Date: Mon, 18 Sep 2023 18:15:36 +0200 Subject: [PATCH 02/21] admin UX - based on target UX --- .gitignore | 1 + .../admin/boxes/box_form_component.html.erb | 45 +++++++++++++++ .../admin/boxes/box_form_component.rb | 6 ++ .../admin/boxes/box_rename_component.html.erb | 28 +++++++++ .../admin/boxes/box_rename_component.rb | 5 ++ .../admin/boxes/boxes_list_component.html.erb | 15 +++++ .../admin/boxes/boxes_list_component.rb | 5 ++ .../boxes/boxes_list_row_component.html.erb | 23 ++++++++ .../admin/boxes/boxes_list_row_component.rb | 5 ++ .../groups/group_form_component.html.erb | 4 +- .../admin/groups/group_form_component.rb | 4 +- .../groups/groups_list_component.html.erb | 12 ++-- .../groups/groups_list_row_component.html.erb | 2 +- .../hidden_group_form_component.html.erb | 8 --- .../groups/hidden_group_form_component.rb | 5 -- .../admin/groups/user_add_component.html.erb | 9 +-- .../permissions/group_form_component.html.erb | 44 ++++++++++++++ .../admin/permissions/group_form_component.rb | 5 ++ .../group_rename_component.html.erb | 28 +++++++++ .../permissions/group_rename_component.rb | 5 ++ .../groups_list_component.html.erb | 50 ++++++++++++++++ .../permissions/groups_list_component.rb | 5 ++ .../groups_list_row_component.html.erb | 31 ++++++++++ .../permissions/groups_list_row_component.rb | 5 ++ ...bers_list_row_view_only_component.html.erb | 7 +++ .../members_list_row_view_only_component.rb | 6 ++ .../new_group_form_component.html.erb | 35 ++++++++++++ .../permissions/new_group_form_component.rb | 5 ++ .../permission_add_component.html.erb | 8 +++ .../permissions/permission_add_component.rb | 7 +++ .../permissions_add_popup_component.html.erb | 23 ++++++++ .../permissions_add_popup_component.rb | 6 ++ .../permissions_list_row_component.html.erb | 4 ++ .../permissions_list_row_component.rb | 6 ++ .../admin/permissions/tag_component.html.erb | 7 +++ .../admin/permissions/tag_component.rb | 5 ++ .../tag_group_table_row_component.html.erb | 12 ++++ .../admin/tag_group_table_row_component.rb | 10 ++++ .../admin/tag_table_row_component.html.erb | 8 +-- .../admin/tag_table_row_component.rb | 4 +- .../tag_user_table_row_component.html.erb | 2 +- .../tags/external_tags_component.html.erb | 19 +++++++ .../admin/tags/external_tags_component.rb | 5 ++ .../admin/tags/tag_form_component.html.erb | 35 ++++++++++++ .../admin/tags/tag_form_component.rb | 6 ++ .../admin/tags/tag_rename_component.html.erb | 28 +++++++++ .../admin/tags/tag_rename_component.rb | 5 ++ .../admin/tags/tags_list_component.html.erb | 42 ++++++++++++++ .../admin/tags/tags_list_component.rb | 6 ++ .../tags/tags_list_row_component.html.erb | 15 +++++ .../admin/tags/tags_list_row_component.rb | 5 ++ .../tags/visibility_toggle_component.html.erb | 9 +++ .../admin/tags/visibility_toggle_component.rb | 8 +++ .../tenants/tenant_form_component.html.erb | 35 ++++++++++++ .../admin/tenants/tenant_form_component.rb | 6 ++ .../tenants/tenant_rename_component.html.erb | 28 +++++++++ .../admin/tenants/tenant_rename_component.rb | 5 ++ .../tenants/tenants_list_component.html.erb | 15 +++++ .../admin/tenants/tenants_list_component.rb | 5 ++ .../tenants_list_row_component.html.erb | 18 ++++++ .../tenants/tenants_list_row_component.rb | 5 ++ .../admin/users/user_form_component.html.erb | 14 ++--- .../admin/users/user_form_component.rb | 3 +- .../admin/users/users_list_component.html.erb | 10 ++-- .../users/users_list_row_component.html.erb | 4 +- .../common/tag_selector_popup_component.rb | 2 +- .../icons/closed_lock_component.html.erb | 3 + app/components/icons/closed_lock_component.rb | 2 + .../message_thread_sidebar_component.html.erb | 5 -- .../layout/sidebar_divider_component.html.erb | 5 ++ .../layout/sidebar_divider_component.rb | 2 + app/components/message_component.html.erb | 19 ++++--- .../rules/actions_form_component.html.erb | 2 +- .../automation_rules_list_component.html.erb | 14 +++++ ...omation_rules_table_row_component.html.erb | 2 +- app/controllers/admin/boxes_controller.rb | 3 +- app/controllers/admin/groups_controller.rb | 29 ++++++++-- .../admin/tag_groups_controller.rb | 16 ++++-- app/controllers/admin/tags_controller.rb | 18 ++++-- app/controllers/admin/tenants_controller.rb | 33 ++++------- app/controllers/admin/users_controller.rb | 9 +-- .../settings/automation_rules_controller.rb | 7 +-- app/jobs/drafts/parse_import_job.rb | 2 + app/lib/sidebar_menu.rb | 13 +++-- app/models/box.rb | 27 ++++++++- app/models/govbox/message.rb | 1 + app/policies/admin/group_policy.rb | 8 +++ app/policies/admin/tag_group_policy.rb | 2 +- app/policies/admin/tag_policy.rb | 4 ++ app/views/admin/boxes/edit.html.erb | 7 +-- app/views/admin/boxes/index.html.erb | 14 +---- app/views/admin/boxes/new.html.erb | 6 +- .../admin/group_memberships/create.html.erb | 1 + .../group_memberships/create.turbo_stream.erb | 4 -- .../admin/groups/edit_permissions.html.erb | 1 + .../groups/search_non_tags.turbo_stream.erb | 5 ++ app/views/admin/tag_groups/index.html.erb | 1 + app/views/admin/tags/edit.html.erb | 7 +-- app/views/admin/tags/index.html.erb | 14 +---- app/views/admin/tags/new.html.erb | 6 +- .../admin/tags/visibility_toggle.html.erb | 1 + app/views/admin/tenants/edit.html.erb | 7 +-- app/views/admin/tenants/index.html.erb | 13 +---- app/views/admin/tenants/new.html.erb | 6 +- app/views/admin/users/edit.html.erb | 2 +- app/views/admin/users/new.html.erb | 2 +- app/views/layouts/application.html.erb | 1 + app/views/sessions/login.html.erb | 12 +++- config/routes.rb | 14 ++--- .../20230912140348_add_short_name_to_boxes.rb | 6 ++ .../20230912140629_add_color_to_boxes.rb | 12 ++++ .../20230914151243_add_external_to_tags.rb | 9 +++ db/schema.rb | 57 ++----------------- 113 files changed, 1012 insertions(+), 260 deletions(-) create mode 100644 app/components/admin/boxes/box_form_component.html.erb create mode 100644 app/components/admin/boxes/box_form_component.rb create mode 100644 app/components/admin/boxes/box_rename_component.html.erb create mode 100644 app/components/admin/boxes/box_rename_component.rb create mode 100644 app/components/admin/boxes/boxes_list_component.html.erb create mode 100644 app/components/admin/boxes/boxes_list_component.rb create mode 100644 app/components/admin/boxes/boxes_list_row_component.html.erb create mode 100644 app/components/admin/boxes/boxes_list_row_component.rb delete mode 100644 app/components/admin/groups/hidden_group_form_component.html.erb delete mode 100644 app/components/admin/groups/hidden_group_form_component.rb create mode 100644 app/components/admin/permissions/group_form_component.html.erb create mode 100644 app/components/admin/permissions/group_form_component.rb create mode 100644 app/components/admin/permissions/group_rename_component.html.erb create mode 100644 app/components/admin/permissions/group_rename_component.rb create mode 100644 app/components/admin/permissions/groups_list_component.html.erb create mode 100644 app/components/admin/permissions/groups_list_component.rb create mode 100644 app/components/admin/permissions/groups_list_row_component.html.erb create mode 100644 app/components/admin/permissions/groups_list_row_component.rb create mode 100644 app/components/admin/permissions/members_list_row_view_only_component.html.erb create mode 100644 app/components/admin/permissions/members_list_row_view_only_component.rb create mode 100644 app/components/admin/permissions/new_group_form_component.html.erb create mode 100644 app/components/admin/permissions/new_group_form_component.rb create mode 100644 app/components/admin/permissions/permission_add_component.html.erb create mode 100644 app/components/admin/permissions/permission_add_component.rb create mode 100644 app/components/admin/permissions/permissions_add_popup_component.html.erb create mode 100644 app/components/admin/permissions/permissions_add_popup_component.rb create mode 100644 app/components/admin/permissions/permissions_list_row_component.html.erb create mode 100644 app/components/admin/permissions/permissions_list_row_component.rb create mode 100644 app/components/admin/permissions/tag_component.html.erb create mode 100644 app/components/admin/permissions/tag_component.rb create mode 100644 app/components/admin/tag_group_table_row_component.html.erb create mode 100644 app/components/admin/tag_group_table_row_component.rb create mode 100644 app/components/admin/tags/external_tags_component.html.erb create mode 100644 app/components/admin/tags/external_tags_component.rb create mode 100644 app/components/admin/tags/tag_form_component.html.erb create mode 100644 app/components/admin/tags/tag_form_component.rb create mode 100644 app/components/admin/tags/tag_rename_component.html.erb create mode 100644 app/components/admin/tags/tag_rename_component.rb create mode 100644 app/components/admin/tags/tags_list_component.html.erb create mode 100644 app/components/admin/tags/tags_list_component.rb create mode 100644 app/components/admin/tags/tags_list_row_component.html.erb create mode 100644 app/components/admin/tags/tags_list_row_component.rb create mode 100644 app/components/admin/tags/visibility_toggle_component.html.erb create mode 100644 app/components/admin/tags/visibility_toggle_component.rb create mode 100644 app/components/admin/tenants/tenant_form_component.html.erb create mode 100644 app/components/admin/tenants/tenant_form_component.rb create mode 100644 app/components/admin/tenants/tenant_rename_component.html.erb create mode 100644 app/components/admin/tenants/tenant_rename_component.rb create mode 100644 app/components/admin/tenants/tenants_list_component.html.erb create mode 100644 app/components/admin/tenants/tenants_list_component.rb create mode 100644 app/components/admin/tenants/tenants_list_row_component.html.erb create mode 100644 app/components/admin/tenants/tenants_list_row_component.rb create mode 100644 app/components/icons/closed_lock_component.html.erb create mode 100644 app/components/icons/closed_lock_component.rb create mode 100644 app/components/layout/sidebar_divider_component.html.erb create mode 100644 app/components/layout/sidebar_divider_component.rb create mode 100644 app/views/admin/group_memberships/create.html.erb delete mode 100644 app/views/admin/group_memberships/create.turbo_stream.erb create mode 100644 app/views/admin/groups/edit_permissions.html.erb create mode 100644 app/views/admin/groups/search_non_tags.turbo_stream.erb create mode 100644 app/views/admin/tag_groups/index.html.erb create mode 100644 app/views/admin/tags/visibility_toggle.html.erb create mode 100644 db/migrate/20230912140348_add_short_name_to_boxes.rb create mode 100644 db/migrate/20230912140629_add_color_to_boxes.rb create mode 100644 db/migrate/20230914151243_add_external_to_tags.rb diff --git a/.gitignore b/.gitignore index aceb6077f..94b93dbe7 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ .idea .vscode +.streerc .rdbg* # Ignore all logfiles and tempfiles. diff --git a/app/components/admin/boxes/box_form_component.html.erb b/app/components/admin/boxes/box_form_component.html.erb new file mode 100644 index 000000000..53eb699f6 --- /dev/null +++ b/app/components/admin/boxes/box_form_component.html.erb @@ -0,0 +1,45 @@ +<%= tag.turbo_frame id: 'modal' do %> + +<% end %> diff --git a/app/components/admin/boxes/box_form_component.rb b/app/components/admin/boxes/box_form_component.rb new file mode 100644 index 000000000..d8a2c724c --- /dev/null +++ b/app/components/admin/boxes/box_form_component.rb @@ -0,0 +1,6 @@ +class Admin::Boxes::BoxFormComponent < ViewComponent::Base + def initialize(box:, action:) + @box = box + @action = action + end +end diff --git a/app/components/admin/boxes/box_rename_component.html.erb b/app/components/admin/boxes/box_rename_component.html.erb new file mode 100644 index 000000000..de0de8125 --- /dev/null +++ b/app/components/admin/boxes/box_rename_component.html.erb @@ -0,0 +1,28 @@ +
+ + +
diff --git a/app/components/admin/boxes/box_rename_component.rb b/app/components/admin/boxes/box_rename_component.rb new file mode 100644 index 000000000..2e51070d0 --- /dev/null +++ b/app/components/admin/boxes/box_rename_component.rb @@ -0,0 +1,5 @@ +class Admin::Boxes::BoxRenameComponent < ViewComponent::Base + def initialize(box) + @box = box + end +end diff --git a/app/components/admin/boxes/boxes_list_component.html.erb b/app/components/admin/boxes/boxes_list_component.html.erb new file mode 100644 index 000000000..f423ac2f8 --- /dev/null +++ b/app/components/admin/boxes/boxes_list_component.html.erb @@ -0,0 +1,15 @@ +
+
+
+
Pripojené schránky
+ <%= link_to new_admin_tenant_box_path, class:"px-3.5 py-2.5 bg-blue-600 rounded-md justify-center items-center gap-2.5 flex" do %> +

Pripojiť schránku

+ <% end %> +
+
+ <% @boxes.each do |box| %> + <%= render Admin::Boxes::BoxesListRowComponent.new(box) %> + <% end %> +
+
+
diff --git a/app/components/admin/boxes/boxes_list_component.rb b/app/components/admin/boxes/boxes_list_component.rb new file mode 100644 index 000000000..b481b555b --- /dev/null +++ b/app/components/admin/boxes/boxes_list_component.rb @@ -0,0 +1,5 @@ +class Admin::Boxes::BoxesListComponent < ViewComponent::Base + def initialize(boxes) + @boxes = boxes + end +end diff --git a/app/components/admin/boxes/boxes_list_row_component.html.erb b/app/components/admin/boxes/boxes_list_row_component.html.erb new file mode 100644 index 000000000..385005ce3 --- /dev/null +++ b/app/components/admin/boxes/boxes_list_row_component.html.erb @@ -0,0 +1,23 @@ +
+
+
+

<%= @box.short_name || @box.name[0] %>

+
+
+
+
+ <%= render Admin::Boxes::BoxRenameComponent.new(@box) %> +
+
+ <%= @box.uri %> +
+
+
+ <%= link_to edit_admin_tenant_box_path(@box.tenant, @box), data: { turbo_frame: :modal } do %> + <%= render Common::EditButtonComponent.new %> + <% end %> + <%= button_to admin_tenant_box_path(@box.tenant, @box), method: :delete do %> + <%= render Common::DeleteButtonComponent.new %> + <% end %> +
+
diff --git a/app/components/admin/boxes/boxes_list_row_component.rb b/app/components/admin/boxes/boxes_list_row_component.rb new file mode 100644 index 000000000..c00a2bbe4 --- /dev/null +++ b/app/components/admin/boxes/boxes_list_row_component.rb @@ -0,0 +1,5 @@ +class Admin::Boxes::BoxesListRowComponent < ViewComponent::Base + def initialize(box) + @box = box + end +end diff --git a/app/components/admin/groups/group_form_component.html.erb b/app/components/admin/groups/group_form_component.html.erb index fe8489239..ba5a5f261 100644 --- a/app/components/admin/groups/group_form_component.html.erb +++ b/app/components/admin/groups/group_form_component.html.erb @@ -13,7 +13,7 @@ <% end %>
- <% if @step.in? [:new, :edit] %> + <% if @action.in? [:new, :edit] %> <%= form_with url: search_non_members_admin_tenant_group_path(Current.tenant, @group), class:"flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200" do |form| %>
@@ -30,7 +30,7 @@
<% @group.group_memberships.each do |group_membership| %>
- <% if @step.in? [:new, :edit] %> + <% if @action.in? [:new, :edit] %> <%= render Admin::Groups::MembersListRowComponent.new(group_membership) %> <% else %> <%= render Admin::Groups::MembersListRowViewOnlyComponent.new(group_membership) %> diff --git a/app/components/admin/groups/group_form_component.rb b/app/components/admin/groups/group_form_component.rb index c60482959..221adc19f 100644 --- a/app/components/admin/groups/group_form_component.rb +++ b/app/components/admin/groups/group_form_component.rb @@ -1,6 +1,6 @@ class Admin::Groups::GroupFormComponent < ViewComponent::Base - def initialize(group:, step:) + def initialize(group:, action:) @group = group - @step = step + @action = action end end diff --git a/app/components/admin/groups/groups_list_component.html.erb b/app/components/admin/groups/groups_list_component.html.erb index fca46084b..01a3d7f01 100644 --- a/app/components/admin/groups/groups_list_component.html.erb +++ b/app/components/admin/groups/groups_list_component.html.erb @@ -34,9 +34,9 @@
Pridať používateľov
Existujúci používatelia môžu byť rozdelení do skupín, napríklad podľa zodpovednosti
-
-
Nastaviť používateľov
-
+ <%= link_to admin_tenant_users_path, class:"px-3.5 py-2.5 bg-white rounded-md border border-gray-300 justify-center items-center gap-2.5 flex" do %> +

Nastaviť používateľov

+ <% end %>
@@ -46,9 +46,9 @@
Určiť prístup skupín k správam
Jednotlivé skupiny používateľov (ako aj samotný používatelia) môžu mať rozdielny prístup k správam
-
-
Nastaviť prístup
-
+ <%= link_to admin_tenant_tag_groups_path, class:"px-3.5 py-2.5 bg-white rounded-md border border-gray-300 justify-center items-center gap-2.5 flex" do %> +

Nastaviť prístup

+ <% end %>
diff --git a/app/components/admin/groups/groups_list_row_component.html.erb b/app/components/admin/groups/groups_list_row_component.html.erb index 2b9bdfea8..825705209 100644 --- a/app/components/admin/groups/groups_list_row_component.html.erb +++ b/app/components/admin/groups/groups_list_row_component.html.erb @@ -21,7 +21,7 @@ <%= link_to edit_members_admin_tenant_group_path(@group.tenant, @group), data: { turbo_frame: :modal } do %> <%= render Common::EditButtonComponent.new %> <% end %> - <%= button_to admin_tenant_group_path(@group.tenant, @group), method: :delete, data: { turbo_frame: :modal } do %> + <%= button_to admin_tenant_group_path(@group.tenant, @group), method: :delete do %> <%= render Common::DeleteButtonComponent.new %> <% end %> <% else %> diff --git a/app/components/admin/groups/hidden_group_form_component.html.erb b/app/components/admin/groups/hidden_group_form_component.html.erb deleted file mode 100644 index 95371a224..000000000 --- a/app/components/admin/groups/hidden_group_form_component.html.erb +++ /dev/null @@ -1,8 +0,0 @@ -<%= @form.hidden_field :id %> -<%= @form.hidden_field :tenant_id %> -<%= @form.fields_for :group_memberships do |membership_form| %> - <%= membership_form.hidden_field :group_id %> - <%= membership_form.hidden_field :user_id %> - <%= membership_form.hidden_field :id if membership_form.object.id %> - <%= membership_form.hidden_field :delete_record if membership_form.object.delete_record %> -<% end %> diff --git a/app/components/admin/groups/hidden_group_form_component.rb b/app/components/admin/groups/hidden_group_form_component.rb deleted file mode 100644 index a2d2cc551..000000000 --- a/app/components/admin/groups/hidden_group_form_component.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Admin::Groups::HiddenGroupFormComponent < ViewComponent::Base - def initialize(form:) - @form = form - end -end diff --git a/app/components/admin/groups/user_add_component.html.erb b/app/components/admin/groups/user_add_component.html.erb index 18b53e32d..f43df8a2d 100644 --- a/app/components/admin/groups/user_add_component.html.erb +++ b/app/components/admin/groups/user_add_component.html.erb @@ -6,7 +6,8 @@
<%= @user.name %>
<%= @user.email %>
- <%= button_to controller: :group_memberships, method: :post, action: :create, group_membership: { group_id: @group.id, user_id: @user.id } do %> - <%= render Common::AddButtonComponent.new %> - <% end %> - + <%#= button_to controller: :group_memberships, method: :post, action: :create, group_membership: { group_id: @group.id, user_id: @user.id }, do %> + <%= button_to admin_group_memberships_path(group_membership: { group_id: @group.id, user_id: @user.id }), method: :post, data: { turbo_frame: "modal" } do %> + <%= render Common::AddButtonComponent.new %> + <% end %> + diff --git a/app/components/admin/permissions/group_form_component.html.erb b/app/components/admin/permissions/group_form_component.html.erb new file mode 100644 index 000000000..3462a580f --- /dev/null +++ b/app/components/admin/permissions/group_form_component.html.erb @@ -0,0 +1,44 @@ +<%= tag.turbo_frame id: 'modal' do %> + +<% end %> diff --git a/app/components/admin/permissions/group_form_component.rb b/app/components/admin/permissions/group_form_component.rb new file mode 100644 index 000000000..2a45069b2 --- /dev/null +++ b/app/components/admin/permissions/group_form_component.rb @@ -0,0 +1,5 @@ +class Admin::Permissions::GroupFormComponent < ViewComponent::Base + def initialize(group:) + @group = group + end +end diff --git a/app/components/admin/permissions/group_rename_component.html.erb b/app/components/admin/permissions/group_rename_component.html.erb new file mode 100644 index 000000000..30c1e6b8f --- /dev/null +++ b/app/components/admin/permissions/group_rename_component.html.erb @@ -0,0 +1,28 @@ +
+ + +
diff --git a/app/components/admin/permissions/group_rename_component.rb b/app/components/admin/permissions/group_rename_component.rb new file mode 100644 index 000000000..6b8d012f4 --- /dev/null +++ b/app/components/admin/permissions/group_rename_component.rb @@ -0,0 +1,5 @@ +class Admin::Groups::GroupRenameComponent < ViewComponent::Base + def initialize(group) + @group = group + end +end diff --git a/app/components/admin/permissions/groups_list_component.html.erb b/app/components/admin/permissions/groups_list_component.html.erb new file mode 100644 index 000000000..a1f61b825 --- /dev/null +++ b/app/components/admin/permissions/groups_list_component.html.erb @@ -0,0 +1,50 @@ +
+
+
+
Skupiny
+
+
+ <% @groups.each do |group| %> + <%= render Admin::Permissions::GroupsListRowComponent.new(group) %> + <% end %> +
+
+
+
+
+ <%= render Icons::InfoComponent.new %> +
+
+
Pridať používateľov
+
Existujúci používatelia môžu byť rozdelení do skupín, napríklad podľa zodpovednosti
+
+ <%= link_to admin_tenant_users_path, class:"px-3.5 py-2.5 bg-white rounded-md border border-gray-300 justify-center items-center gap-2.5 flex" do %> +

Nastaviť používateľov

+ <% end %> +
+
+
+ <%= render Icons::InfoComponent.new %> +
+
+
Pridať skupiny
+
Používatelia môžu patriť do skupín, napríklad podľa zodpovednosti
+
+ <%= link_to admin_tenant_groups_path, class:"px-3.5 py-2.5 bg-white rounded-md border border-gray-300 justify-center items-center gap-2.5 flex" do %> +

Nastaviť skupiny

+ <% end %> +
+
+
+ <%= render Icons::InfoComponent.new %> +
+
+
Pridať štítky
+
Štítky môžu byť použité na limitovanie prístupu k správam pre jednotlivých používateľov/skupiny
+
+ <%= link_to admin_tenant_tags_path(Current.tenant), class:"px-3.5 py-2.5 bg-white rounded-md border border-gray-300 justify-center items-center gap-2.5 flex" do %> +

Nastaviť štítky

+ <% end %> +
+
+
diff --git a/app/components/admin/permissions/groups_list_component.rb b/app/components/admin/permissions/groups_list_component.rb new file mode 100644 index 000000000..20bc03135 --- /dev/null +++ b/app/components/admin/permissions/groups_list_component.rb @@ -0,0 +1,5 @@ +class Admin::Permissions::GroupsListComponent < ViewComponent::Base + def initialize(groups) + @groups = groups + end +end diff --git a/app/components/admin/permissions/groups_list_row_component.html.erb b/app/components/admin/permissions/groups_list_row_component.html.erb new file mode 100644 index 000000000..4d2c06059 --- /dev/null +++ b/app/components/admin/permissions/groups_list_row_component.html.erb @@ -0,0 +1,31 @@ +
+
+
+ <%= @group.name[0] %> +
+
+
+ <% if @group.is_modifiable? %> + <%= render Admin::Groups::GroupRenameComponent.new(@group) if @group.is_modifiable? %> + <% else %> + <%= @group.name %> + <% end %> +
+
+ <%= t :user, count: @group.users.count %> +
+
+
+
+ <% @group.tag_groups.each do |tag_group| %> + <%= render Admin::Permissions::TagComponent.new(tag_group.tag) %> + <% end %> +
+
+
+
+ <%= link_to edit_permissions_admin_tenant_group_path(@group.tenant, @group), data: { turbo_frame: :modal } do %> + <%= render Common::EditButtonComponent.new %> + <% end %> +
+
diff --git a/app/components/admin/permissions/groups_list_row_component.rb b/app/components/admin/permissions/groups_list_row_component.rb new file mode 100644 index 000000000..66b141d3e --- /dev/null +++ b/app/components/admin/permissions/groups_list_row_component.rb @@ -0,0 +1,5 @@ +class Admin::Permissions::GroupsListRowComponent < ViewComponent::Base + def initialize(group) + @group = group + end +end diff --git a/app/components/admin/permissions/members_list_row_view_only_component.html.erb b/app/components/admin/permissions/members_list_row_view_only_component.html.erb new file mode 100644 index 000000000..75ac7e9d3 --- /dev/null +++ b/app/components/admin/permissions/members_list_row_view_only_component.html.erb @@ -0,0 +1,7 @@ +
+ +
+
+
<%= @user.name %>
+
<%= @user.email %>
+
diff --git a/app/components/admin/permissions/members_list_row_view_only_component.rb b/app/components/admin/permissions/members_list_row_view_only_component.rb new file mode 100644 index 000000000..2cf57fcc7 --- /dev/null +++ b/app/components/admin/permissions/members_list_row_view_only_component.rb @@ -0,0 +1,6 @@ +class Admin::Groups::MembersListRowViewOnlyComponent < ViewComponent::Base + def initialize(group_membership) + @group_membership = group_membership + @user = @group_membership.user + end +end diff --git a/app/components/admin/permissions/new_group_form_component.html.erb b/app/components/admin/permissions/new_group_form_component.html.erb new file mode 100644 index 000000000..f6ca64b8c --- /dev/null +++ b/app/components/admin/permissions/new_group_form_component.html.erb @@ -0,0 +1,35 @@ +<%= tag.turbo_frame id: 'modal' do %> + +<% end %> diff --git a/app/components/admin/permissions/new_group_form_component.rb b/app/components/admin/permissions/new_group_form_component.rb new file mode 100644 index 000000000..9f60f975c --- /dev/null +++ b/app/components/admin/permissions/new_group_form_component.rb @@ -0,0 +1,5 @@ +class Admin::Groups::NewGroupFormComponent < ViewComponent::Base + def initialize(group) + @group = group + end +end diff --git a/app/components/admin/permissions/permission_add_component.html.erb b/app/components/admin/permissions/permission_add_component.html.erb new file mode 100644 index 000000000..c6f00b054 --- /dev/null +++ b/app/components/admin/permissions/permission_add_component.html.erb @@ -0,0 +1,8 @@ +<%= button_to admin_tenant_tag_groups_path(@group.tenant, tag_group: { group_id: @group.id, tag_id: @tag.id }), data: { turbo_frame: "modal" } do %> +
+

<%= @tag.name %>

+ + + +
+<% end %> diff --git a/app/components/admin/permissions/permission_add_component.rb b/app/components/admin/permissions/permission_add_component.rb new file mode 100644 index 000000000..aa7b75310 --- /dev/null +++ b/app/components/admin/permissions/permission_add_component.rb @@ -0,0 +1,7 @@ +class Admin::Permissions::PermissionAddComponent < ViewComponent::Base + def initialize(tag:, group:) + @tag = tag + @group = group + @new_permission = TagGroup.new({ group_id: @group.id, tag_id: @tag.id }) + end +end diff --git a/app/components/admin/permissions/permissions_add_popup_component.html.erb b/app/components/admin/permissions/permissions_add_popup_component.html.erb new file mode 100644 index 000000000..eebb66379 --- /dev/null +++ b/app/components/admin/permissions/permissions_add_popup_component.html.erb @@ -0,0 +1,23 @@ + diff --git a/app/components/admin/permissions/permissions_add_popup_component.rb b/app/components/admin/permissions/permissions_add_popup_component.rb new file mode 100644 index 000000000..722b81aa3 --- /dev/null +++ b/app/components/admin/permissions/permissions_add_popup_component.rb @@ -0,0 +1,6 @@ +class Admin::Permissions::PermissionsAddPopupComponent < ViewComponent::Base + def initialize(tags:, group:) + @group = group + @tags = tags + end +end diff --git a/app/components/admin/permissions/permissions_list_row_component.html.erb b/app/components/admin/permissions/permissions_list_row_component.html.erb new file mode 100644 index 000000000..c7c339d1b --- /dev/null +++ b/app/components/admin/permissions/permissions_list_row_component.html.erb @@ -0,0 +1,4 @@ +<%= render Admin::Permissions::TagComponent.new(@tag_group.tag) %> +<%= button_to admin_tag_group_path(@tag_group), method: :delete do %> + <%= render Common::DeleteButtonComponent.new %> +<% end %> diff --git a/app/components/admin/permissions/permissions_list_row_component.rb b/app/components/admin/permissions/permissions_list_row_component.rb new file mode 100644 index 000000000..db2f01265 --- /dev/null +++ b/app/components/admin/permissions/permissions_list_row_component.rb @@ -0,0 +1,6 @@ +class Admin::Permissions::PermissionsListRowComponent < ViewComponent::Base + def initialize(tag_group) + @tag_group = tag_group + @tag = @tag_group.tag + end +end diff --git a/app/components/admin/permissions/tag_component.html.erb b/app/components/admin/permissions/tag_component.html.erb new file mode 100644 index 000000000..af3629573 --- /dev/null +++ b/app/components/admin/permissions/tag_component.html.erb @@ -0,0 +1,7 @@ + +
+

<%= @tag.name %>

+ + + +
diff --git a/app/components/admin/permissions/tag_component.rb b/app/components/admin/permissions/tag_component.rb new file mode 100644 index 000000000..41767a466 --- /dev/null +++ b/app/components/admin/permissions/tag_component.rb @@ -0,0 +1,5 @@ +class Admin::Permissions::TagComponent < ViewComponent::Base + def initialize(tag) + @tag = tag + end +end diff --git a/app/components/admin/tag_group_table_row_component.html.erb b/app/components/admin/tag_group_table_row_component.html.erb new file mode 100644 index 000000000..25ac5897f --- /dev/null +++ b/app/components/admin/tag_group_table_row_component.html.erb @@ -0,0 +1,12 @@ + + + <%= link_to @tag_group.tag.name, admin_tenant_tag_path(Current.tenant, @tag_group.tag) %> + + + <%= @tag_group.tag.visible %> + + + <%= button_to 'Unassign tag', admin_tag_group_path(@tag_group), + method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium cursor-pointer" %> + + diff --git a/app/components/admin/tag_group_table_row_component.rb b/app/components/admin/tag_group_table_row_component.rb new file mode 100644 index 000000000..51d873708 --- /dev/null +++ b/app/components/admin/tag_group_table_row_component.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +class Admin::TagGroupTableRowComponent < ViewComponent::Base + with_collection_parameter :tag_group + + def initialize(tag_group:) + @tag_group = tag_group + end + +end diff --git a/app/components/admin/tag_table_row_component.html.erb b/app/components/admin/tag_table_row_component.html.erb index 8318f76fe..ff8997bba 100644 --- a/app/components/admin/tag_table_row_component.html.erb +++ b/app/components/admin/tag_table_row_component.html.erb @@ -9,12 +9,12 @@ case @tag_action when 'add' %> - <%= form_with model: [:admin, TagUser.new(tag_id: @tag.id, user_id: @user.id)], class: "contents" do |form| %> + <%= form_with model: [:admin, TagGroup.new(tag_id: @tag.id, group_id: @group.id)], class: "contents" do |form| %> <%= form.hidden_field :tag_id %> - <%= form.hidden_field :user_id %> + <%= form.hidden_field :group_id %> <%= form.submit 'Assign tag' ,class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> - - <% end %> + <% end %> + <% else %> <%= link_to 'Edit this tag', edit_admin_tenant_tag_path(Current.tenant, @tag), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> diff --git a/app/components/admin/tag_table_row_component.rb b/app/components/admin/tag_table_row_component.rb index 22758878d..2dddc1de5 100644 --- a/app/components/admin/tag_table_row_component.rb +++ b/app/components/admin/tag_table_row_component.rb @@ -3,9 +3,9 @@ class Admin::TagTableRowComponent < ViewComponent::Base with_collection_parameter :tag - def initialize(tag:, user: "", tag_action: "") + def initialize(tag:, group: "", tag_action: "") @tag = tag - @user = user + @group = group @tag_action = tag_action end end diff --git a/app/components/admin/tag_user_table_row_component.html.erb b/app/components/admin/tag_user_table_row_component.html.erb index a3ae3b215..b49b47ee7 100644 --- a/app/components/admin/tag_user_table_row_component.html.erb +++ b/app/components/admin/tag_user_table_row_component.html.erb @@ -6,7 +6,7 @@ <%= @tag_user.tag.visible %> - <%= button_to 'Unassign tag', admin_tag_user_path(@tag_user), + <%#= button_to 'Unassign tag', admin_tag_user_path(@tag_user), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium cursor-pointer" %> diff --git a/app/components/admin/tags/external_tags_component.html.erb b/app/components/admin/tags/external_tags_component.html.erb new file mode 100644 index 000000000..779ad420d --- /dev/null +++ b/app/components/admin/tags/external_tags_component.html.erb @@ -0,0 +1,19 @@ +
+
+
+

Zobraziť štítky zo štátnej schránky

+
+
+ <% @tags.each do |tag| %> +
+
+
+
+

<%= tag.name %>

+
+
+ <%= render Admin::Tags::VisibilityToggleComponent.new(tag) %> +
+
+ <% end %> +
diff --git a/app/components/admin/tags/external_tags_component.rb b/app/components/admin/tags/external_tags_component.rb new file mode 100644 index 000000000..251d5412b --- /dev/null +++ b/app/components/admin/tags/external_tags_component.rb @@ -0,0 +1,5 @@ +class Admin::Tags::ExternalTagsComponent < ViewComponent::Base + def initialize(tags) + @tags = tags + end +end diff --git a/app/components/admin/tags/tag_form_component.html.erb b/app/components/admin/tags/tag_form_component.html.erb new file mode 100644 index 000000000..297a572ae --- /dev/null +++ b/app/components/admin/tags/tag_form_component.html.erb @@ -0,0 +1,35 @@ +<%= tag.turbo_frame id: 'modal' do %> + +<% end %> diff --git a/app/components/admin/tags/tag_form_component.rb b/app/components/admin/tags/tag_form_component.rb new file mode 100644 index 000000000..cbad0d5a4 --- /dev/null +++ b/app/components/admin/tags/tag_form_component.rb @@ -0,0 +1,6 @@ +class Admin::Tags::TagFormComponent < ViewComponent::Base + def initialize(tag:, action:) + @tag = tag + @actio = action + end +end diff --git a/app/components/admin/tags/tag_rename_component.html.erb b/app/components/admin/tags/tag_rename_component.html.erb new file mode 100644 index 000000000..4a5e3bddb --- /dev/null +++ b/app/components/admin/tags/tag_rename_component.html.erb @@ -0,0 +1,28 @@ +
+ + +
diff --git a/app/components/admin/tags/tag_rename_component.rb b/app/components/admin/tags/tag_rename_component.rb new file mode 100644 index 000000000..f8cc372b5 --- /dev/null +++ b/app/components/admin/tags/tag_rename_component.rb @@ -0,0 +1,5 @@ +class Admin::Tags::TagRenameComponent < ViewComponent::Base + def initialize(tag) + @tag = tag + end +end diff --git a/app/components/admin/tags/tags_list_component.html.erb b/app/components/admin/tags/tags_list_component.html.erb new file mode 100644 index 000000000..9a68eddb0 --- /dev/null +++ b/app/components/admin/tags/tags_list_component.html.erb @@ -0,0 +1,42 @@ +
+
+
+
Štítky
+ <%= link_to new_admin_tenant_tag_path, class:"px-3.5 py-2.5 bg-blue-600 rounded-md justify-center items-center gap-2.5 flex" do %> +

Vytvoriť štítok

+ <% end %> +
+
+ <% @internal_tags.each do |tag| %> + <%= render Admin::Tags::TagsListRowComponent.new(tag) %> + <% end %> +
+
+ <%= render Admin::Tags::ExternalTagsComponent.new(@external_tags) %> +
+
+
+ <%= render Icons::InfoComponent.new %> +
+
+
Nataviť prístup na základe štítkov
+
Jednotlivý používatelia alebo skupiny používateľov môžu mať rozdielny prístup k správam
+
+ <%= link_to admin_tenant_tag_groups_path, class:"px-3.5 py-2.5 bg-white rounded-md border border-gray-300 justify-center items-center gap-2.5 flex" do %> +

Nastaviť prístup

+ <% end %> +
+
+
+ <%= render Icons::InfoComponent.new %> +
+
+
Zautomatizovať pridávanie štítkov
+
V prípade jasne zadaných pravidiel je možné automaticky k novým správam prideliť štítky
+
+ <%= link_to settings_automation_rules_path, class:"px-3.5 py-2.5 bg-white rounded-md border border-gray-300 justify-center items-center gap-2.5 flex" do %> +

Nastaviť pravidlá

+ <% end %> +
+
+
diff --git a/app/components/admin/tags/tags_list_component.rb b/app/components/admin/tags/tags_list_component.rb new file mode 100644 index 000000000..d52127bdb --- /dev/null +++ b/app/components/admin/tags/tags_list_component.rb @@ -0,0 +1,6 @@ +class Admin::Tags::TagsListComponent < ViewComponent::Base + def initialize(tags) + @external_tags = tags.where(external: true).order(:name) + @internal_tags = tags.where(external: false).order(:name) + end +end diff --git a/app/components/admin/tags/tags_list_row_component.html.erb b/app/components/admin/tags/tags_list_row_component.html.erb new file mode 100644 index 000000000..e3ba0cb85 --- /dev/null +++ b/app/components/admin/tags/tags_list_row_component.html.erb @@ -0,0 +1,15 @@ +
+
+
+ <%= render Admin::Tags::TagRenameComponent.new(@tag) %> +
+
+
+ <%= link_to edit_admin_tenant_tag_path(@tag.tenant, @tag) do %> + <%= render Common::EditButtonComponent.new %> + <% end %> + <%= button_to admin_tenant_tag_path(@tag.tenant, @tag), method: :delete do %> + <%= render Common::DeleteButtonComponent.new %> + <% end %> +
+
diff --git a/app/components/admin/tags/tags_list_row_component.rb b/app/components/admin/tags/tags_list_row_component.rb new file mode 100644 index 000000000..9fee83094 --- /dev/null +++ b/app/components/admin/tags/tags_list_row_component.rb @@ -0,0 +1,5 @@ +class Admin::Tags::TagsListRowComponent < ViewComponent::Base + def initialize(tag) + @tag = tag + end +end diff --git a/app/components/admin/tags/visibility_toggle_component.html.erb b/app/components/admin/tags/visibility_toggle_component.html.erb new file mode 100644 index 000000000..5386261cf --- /dev/null +++ b/app/components/admin/tags/visibility_toggle_component.html.erb @@ -0,0 +1,9 @@ +<%= tag.turbo_frame id:"@tag-form-visible-#{tag.id}" do %> + <%= form_with url:visibility_toggle_admin_tenant_tag_path(@tag.tenant, @tag), method: :patch do |form| %> + <%= form.hidden_field :visible, value:!@tag.visible %> + <%= form.button class:"#{@tag.visible ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: :false}, data: @dialog do %> + Use setting + + <% end %> + <% end %> +<% end %> diff --git a/app/components/admin/tags/visibility_toggle_component.rb b/app/components/admin/tags/visibility_toggle_component.rb new file mode 100644 index 000000000..bcc9279d0 --- /dev/null +++ b/app/components/admin/tags/visibility_toggle_component.rb @@ -0,0 +1,8 @@ +class Admin::Tags::VisibilityToggleComponent < ViewComponent::Base + def initialize(tag) + @tag = tag + @dialog = { + turbo_confirm: 'Naozaj zrušiť viditeľnosť štítku? Používateľom nebude zobrazovaný v zozname štítkov, a nedostanú sa k príslušným správam', + } if @tag.visible + end +end diff --git a/app/components/admin/tenants/tenant_form_component.html.erb b/app/components/admin/tenants/tenant_form_component.html.erb new file mode 100644 index 000000000..36e0d0c2a --- /dev/null +++ b/app/components/admin/tenants/tenant_form_component.html.erb @@ -0,0 +1,35 @@ +<%= tag.turbo_frame id: 'modal' do %> + +<% end %> diff --git a/app/components/admin/tenants/tenant_form_component.rb b/app/components/admin/tenants/tenant_form_component.rb new file mode 100644 index 000000000..409ab7be2 --- /dev/null +++ b/app/components/admin/tenants/tenant_form_component.rb @@ -0,0 +1,6 @@ +class Admin::Tenants::TenantFormComponent < ViewComponent::Base + def initialize(tenant:, action:) + @tenant = tenant + @action = action + end +end diff --git a/app/components/admin/tenants/tenant_rename_component.html.erb b/app/components/admin/tenants/tenant_rename_component.html.erb new file mode 100644 index 000000000..641f4984d --- /dev/null +++ b/app/components/admin/tenants/tenant_rename_component.html.erb @@ -0,0 +1,28 @@ +
+ + +
diff --git a/app/components/admin/tenants/tenant_rename_component.rb b/app/components/admin/tenants/tenant_rename_component.rb new file mode 100644 index 000000000..23762b681 --- /dev/null +++ b/app/components/admin/tenants/tenant_rename_component.rb @@ -0,0 +1,5 @@ +class Admin::Tenants::TenantRenameComponent < ViewComponent::Base + def initialize(tenant) + @tenant = tenant + end +end diff --git a/app/components/admin/tenants/tenants_list_component.html.erb b/app/components/admin/tenants/tenants_list_component.html.erb new file mode 100644 index 000000000..fb32fd8a7 --- /dev/null +++ b/app/components/admin/tenants/tenants_list_component.html.erb @@ -0,0 +1,15 @@ +
+
+
+
Tenanti / Organizácie
+ <%= link_to new_admin_tenant_path, class:"px-3.5 py-2.5 bg-blue-600 rounded-md justify-center items-center gap-2.5 flex" do %> +

Vytvoriť nového tenanta

+ <% end %> +
+
+ <% @tenants.each do |tenant| %> + <%= render Admin::Tenants::TenantsListRowComponent.new(tenant) %> + <% end %> +
+
+
diff --git a/app/components/admin/tenants/tenants_list_component.rb b/app/components/admin/tenants/tenants_list_component.rb new file mode 100644 index 000000000..04f98374a --- /dev/null +++ b/app/components/admin/tenants/tenants_list_component.rb @@ -0,0 +1,5 @@ +class Admin::Tenants::TenantsListComponent < ViewComponent::Base + def initialize(tenants) + @tenants = tenants + end +end diff --git a/app/components/admin/tenants/tenants_list_row_component.html.erb b/app/components/admin/tenants/tenants_list_row_component.html.erb new file mode 100644 index 000000000..8ce6252a7 --- /dev/null +++ b/app/components/admin/tenants/tenants_list_row_component.html.erb @@ -0,0 +1,18 @@ +
+
+ <%= @tenant.name[0] %> +
+
+
+ <%= render Admin::Tenants::TenantRenameComponent.new(@tenant) %> +
+
+
+ <%= link_to edit_admin_tenant_path(@tenant) do %> + <%= render Common::EditButtonComponent.new %> + <% end %> + <%= button_to admin_tenant_path(@tenant), method: :delete do %> + <%= render Common::DeleteButtonComponent.new %> + <% end %> +
+
diff --git a/app/components/admin/tenants/tenants_list_row_component.rb b/app/components/admin/tenants/tenants_list_row_component.rb new file mode 100644 index 000000000..236e80d42 --- /dev/null +++ b/app/components/admin/tenants/tenants_list_row_component.rb @@ -0,0 +1,5 @@ +class Admin::Tenants::TenantsListRowComponent < ViewComponent::Base + def initialize(tenant) + @tenant = tenant + end +end diff --git a/app/components/admin/users/user_form_component.html.erb b/app/components/admin/users/user_form_component.html.erb index 12b8fcdd0..b35ead305 100644 --- a/app/components/admin/users/user_form_component.html.erb +++ b/app/components/admin/users/user_form_component.html.erb @@ -1,25 +1,25 @@ <%= tag.turbo_frame id: 'modal' do %>
- <%= link_to edit_settings_automation_rule_path(@automation_rule), data: { turbo_frame: :modal } do %> + <%= link_to edit_settings_automation_rule_path(@automation_rule) do %> <%= render Common::EditButtonComponent.new %> <% end %> <%= button_to settings_automation_rule_path(@automation_rule), method: :delete do %> diff --git a/app/controllers/admin/boxes_controller.rb b/app/controllers/admin/boxes_controller.rb index abee6b7b5..61efae04d 100644 --- a/app/controllers/admin/boxes_controller.rb +++ b/app/controllers/admin/boxes_controller.rb @@ -23,6 +23,7 @@ def edit def create @box = Current.tenant.boxes.new(box_params) authorize([:admin, @box]) + @box.color = Box.colors.keys[Digest::MD5.hexdigest(@box.name).to_i(16) % Box.colors.size] if @box.save redirect_to admin_tenant_url(Current.tenant), notice: "Box was successfully created." @@ -53,6 +54,6 @@ def set_box end def box_params - params.require(:box).permit(:name, :uri) + params.require(:box).permit(:name, :uri, :short_name, :color) end end diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 7172db990..3f08b1dbe 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -1,5 +1,5 @@ class Admin::GroupsController < ApplicationController - before_action :set_group, only: %i[show edit update destroy edit_members search_non_members] + before_action :set_group, only: %i[show edit update destroy edit_members edit_permissions search_non_members search_non_tags] def index authorize([:admin, Group]) @@ -25,13 +25,17 @@ def edit_members authorize([:admin, @group]) end + def edit_permissions + authorize([:admin, @group]) + end + def create @group = Current.tenant.groups.new(group_params) @group.group_type = 'CUSTOM' authorize([:admin, @group]) if @group.save - redirect_to edit_members_admin_tenant_group_url(Current.tenant, @group, step: :new), notice: 'Group was successfully created.' + redirect_to edit_members_admin_tenant_group_url(Current.tenant, @group, step: :new), notice: 'Group was successfully created' else render :new, status: :unprocessable_entity end @@ -40,8 +44,7 @@ def create def update authorize([:admin, @group]) if @group.update(group_params) - flash[:notice] = 'Group was successfully updated' - render turbo_stream: turbo_stream.action(:redirect, admin_tenant_groups_url) + redirect_to admin_tenant_groups_url(Current.tenant), notice: 'Group was successfully updated' else render :edit, status: :unprocessable_entity end @@ -50,8 +53,7 @@ def update def destroy authorize([:admin, @group]) @group.destroy - flash[:notice] = 'Group was successfully updated' - render turbo_stream: turbo_stream.action(:redirect, admin_tenant_groups_url) + redirect_to admin_tenant_groups_url(Current.tenant), notice: 'Group was successfully destroyed' end def search_non_members @@ -61,6 +63,13 @@ def search_non_members @users = non_members_search_clause end + def search_non_tags + authorize([:admin, @group]) + return if params[:name_search].blank? + + @tags = non_tags_search_clause + end + private def non_members_search_clause @@ -71,6 +80,14 @@ def non_members_search_clause .order(:name) end + def non_tags_search_clause + policy_scope([:admin, Tag]) + .where(tenant: Current.tenant.id) + .where.not(id: Tag.joins(:tag_groups).where(tag_groups: { group_id: @group.id })) + .where('unaccent(name) ILIKE unaccent(?)', "%#{params[:name_search]}%") + .order(:name) + end + def set_group @group = policy_scope([:admin, Group]).find(params[:id]) end diff --git a/app/controllers/admin/tag_groups_controller.rb b/app/controllers/admin/tag_groups_controller.rb index a8e4572b6..8e8e53749 100644 --- a/app/controllers/admin/tag_groups_controller.rb +++ b/app/controllers/admin/tag_groups_controller.rb @@ -1,20 +1,24 @@ class Admin::TagGroupsController < ApplicationController - before_action :set_tag_group, only: %i[ destroy ] - # TODO - rediscuss the whole concept of SITE_ADMIN vs TENANT admin responsibilities and functionality + before_action :set_tag_group, only: %i[destroy] + # TODO: rediscuss the whole concept of SITE_ADMIN vs TENANT admin responsibilities and functionality + + # TODO: Toto je trochu nestastne, ze to nastavuje skupiny. Komponent, co listuje vsetky TagGroups ale naozaj listuje skupiny, a k nim potom tagy. Keby som to daval pod skupiny, tak asi pod samostatnu akciu, aby som odlisil na aky komponent idem (kedze je to iny, ako pre administraciu skupin) + def index + authorize([:admin, TagGroup]) + @groups = policy_scope([:admin, Group]) + end def create @tag_group = TagGroup.new(tag_group_params) authorize([:admin, @tag_group]) - @tag_group.save! - - redirect_back fallback_location:"/", notice: "Tag permission was successfully assigned." + redirect_to edit_permissions_admin_tenant_group_url(Current.tenant, @tag_group.group), notice: "Tag permission was successfully assigned" end def destroy authorize([:admin, @tag_group]) @tag_group.destroy - redirect_back fallback_location:"/", notice: "Tag permission was successfully destroyed." + redirect_to edit_permissions_admin_tenant_group_url(Current.tenant, @tag_group.group), notice: "Tag permission was successfully destroyed" end private diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index b2b9562cb..3d631590c 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -1,5 +1,5 @@ class Admin::TagsController < ApplicationController - before_action :set_tag, only: %i[show edit update destroy] + before_action :set_tag, only: %i[show edit update destroy visibility_toggle] def index authorize [:admin, Tag] @@ -22,10 +22,11 @@ def edit def create @tag = Current.tenant.tags.new(tag_params) + @tag.user_id = Current.user.id authorize([:admin, @tag]) if @tag.save - redirect_to admin_tenant_url(Current.tenant), notice: "Tag was successfully created." + redirect_to admin_tenant_tags_path(Current.tenant), notice: 'Tag was successfully created' else render :new, status: :unprocessable_entity end @@ -34,16 +35,21 @@ def create def update authorize([:admin, @tag]) if @tag.update(tag_params) - redirect_to admin_tenant_url(Current.tenant), notice: "Tag was successfully updated." + redirect_to admin_tenant_tags_path(Current.tenant), notice: 'Tag was successfully updated' else render :edit, status: :unprocessable_entity end end + def visibility_toggle + authorize([:admin, @tag]) + @tag.update(tag_params_visibility) + end + def destroy authorize([:admin, @tag]) @tag.destroy - redirect_to admin_tenant_url(Current.tenant), notice: "Tag was successfully destroyed." + redirect_to admin_tenant_tags_path(Current.tenant), notice: 'Tag was successfully created' end private @@ -55,4 +61,8 @@ def set_tag def tag_params params.require(:tag).permit(:name, :visible, :user_id) end + + def tag_params_visibility + params.permit(:visible) + end end diff --git a/app/controllers/admin/tenants_controller.rb b/app/controllers/admin/tenants_controller.rb index b8a16fb3c..8cc883821 100644 --- a/app/controllers/admin/tenants_controller.rb +++ b/app/controllers/admin/tenants_controller.rb @@ -25,28 +25,20 @@ def edit def create @tenant = Tenant.new(tenant_params) authorize([:admin, @tenant]) - respond_to do |format| - if @tenant.save - format.html { redirect_to admin_tenant_url(@tenant), notice: 'Tenant was successfully created.' } - format.json { render :show, status: :created, location: @tenant } - else - format.html { render :new, status: :unprocessable_entity } - format.json { render json: @tenant.errors, status: :unprocessable_entity } - end + if @tenant.save + redirect_to admin_tenants_url, notice: 'Tenant was successfully created' + else + render :new, status: :unprocessable_entity end end # PATCH/PUT /tenants/1 or /tenants/1.json def update authorize([:admin, @tenant]) - respond_to do |format| - if @tenant.update(tenant_params) - format.html { redirect_to admin_tenant_url(@tenant), notice: 'Tenant was successfully updated.' } - format.json { render :show, status: :ok, location: @tenant } - else - format.html { render :edit, status: :unprocessable_entity } - format.json { render json: @tenant.errors, status: :unprocessable_entity } - end + if @tenant.update(tenant_params) + redirect_to admin_tenants_url, notice: 'Tenant was successfully updated' + else + render :edit, status: :unprocessable_entity end end @@ -54,11 +46,8 @@ def update def destroy authorize([:admin, @tenant]) @tenant.destroy - session[:tenant_id] = nil - respond_to do |format| - format.html { redirect_to admin_tenants_url, notice: 'Tenant was successfully destroyed.' } - format.json { head :no_content } - end + session[:tenant_id] = nil if Current.tenant == @tenant + redirect_to admin_tenants_url, notice: 'Tenant was successfully destroyed' end private @@ -72,4 +61,4 @@ def set_tenant def tenant_params params.require(:tenant).permit(:name) end -end \ No newline at end of file +end diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 890ab0511..feba69499 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -20,8 +20,7 @@ def create authorize([:admin, @user]) if @user.save - flash[:notice] = 'User was successfully created' - render turbo_stream: turbo_stream.action(:redirect, admin_tenant_users_path(Current.tenant)) + redirect_to admin_tenant_users_url(Current.tenant), notice: 'User was successfully created' else render :new, status: :unprocessable_entity end @@ -30,8 +29,7 @@ def create def update authorize([:admin, @user]) if @user.update(user_params) - flash[:notice] = 'User was successfully updated' - render turbo_stream: turbo_stream.action(:redirect, admin_tenant_users_path(Current.tenant)) + redirect_to admin_tenant_users_url(Current.tenant), notice: 'User was successfully updated' else render :edit, status: :unprocessable_entity end @@ -40,8 +38,7 @@ def update def destroy authorize([:admin, @user]) @user.destroy - flash[:notice] = 'User was successfully destroyed' - render turbo_stream: turbo_stream.action(:redirect, admin_tenant_users_path(Current.tenant)) + redirect_to admin_tenant_users_url(Current.tenant), notice: 'User was successfully destroyed' end private diff --git a/app/controllers/settings/automation_rules_controller.rb b/app/controllers/settings/automation_rules_controller.rb index 3614cfe27..b9eb8d461 100644 --- a/app/controllers/settings/automation_rules_controller.rb +++ b/app/controllers/settings/automation_rules_controller.rb @@ -22,8 +22,7 @@ def create @automation_rule.user = Current.user authorize @automation_rule, policy_class: Settings::AutomationRulePolicy if @automation_rule.save - flash[:notice] = 'Thing was successfully created' - render turbo_stream: turbo_stream.action(:redirect, settings_automation_rules_path) + redirect_to settings_automation_rules_path, notice: 'Rule was successfully created' else render :new, status: :unprocessable_entity end @@ -32,8 +31,7 @@ def create def update authorize @automation_rule, policy_class: Settings::AutomationRulePolicy if @automation_rule.update(automation_rule_params) - flash[:notice] = 'Thing was successfully updated' - render turbo_stream: turbo_stream.action(:redirect, settings_automation_rules_path) + redirect_to settings_automation_rules_path, notice: 'Rule was successfully created' else # TODO: Vieme nejako zachranit? render :new, status: :unprocessable_entity @@ -54,7 +52,6 @@ def actions_step authorize @automation_rule, policy_class: Settings::AutomationRulePolicy end - def conditions_step authorize @automation_rule, policy_class: Settings::AutomationRulePolicy end diff --git a/app/jobs/drafts/parse_import_job.rb b/app/jobs/drafts/parse_import_job.rb index 40680da35..bc2d7af66 100644 --- a/app/jobs/drafts/parse_import_job.rb +++ b/app/jobs/drafts/parse_import_job.rb @@ -77,9 +77,11 @@ def load_import_csv(import, csv_path) last_message_delivered_at: Time.now ) + # TODO: Nemali by sme tento vytvorit hned s tenantom? Co ked niekto zalozi rucne medzitym? A to external je v tomto pripade matuce, mozno by to malo byt "system". Povedzme si message_thread.tags << Tag.find_or_create_by!( name: "Drafts", tenant: import.box.tenant, + external: false visible: true ) diff --git a/app/lib/sidebar_menu.rb b/app/lib/sidebar_menu.rb index 7b85c93ed..866896645 100644 --- a/app/lib/sidebar_menu.rb +++ b/app/lib/sidebar_menu.rb @@ -14,7 +14,7 @@ def get_menu def initial_structure(controller, action) return default_message_thread_menu if controller.in? %w[messages message_drafts] - return admin_main_menu if (controller.in? %w[groups users tags automation_rules boxes]) && (Current.user.admin? || Current.user.site_admin?) + return admin_main_menu if (controller.in? %w[groups users tags tag_groups automation_rules boxes tenants]) && (Current.user.admin? || Current.user.site_admin?) default_main_menu end @@ -31,17 +31,22 @@ def default_main_menu def admin_main_menu [ Layout::BackToBoxComponent.new(), + Layout::SidebarDividerComponent.new(), TW::SidebarMenuDividerComponent.new(name: 'Produkt'), + Current.user.site_admin? ? TW::SidebarMenuItemComponent.new(name: 'Tenanti', url: admin_tenants_path, icon: Icons::GroupsComponent.new) : nil, TW::SidebarMenuItemComponent.new(name: 'Používatelia', url: admin_tenant_users_path(Current.tenant), icon: Icons::UsersComponent.new), TW::SidebarMenuItemComponent.new(name: 'Pravidlá', url: settings_automation_rules_path, icon: Icons::RulesComponent.new), - TW::SidebarMenuItemComponent.new(name: 'Schránky', url: boxes_path, icon: Icons::BoxesComponent.new), + TW::SidebarMenuItemComponent.new(name: 'Prístup', url: admin_tenant_tag_groups_path(Current.tenant), icon: Icons::ClosedLockComponent.new), + TW::SidebarMenuItemComponent.new(name: 'Schránky', url: admin_tenant_boxes_path(Current.tenant), icon: Icons::BoxesComponent.new), TW::SidebarMenuItemComponent.new(name: 'Skupiny', url: admin_tenant_groups_path(Current.tenant), icon: Icons::GroupsComponent.new), TW::SidebarMenuItemComponent.new(name: 'Štítky', url: admin_tenant_tags_path(Current.tenant), icon: Icons::TagsComponent.new), + Layout::SidebarDividerComponent.new(), + TW::SidebarMenuDividerComponent.new(name: 'Admin'), TW::SidebarMenuItemComponent.new(name: 'Good Job Dashboard', url: good_job_path, icon: Icons::GoodJobComponent.new), - ] + ].compact end def default_message_thread_menu - [Layout::BackToBoxComponent.new, Layout::MessageThreadSidebarComponent.new(message: @parameters[:message])] if @parameters && @parameters[:message] + [Layout::BackToBoxComponent.new, Layout::SidebarDividerComponent.new, Layout::MessageThreadSidebarComponent.new(message: @parameters[:message])] if @parameters && @parameters[:message] end end diff --git a/app/models/box.rb b/app/models/box.rb index bf6c09b44..eaf02793c 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -16,5 +16,30 @@ class Box < ApplicationRecord has_many :folders has_many :message_threads, through: :folders, extend: MessageThreadsExtensions has_many :message_drafts_imports -end + enum :color, + { + slate: 'slate', + gray: 'gray', + zinc: 'zinc', + neutral: 'neutral', + stone: 'stone', + red: 'red', + orange: 'orange', + amber: 'amber', + yellow: 'yellow', + lime: 'lime', + green: 'green', + emerald: 'emerald', + teal: 'teal', + cyan: 'cyan', + sky: 'sky', + blue: 'blue', + indigo: 'indigo', + violet: 'violet', + purple: 'purple', + fuchsia: 'fuchsia', + pink: 'pink', + rose: 'rose', + } +end diff --git a/app/models/govbox/message.rb b/app/models/govbox/message.rb index 824ec0971..b90e0e39f 100644 --- a/app/models/govbox/message.rb +++ b/app/models/govbox/message.rb @@ -104,6 +104,7 @@ def self.create_message_tag(message, govbox_message) tag = Tag.find_or_create_by!( name: "slovensko.sk:#{govbox_message.folder.full_name}", tenant: govbox_message.box.tenant, + external: true, visible: !govbox_message.folder.system? ) diff --git a/app/policies/admin/group_policy.rb b/app/policies/admin/group_policy.rb index 73b73b047..665d76109 100644 --- a/app/policies/admin/group_policy.rb +++ b/app/policies/admin/group_policy.rb @@ -46,6 +46,10 @@ def edit_members? update? end + def edit_permissions? + update? + end + def destroy? @user.site_admin? || @user.admin? end @@ -54,4 +58,8 @@ def search_non_members? @user.site_admin? || @user.admin? end + def search_non_tags? + @user.site_admin? || @user.admin? + end + end diff --git a/app/policies/admin/tag_group_policy.rb b/app/policies/admin/tag_group_policy.rb index 215b8a12c..b17405123 100644 --- a/app/policies/admin/tag_group_policy.rb +++ b/app/policies/admin/tag_group_policy.rb @@ -18,7 +18,7 @@ def resolve end end - def index + def index? @user.site_admin? || @user.admin? end diff --git a/app/policies/admin/tag_policy.rb b/app/policies/admin/tag_policy.rb index fa70bced6..bb176c700 100644 --- a/app/policies/admin/tag_policy.rb +++ b/app/policies/admin/tag_policy.rb @@ -38,6 +38,10 @@ def edit? update? end + def visibility_toggle? + update? + end + def destroy? @user.site_admin? || @user.admin? end diff --git a/app/views/admin/boxes/edit.html.erb b/app/views/admin/boxes/edit.html.erb index c967a4a99..8cff92d70 100644 --- a/app/views/admin/boxes/edit.html.erb +++ b/app/views/admin/boxes/edit.html.erb @@ -1,6 +1 @@ -
-

Editing box

- <%= render "form", box: @box %> - <%= link_to "Show this box", admin_tenant_box_path(Current.tenant, @box), class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> - <%= link_to "Back to tenant", admin_tenant_path(Current.tenant), class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
+<%= render Admin::Boxes::BoxFormComponent.new(box: @box, action: :edit) %> diff --git a/app/views/admin/boxes/index.html.erb b/app/views/admin/boxes/index.html.erb index 754c94b89..3dac44f9c 100644 --- a/app/views/admin/boxes/index.html.erb +++ b/app/views/admin/boxes/index.html.erb @@ -1,13 +1 @@ -
- <% if notice.present? %> -

<%= notice %>

- <% end %> -
-

Boxes

- <%= link_to 'New box', new_admin_box_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> -
-
- <%= render @boxes %> -
-
+<%= render Admin::Boxes::BoxesListComponent.new(@boxes) %> diff --git a/app/views/admin/boxes/new.html.erb b/app/views/admin/boxes/new.html.erb index e00de502d..5285c2fcc 100644 --- a/app/views/admin/boxes/new.html.erb +++ b/app/views/admin/boxes/new.html.erb @@ -1,5 +1 @@ -
-

New box

- <%= render "form", box: @box %> - <%= link_to 'Back to tenant', admin_tenant_path(Current.tenant), class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
+<%= render Admin::Boxes::BoxFormComponent.new(box: @box, action: :new) %> diff --git a/app/views/admin/group_memberships/create.html.erb b/app/views/admin/group_memberships/create.html.erb new file mode 100644 index 000000000..a0e330280 --- /dev/null +++ b/app/views/admin/group_memberships/create.html.erb @@ -0,0 +1 @@ +<%= render Admin::Groups::GroupFormComponent.new(group: @group, action: :new)%> diff --git a/app/views/admin/group_memberships/create.turbo_stream.erb b/app/views/admin/group_memberships/create.turbo_stream.erb deleted file mode 100644 index d55113fc6..000000000 --- a/app/views/admin/group_memberships/create.turbo_stream.erb +++ /dev/null @@ -1,4 +0,0 @@ -<%# TODO: Toto sa mi nepodarilo vyriesit standartnym redirectom, len takymto hackom. Nahodou nejake napady? Problem je, ze create sa vola z ineho turbo framu, z ktoreho neviem inak uniknut %> -<%= turbo_stream.update 'modal' do %> - <%= render Admin::Groups::GroupFormComponent.new(group: @group, step: :new)%> -<% end %> diff --git a/app/views/admin/groups/edit_permissions.html.erb b/app/views/admin/groups/edit_permissions.html.erb new file mode 100644 index 000000000..bf0cbe7ae --- /dev/null +++ b/app/views/admin/groups/edit_permissions.html.erb @@ -0,0 +1 @@ +<%= render Admin::Permissions::GroupFormComponent.new(group: @group) %> diff --git a/app/views/admin/groups/search_non_tags.turbo_stream.erb b/app/views/admin/groups/search_non_tags.turbo_stream.erb new file mode 100644 index 000000000..4d135ed1f --- /dev/null +++ b/app/views/admin/groups/search_non_tags.turbo_stream.erb @@ -0,0 +1,5 @@ +<%= turbo_stream.update 'tag-search-results' do %> + <% if !params[:name_search].empty? %> + <%= render Admin::Permissions::PermissionsAddPopupComponent.new(tags: @tags, group: @group) %> + <% end %> +<% end %> diff --git a/app/views/admin/tag_groups/index.html.erb b/app/views/admin/tag_groups/index.html.erb new file mode 100644 index 000000000..54a19255e --- /dev/null +++ b/app/views/admin/tag_groups/index.html.erb @@ -0,0 +1 @@ +<%= render Admin::Permissions::GroupsListComponent.new(@groups) %> diff --git a/app/views/admin/tags/edit.html.erb b/app/views/admin/tags/edit.html.erb index 2e88ede92..18d320002 100644 --- a/app/views/admin/tags/edit.html.erb +++ b/app/views/admin/tags/edit.html.erb @@ -1,6 +1 @@ -
-

Editing tag

- <%= render "form", tag: @tag %> - <%= link_to "Show this tag", admin_tenant_tag_path(Current.tenant, @tag), class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> - <%= link_to "Back to tenant", admin_tenant_path(Current.tenant), class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
+<%= render Admin::Tags::TagFormComponent.new(tag: @tag, action: :edit) %> diff --git a/app/views/admin/tags/index.html.erb b/app/views/admin/tags/index.html.erb index 3c61c751f..3f6708b2f 100644 --- a/app/views/admin/tags/index.html.erb +++ b/app/views/admin/tags/index.html.erb @@ -1,13 +1 @@ -
- <% if notice.present? %> -

<%= notice %>

- <% end %> -
-

Tags

- <%= link_to 'New tag', new_admin_tenant_tag_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> -
-
- <%= render @tags %> -
-
+<%= render Admin::Tags::TagsListComponent.new(@tags) %> diff --git a/app/views/admin/tags/new.html.erb b/app/views/admin/tags/new.html.erb index d428803d8..eda4f5ee3 100644 --- a/app/views/admin/tags/new.html.erb +++ b/app/views/admin/tags/new.html.erb @@ -1,5 +1 @@ -
-

New tag

- <%= render "form", tag: @tag %> - <%= link_to 'Back to tenant', admin_tenant_path(Current.tenant), class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
+<%= render Admin::Tags::TagFormComponent.new(tag: @tag, action: :new) %> diff --git a/app/views/admin/tags/visibility_toggle.html.erb b/app/views/admin/tags/visibility_toggle.html.erb new file mode 100644 index 000000000..bce935c2b --- /dev/null +++ b/app/views/admin/tags/visibility_toggle.html.erb @@ -0,0 +1 @@ +<%= render Admin::Tags::VisibilityToggleComponent.new(@tag) %> diff --git a/app/views/admin/tenants/edit.html.erb b/app/views/admin/tenants/edit.html.erb index 520cef89d..2d31254c0 100644 --- a/app/views/admin/tenants/edit.html.erb +++ b/app/views/admin/tenants/edit.html.erb @@ -1,6 +1 @@ -
-

Editing tenant

- <%= render "form", tenant: @tenant %> - <%= link_to "Show this tenant", [:admin, @tenant], class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> - <%= link_to "Back to tenants", admin_tenants_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
+<%= render Admin::Tenants::TenantFormComponent.new(tenant: @tenant, action: :edit) %> diff --git a/app/views/admin/tenants/index.html.erb b/app/views/admin/tenants/index.html.erb index 4005ba346..432a180e3 100644 --- a/app/views/admin/tenants/index.html.erb +++ b/app/views/admin/tenants/index.html.erb @@ -1,12 +1 @@ -
- <% if notice.present? %> -

<%= notice %>

- <% end %> -
-

Tenants

- <%= link_to 'New tenant', new_admin_tenant_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %> -
-
- <%= render @tenants %> -
-
+<%= render Admin::Tenants::TenantsListComponent.new(@tenants) %> diff --git a/app/views/admin/tenants/new.html.erb b/app/views/admin/tenants/new.html.erb index 70cf94ee3..e4989ae8f 100644 --- a/app/views/admin/tenants/new.html.erb +++ b/app/views/admin/tenants/new.html.erb @@ -1,5 +1 @@ -
-

New tenant

- <%= render "form", tenant: @tenant %> - <%= link_to 'Back to tenants', admin_tenants_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -
+<%= render Admin::Tenants::TenantFormComponent.new(tenant: @tenant, action: :new) %> diff --git a/app/views/admin/users/edit.html.erb b/app/views/admin/users/edit.html.erb index 3de486c10..0b419cf11 100644 --- a/app/views/admin/users/edit.html.erb +++ b/app/views/admin/users/edit.html.erb @@ -1 +1 @@ -<%= render Admin::Users::UserFormComponent.new(@user) %> +<%= render Admin::Users::UserFormComponent.new(user: @user, action: :edit) %> diff --git a/app/views/admin/users/new.html.erb b/app/views/admin/users/new.html.erb index 3de486c10..65170352e 100644 --- a/app/views/admin/users/new.html.erb +++ b/app/views/admin/users/new.html.erb @@ -1 +1 @@ -<%= render Admin::Users::UserFormComponent.new(@user) %> +<%= render Admin::Users::UserFormComponent.new(user: @user, action: :new) %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 915bb66e2..99bd1fe38 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -22,5 +22,6 @@ <% end %> <% end %> <%= turbo_frame_tag :modal %> + <%= turbo_frame_tag :login_screen %> diff --git a/app/views/sessions/login.html.erb b/app/views/sessions/login.html.erb index 46cbf8b15..5f33a2b1f 100644 --- a/app/views/sessions/login.html.erb +++ b/app/views/sessions/login.html.erb @@ -1,4 +1,14 @@ <% unless Current.user %> -

<%= button_to "Sign in with Google", "/auth/google_oauth2", method: :post, data: { turbo: false }, class: "rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600" %>

+ <%= turbo_stream.replace "login_screen" do %> + + <% end %> <% end %> diff --git a/config/routes.rb b/config/routes.rb index 0e85a5e93..c5c4720cb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,4 @@ Rails.application.routes.draw do - - namespace :settings do resources :automation_rules resource :automation_rule do @@ -25,18 +23,18 @@ resources :tenants do resources :groups do get :edit_members, on: :member + get :edit_permissions, on: :member post :search_non_members, on: :member + post :search_non_tags, on: :member resources :group_memberships, param: :index end resources :users resources :boxes - resources :tags + resources :tags do + patch :visibility_toggle, on: :member + end + resources :tag_groups end - - resources :group_memberships - resources :tag_users - - resources :tag_groups, only: [:create, :destroy] end resources :boxes, path: 'schranky', only: [:index, :show] do diff --git a/db/migrate/20230912140348_add_short_name_to_boxes.rb b/db/migrate/20230912140348_add_short_name_to_boxes.rb new file mode 100644 index 000000000..018371d16 --- /dev/null +++ b/db/migrate/20230912140348_add_short_name_to_boxes.rb @@ -0,0 +1,6 @@ +class AddShortNameToBoxes < ActiveRecord::Migration[7.0] + def change + add_column :boxes, :short_name, :string + add_index :boxes, %i[tenant_id short_name], unique: true + end +end diff --git a/db/migrate/20230912140629_add_color_to_boxes.rb b/db/migrate/20230912140629_add_color_to_boxes.rb new file mode 100644 index 000000000..8b34cee23 --- /dev/null +++ b/db/migrate/20230912140629_add_color_to_boxes.rb @@ -0,0 +1,12 @@ +class AddColorToBoxes < ActiveRecord::Migration[7.0] + def change + create_enum :color, %w[slate gray zinc neutral stone red orange amber yellow lime green emerald teal cyan sky blue indigo violet purple fuchsia pink rose] + change_table :boxes do |t| + t.enum :color, enum_type: 'color' + end + Box.all.each do |box| + box.color = Box.colors.keys[Digest::MD5.hexdigest(@box.name).to_i(16) % Box.colors.size] + box.short_name = box.name[0] + end + end +end diff --git a/db/migrate/20230914151243_add_external_to_tags.rb b/db/migrate/20230914151243_add_external_to_tags.rb new file mode 100644 index 000000000..4c6edfc71 --- /dev/null +++ b/db/migrate/20230914151243_add_external_to_tags.rb @@ -0,0 +1,9 @@ +class AddExternalToTags < ActiveRecord::Migration[7.0] + def change + add_column :tags, :external, :boolean, default: false + Tag.all.each do |tag| + tag.external = (tag.name.match? '^slovensko.sk') + tag.save + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 8689d4c89..0b0420a73 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_09_11_071311) do +ActiveRecord::Schema[7.0].define(version: 2023_09_14_151243) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" enable_extension "plpgsql" @@ -18,6 +18,7 @@ # Custom types defined in this database. # Note that some types may not work with other database engines. Be careful if changing database. + create_enum "color", ["slate", "gray", "zinc", "neutral", "stone", "red", "orange", "amber", "yellow", "lime", "green", "emerald", "teal", "cyan", "sky", "blue", "indigo", "violet", "purple", "fuchsia", "pink", "rose"] create_enum "group_type", ["ALL", "USER", "CUSTOM", "ADMIN"] create_table "active_storage_attachments", force: :cascade do |t| @@ -85,7 +86,9 @@ t.datetime "updated_at", null: false t.bigint "tenant_id", null: false t.boolean "syncable", default: true, null: false - t.boolean "syncable", default: true, null: false + t.string "short_name" + t.enum "color", enum_type: "color" + t.index ["tenant_id", "short_name"], name: "index_boxes_on_tenant_id_and_short_name", unique: true t.index ["tenant_id"], name: "index_boxes_on_tenant_id" end @@ -237,16 +240,6 @@ t.index ["box_id"], name: "index_message_drafts_imports_on_box_id" end - create_table "message_drafts_imports", force: :cascade do |t| - t.string "name", null: false - t.integer "status", default: 0 - t.string "content_path" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.bigint "box_id", null: false - t.index ["box_id"], name: "index_message_drafts_imports_on_box_id" - end - create_table "message_object_data", force: :cascade do |t| t.bigint "message_object_id", null: false t.binary "blob", null: false @@ -264,7 +257,6 @@ t.datetime "updated_at", null: false t.boolean "is_signed" t.boolean "to_be_signed", default: false, null: false - t.boolean "to_be_signed", default: false, null: false t.index ["message_id"], name: "index_message_objects_on_message_id" end @@ -317,10 +309,6 @@ t.bigint "author_id" t.index ["author_id"], name: "index_messages_on_author_id" t.index ["import_id"], name: "index_messages_on_import_id" - t.bigint "import_id" - t.bigint "author_id" - t.index ["author_id"], name: "index_messages_on_author_id" - t.index ["import_id"], name: "index_messages_on_import_id" t.index ["message_thread_id"], name: "index_messages_on_message_thread_id" end @@ -342,15 +330,6 @@ t.index ["tag_id"], name: "index_tag_groups_on_tag_id" end - create_table "tag_groups", force: :cascade do |t| - t.bigint "group_id", null: false - t.bigint "tag_id", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["group_id"], name: "index_tag_groups_on_group_id" - t.index ["tag_id"], name: "index_tag_groups_on_tag_id" - end - create_table "tag_users", force: :cascade do |t| t.bigint "user_id", null: false t.bigint "tag_id", null: false @@ -367,6 +346,7 @@ t.datetime "updated_at", null: false t.boolean "visible", default: true, null: false t.bigint "user_id" + t.boolean "external", default: false t.index ["tenant_id"], name: "index_tags_on_tenant_id" t.index ["user_id"], name: "index_tags_on_user_id" end @@ -396,25 +376,6 @@ t.index ["identifier", "version"], name: "index_form_templates_on_identifier_and_version", unique: true end - create_table "upvs_form_template_related_documents", force: :cascade do |t| - t.bigint "upvs_form_template_id", null: false - t.string "data", null: false - t.string "language", null: false - t.string "document_type", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["upvs_form_template_id", "language", "document_type"], name: "index_related_documents_on_template_id_and_language_and_type", unique: true - t.index ["upvs_form_template_id"], name: "index_upvs_form_template_related_documents_on_form_template_id" - end - - create_table "upvs_form_templates", force: :cascade do |t| - t.string "identifier", null: false - t.string "version", null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.index ["identifier", "version"], name: "index_form_templates_on_identifier_and_version", unique: true - end - create_table "users", force: :cascade do |t| t.bigint "tenant_id" t.string "email", null: false @@ -440,7 +401,6 @@ add_foreign_key "group_memberships", "users" add_foreign_key "groups", "tenants" add_foreign_key "message_drafts_imports", "boxes" - add_foreign_key "message_drafts_imports", "boxes" add_foreign_key "message_object_data", "message_objects" add_foreign_key "message_objects", "messages" add_foreign_key "message_thread_merge_identifiers", "message_threads" @@ -448,21 +408,16 @@ add_foreign_key "message_threads_tags", "message_threads" add_foreign_key "message_threads_tags", "tags" add_foreign_key "messages", "message_drafts_imports", column: "import_id" - add_foreign_key "messages", "message_drafts_imports", column: "import_id" add_foreign_key "messages", "message_threads" add_foreign_key "messages", "users", column: "author_id" - add_foreign_key "messages", "users", column: "author_id" add_foreign_key "messages_tags", "messages" add_foreign_key "messages_tags", "tags" add_foreign_key "tag_groups", "groups" add_foreign_key "tag_groups", "tags" - add_foreign_key "tag_groups", "groups" - add_foreign_key "tag_groups", "tags" add_foreign_key "tag_users", "tags" add_foreign_key "tag_users", "users" add_foreign_key "tags", "tenants" add_foreign_key "tags", "users" add_foreign_key "upvs_form_template_related_documents", "upvs_form_templates" - add_foreign_key "upvs_form_template_related_documents", "upvs_form_templates" add_foreign_key "users", "tenants" end From 7435df5263c2dcee97509be2a8c4ef2010b07fc3 Mon Sep 17 00:00:00 2001 From: stage-rl Date: Mon, 18 Sep 2023 18:23:35 +0200 Subject: [PATCH 03/21] Fix seeds and fixtures for changed entities --- db/seeds.rb | 2 +- test/fixtures/boxes.yml | 3 ++- test/fixtures/tags.yml | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/db/seeds.rb b/db/seeds.rb index af667b85a..d94f1542a 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -8,7 +8,7 @@ tenant.users.find_or_create_by!(email: email, name: "Site ADMIN User #{i}") end -box = tenant.boxes.find_or_create_by!(name: "Dev box", uri: "ico://sk/83300252") +box = tenant.boxes.find_or_create_by!(name: "Dev box", uri: "ico://sk/83300252", short_name: 'DEV') Govbox::ApiConnection.find_or_create_by!(sub: "SPL_Irvin_83300252_KK_24022023", box: box, api_token_private_key: File.read(Rails.root + "security/govbox_api_fix.pem")) tenant.tags.find_or_create_by!(name: 'NASES', user_id: tenant.users.first.id) diff --git a/test/fixtures/boxes.yml b/test/fixtures/boxes.yml index 3e16aab1c..fdd42f777 100644 --- a/test/fixtures/boxes.yml +++ b/test/fixtures/boxes.yml @@ -4,9 +4,10 @@ one: name: MyString uri: MyString tenant: solver + short_name: MY1 two: name: MyString uri: MyString tenant: solver - + short_name: MY2 diff --git a/test/fixtures/tags.yml b/test/fixtures/tags.yml index 4c7fa5cfe..b96d7727f 100644 --- a/test/fixtures/tags.yml +++ b/test/fixtures/tags.yml @@ -2,10 +2,12 @@ one: name: MyString + external: false visible: true tenant: solver two: name: MyString + external: false visible: false tenant: solver From 2259084754f41146b75441b192632aacfae4e9bf Mon Sep 17 00:00:00 2001 From: stage-rl Date: Mon, 18 Sep 2023 18:34:15 +0200 Subject: [PATCH 04/21] Fix test with new entity attributes --- test/models/govbox/message_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/models/govbox/message_test.rb b/test/models/govbox/message_test.rb index 3ff20fd16..16de9f86d 100644 --- a/test/models/govbox/message_test.rb +++ b/test/models/govbox/message_test.rb @@ -24,6 +24,7 @@ class Govbox::MessageTest < ActiveSupport::TestCase assert_equal message.tags.count, 1 assert_equal message.tags.first.name, "slovensko.sk:#{govbox_message.folder.name}" assert_equal message.tags.first.visible, false + assert_equal message.tags.first.external, true assert_equal message.thread.tags.count, 1 assert_equal message.tags.first, message.thread.tags.first end @@ -41,7 +42,7 @@ class Govbox::MessageTest < ActiveSupport::TestCase test "should not create new tag if already exists" do govbox_message = govbox_messages(:one) - tag = Tag.create!(name: "slovensko.sk:#{govbox_message.folder.name}", tenant: govbox_message.folder.box.tenant, visible: false) + tag = Tag.create!(name: "slovensko.sk:#{govbox_message.folder.name}", tenant: govbox_message.folder.box.tenant, visible: false, external: true) Govbox::Message.create_message_with_thread!(govbox_message) @@ -57,7 +58,7 @@ class Govbox::MessageTest < ActiveSupport::TestCase govbox_message1 = govbox_messages(:one) govbox_message2 = govbox_messages(:three) - tag = Tag.create!(name: "slovensko.sk:#{govbox_message1.folder.name}", tenant: govbox_message1.folder.box.tenant, visible: false) + tag = Tag.create!(name: "slovensko.sk:#{govbox_message1.folder.name}", tenant: govbox_message1.folder.box.tenant, visible: false, external: true) Govbox::Message.create_message_with_thread!(govbox_message1) message1 = Message.last From 13679bf087570900a4760523b6aae2b5567b3785 Mon Sep 17 00:00:00 2001 From: stage-rl Date: Mon, 18 Sep 2023 19:50:31 +0200 Subject: [PATCH 05/21] Fixes based on manual tests --- .../permissions/permissions_list_row_component.html.erb | 2 +- app/components/common/tag_selector_popup_component.rb | 6 +++++- app/models/box.rb | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/components/admin/permissions/permissions_list_row_component.html.erb b/app/components/admin/permissions/permissions_list_row_component.html.erb index c7c339d1b..a6e69a08e 100644 --- a/app/components/admin/permissions/permissions_list_row_component.html.erb +++ b/app/components/admin/permissions/permissions_list_row_component.html.erb @@ -1,4 +1,4 @@ <%= render Admin::Permissions::TagComponent.new(@tag_group.tag) %> -<%= button_to admin_tag_group_path(@tag_group), method: :delete do %> +<%= button_to admin_tenant_tag_group_path(Current.tenant, @tag_group), method: :delete do %> <%= render Common::DeleteButtonComponent.new %> <% end %> diff --git a/app/components/common/tag_selector_popup_component.rb b/app/components/common/tag_selector_popup_component.rb index 62191f3ad..0c1e53440 100644 --- a/app/components/common/tag_selector_popup_component.rb +++ b/app/components/common/tag_selector_popup_component.rb @@ -2,7 +2,11 @@ module Common class TagSelectorPopupComponent < ViewComponent::Base def initialize(object) @object = object - @tags = policy_scope(Tag).where.not(id: object.tags.ids).where(visible: true) + # TODO: Toto bude treba tiez prestahovat niekam inam. Len je to zas hlboko + @tags = Current.tenant.tags.where.not(id: object.tags.ids).where(visible: true) + .where(id: TagGroup.select(:tag_id).joins(:group, :tag, group: :users) + .where(group: { tenant_id: Current.tenant.id }, tag: { tenant_id: Current.tenant.id }, users: { id: Current.user.id }) + ) end end end diff --git a/app/models/box.rb b/app/models/box.rb index eaf02793c..39597e12f 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -17,6 +17,8 @@ class Box < ApplicationRecord has_many :message_threads, through: :folders, extend: MessageThreadsExtensions has_many :message_drafts_imports + before_create { self.color = Box.colors.keys[Digest::MD5.hexdigest(name).to_i(16) % Box.colors.size] if color.blank? } + enum :color, { slate: 'slate', @@ -40,6 +42,6 @@ class Box < ApplicationRecord purple: 'purple', fuchsia: 'fuchsia', pink: 'pink', - rose: 'rose', + rose: 'rose' } end From 15d1074534484e7ae019f51f39c555ee4ce1d1d0 Mon Sep 17 00:00:00 2001 From: stage-rl Date: Tue, 19 Sep 2023 07:09:01 +0200 Subject: [PATCH 06/21] Move available tags logic from TagSelectorComponent to controllers --- .../common/tag_selector_component.html.erb | 2 +- app/components/common/tag_selector_component.rb | 3 ++- .../common/tag_selector_popup_component.rb | 8 ++------ app/components/message_component.html.erb | 4 ++-- app/components/message_component.rb | 3 ++- .../message_thread_header_component.html.erb | 2 +- app/components/message_thread_header_component.rb | 3 ++- app/controllers/messages_controller.rb | 13 ++++++++++++- app/views/messages/show.html.erb | 2 +- 9 files changed, 25 insertions(+), 15 deletions(-) diff --git a/app/components/common/tag_selector_component.html.erb b/app/components/common/tag_selector_component.html.erb index 464ed477a..ba97dd215 100644 --- a/app/components/common/tag_selector_component.html.erb +++ b/app/components/common/tag_selector_component.html.erb @@ -18,6 +18,6 @@
diff --git a/app/components/common/tag_selector_component.rb b/app/components/common/tag_selector_component.rb index 87ce3c457..56e9ff734 100644 --- a/app/components/common/tag_selector_component.rb +++ b/app/components/common/tag_selector_component.rb @@ -1,7 +1,8 @@ module Common class TagSelectorComponent < ViewComponent::Base - def initialize(object) + def initialize(object, available_tags) @object = object + @available_tags = available_tags end end end diff --git a/app/components/common/tag_selector_popup_component.rb b/app/components/common/tag_selector_popup_component.rb index 0c1e53440..24ad5ca82 100644 --- a/app/components/common/tag_selector_popup_component.rb +++ b/app/components/common/tag_selector_popup_component.rb @@ -1,12 +1,8 @@ module Common class TagSelectorPopupComponent < ViewComponent::Base - def initialize(object) + def initialize(object, available_tags) @object = object - # TODO: Toto bude treba tiez prestahovat niekam inam. Len je to zas hlboko - @tags = Current.tenant.tags.where.not(id: object.tags.ids).where(visible: true) - .where(id: TagGroup.select(:tag_id).joins(:group, :tag, group: :users) - .where(group: { tenant_id: Current.tenant.id }, tag: { tenant_id: Current.tenant.id }, users: { id: Current.user.id }) - ) + @tags = available_tags end end end diff --git a/app/components/message_component.html.erb b/app/components/message_component.html.erb index de5b8f464..0db409fd6 100644 --- a/app/components/message_component.html.erb +++ b/app/components/message_component.html.erb @@ -1,5 +1,5 @@
- <%= render MessageThreadHeaderComponent.new(@message.thread) %> + <%= render MessageThreadHeaderComponent.new(@message.thread, @available_tags) %>
<% if @notice %> <% end %> <% end %> - <%= render Common::TagSelectorComponent.new(@message) %> + <%= render Common::TagSelectorComponent.new(@message, @available_tags) %>
diff --git a/app/components/message_component.rb b/app/components/message_component.rb index e13834d88..ac35364c2 100644 --- a/app/components/message_component.rb +++ b/app/components/message_component.rb @@ -1,8 +1,9 @@ class MessageComponent < ViewComponent::Base renders_many :attachments - def initialize(message:, notice:) + def initialize(message:, notice:, available_tags:) @message = message @notice = notice + @available_tags = available_tags end end diff --git a/app/components/message_thread_header_component.html.erb b/app/components/message_thread_header_component.html.erb index 7bcfc526e..9b81614a2 100644 --- a/app/components/message_thread_header_component.html.erb +++ b/app/components/message_thread_header_component.html.erb @@ -14,7 +14,7 @@
<% end %> <% end %> - <%= render Common::TagSelectorComponent.new(@message_thread) %> + <%= render Common::TagSelectorComponent.new(@message_thread, @available_tags) %>
diff --git a/app/components/message_thread_header_component.rb b/app/components/message_thread_header_component.rb index c1bb566f6..e5190d872 100644 --- a/app/components/message_thread_header_component.rb +++ b/app/components/message_thread_header_component.rb @@ -1,5 +1,6 @@ class MessageThreadHeaderComponent < ViewComponent::Base - def initialize(message_thread) + def initialize(message_thread, available_tags) @message_thread = message_thread + @available_tags = available_tags end end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index b61a46cf0..1e8582f57 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -6,6 +6,7 @@ def show @message.update(read: true) @message_thread = @message.thread + @available_tags = available_tags @notice = notice end @@ -16,7 +17,7 @@ def authorize_delivery_notification notice = Message.authorize_delivery_notification(@message) ? "Správa bola zaradená na prevzatie." : "Správu nie je možné prevziať." redirect_to message_path(@message), notice: notice end - + private def set_message @@ -27,4 +28,14 @@ def set_message def permit_reply_params params.permit(:reply_title, :reply_text) end + + def available_tags + @tenant = @message.tenant + @tenant.tags.where.not(id: @message.tags.ids).where(visible: true) + .where( + id: TagGroup.select(:tag_id) + .joins(:group, :tag, group: :users) + .where(group: { tenant_id: @tenant.id }, tag: { tenant_id: @tenant.id }, users: { id: Current.user.id }) + ) + end end diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index a04952616..851ce633d 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -1,5 +1,5 @@ <%= render TW::FlashComponent.new(flash: flash) %> -<%= render MessageComponent.new(message: @message, notice: @notice) do |component| %> +<%= render MessageComponent.new(message: @message, notice: @notice, available_tags: @available_tags) do |component| %> <% @message.objects.each do |message_object| %> <% component.with_attachment do %> <% render MessageAttachmentComponent.new(message_attachment: message_object) %> From 0a1c4006dd2afe44dbfa7d49f2513d2b27543c9b Mon Sep 17 00:00:00 2001 From: stage-rl Date: Tue, 19 Sep 2023 08:41:06 +0200 Subject: [PATCH 07/21] Static use of tailwind colors to generate proper CSS for dynamic box colors --- app/views/boxes/show.html.erb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/app/views/boxes/show.html.erb b/app/views/boxes/show.html.erb index 522361940..36d1a7a22 100644 --- a/app/views/boxes/show.html.erb +++ b/app/views/boxes/show.html.erb @@ -1,5 +1,29 @@

Schránka <%= @box.name %>

- <%= form_tag box_sync_path(@box), method: :post do %> <%= submit_tag 'Stiahnúť nové správy' %> <% end %> +
+
+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+

Paleta - kvoli pregenerovaniu CSS

+
From 870637402143e15c7d16afd9b9cda57300447f44 Mon Sep 17 00:00:00 2001 From: stage-rl Date: Tue, 19 Sep 2023 09:56:15 +0200 Subject: [PATCH 08/21] Move color palette generation for boxes to Box displaying component --- .../boxes/boxes_list_row_component.html.erb | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/components/admin/boxes/boxes_list_row_component.html.erb b/app/components/admin/boxes/boxes_list_row_component.html.erb index 385005ce3..89c9c5205 100644 --- a/app/components/admin/boxes/boxes_list_row_component.html.erb +++ b/app/components/admin/boxes/boxes_list_row_component.html.erb @@ -21,3 +21,28 @@ <% end %>
+ + + + + + + + + + + + + + + + + + + + + + + + + From 9c70bc9c647c12619c704cd90c6c477a3cf77cdb Mon Sep 17 00:00:00 2001 From: stage-rl Date: Tue, 19 Sep 2023 10:10:30 +0200 Subject: [PATCH 09/21] Move color palette generation for boxes to helper --- app/helpers/box_tailwind_color_helper.rb | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 app/helpers/box_tailwind_color_helper.rb diff --git a/app/helpers/box_tailwind_color_helper.rb b/app/helpers/box_tailwind_color_helper.rb new file mode 100644 index 000000000..aafe04631 --- /dev/null +++ b/app/helpers/box_tailwind_color_helper.rb @@ -0,0 +1,27 @@ +module BoxTailwindColorHelper +end +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# Necessary to generate proper CSS for dynamically generated colors +# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +# class="bg-slate-100 border border-slate-400 text-slate-600" +# class="bg-gray-100 border border-gray-400 text-gray-600" +# class="bg-zinc-100 border border-zinc-400 text-zinc-600" +# class="bg-neutral-100 border border-neutral-400 text-neutral-600" +# class="bg-stone-100 border border-stone-400 text-stone-600" +# class="bg-red-100 border border-red-400 text-red-600" +# class="bg-orange-100 border border-orange-400 text-orange-600" +# class="bg-amber-100 border border-amber-400 text-amber-600" +# class="bg-yellow-100 border border-yellow-400 text-yellow-600" +# class="bg-lime-100 border border-lime-400 text-lime-600" +# class="bg-green-100 border border-green-400 text-green-600" +# class="bg-emerald-100 border border-emerald-400 text-emerald-600" +# class="bg-teal-100 border border-teal-400 text-teal-600" +# class="bg-cyan-100 border border-cyan-400 text-cyan-600" +# class="bg-sky-100 border border-sky-400 text-sky-600" +# class="bg-blue-100 border border-blue-400 text-blue-600" +# class="bg-indigo-100 border border-indigo-400 text-indigo-600" +# class="bg-violet-100 border border-violet-400 text-violet-600" +# class="bg-purple-100 border border-purple-400 text-purple-600" +# class="bg-fuchsia-100 border border-fuchsia-400 text-fuchsia-600" +# class="bg-pink-100 border border-pink-400 text-pink-600" +# class="bg-rose-100 border border-rose-400 text-rose-600" \ No newline at end of file From 8a0e862dbcc32af38800cd6b858168a7b938b0e4 Mon Sep 17 00:00:00 2001 From: stage-rl Date: Tue, 19 Sep 2023 10:11:35 +0200 Subject: [PATCH 10/21] Minor cleanup --- .../boxes/boxes_list_row_component.html.erb | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/app/components/admin/boxes/boxes_list_row_component.html.erb b/app/components/admin/boxes/boxes_list_row_component.html.erb index 89c9c5205..385005ce3 100644 --- a/app/components/admin/boxes/boxes_list_row_component.html.erb +++ b/app/components/admin/boxes/boxes_list_row_component.html.erb @@ -21,28 +21,3 @@ <% end %> - - - - - - - - - - - - - - - - - - - - - - - - - From 9c3906f535c03dbce0c55ee243bfff1934e03fc1 Mon Sep 17 00:00:00 2001 From: stage-rl Date: Wed, 20 Sep 2023 09:57:37 +0200 Subject: [PATCH 11/21] Fix redirects after box CRUD actions --- app/controllers/admin/boxes_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/boxes_controller.rb b/app/controllers/admin/boxes_controller.rb index 61efae04d..05c5df65b 100644 --- a/app/controllers/admin/boxes_controller.rb +++ b/app/controllers/admin/boxes_controller.rb @@ -26,7 +26,7 @@ def create @box.color = Box.colors.keys[Digest::MD5.hexdigest(@box.name).to_i(16) % Box.colors.size] if @box.save - redirect_to admin_tenant_url(Current.tenant), notice: "Box was successfully created." + redirect_to admin_tenant_boxes_url(Current.tenant), notice: "Box was successfully created." else render :new, status: :unprocessable_entity end @@ -35,7 +35,7 @@ def create def update authorize([:admin, @box]) if @box.update(box_params) - redirect_to admin_tenant_url(Current.tenant), notice: "Box was successfully updated." + redirect_to admin_tenant_boxes_url(Current.tenant), notice: "Box was successfully updated." else render :edit, status: :unprocessable_entity end @@ -44,7 +44,7 @@ def update def destroy authorize([:admin, @box]) @box.destroy - redirect_to admin_tenant_url(Current.tenant), notice: "Box was successfully destroyed." + redirect_to admin_tenant_boxes_url(Current.tenant), notice: "Box was successfully destroyed." end private From 13b9762d6b371da04ff968b54a720c18833d6afd Mon Sep 17 00:00:00 2001 From: stage-rl Date: Thu, 21 Sep 2023 11:51:37 +0200 Subject: [PATCH 12/21] Old admin components cleanup --- .../admin/box_table_row_component.html.erb | 23 ----------------- .../admin/box_table_row_component.rb | 11 -------- ...up_membership_table_row_component.html.erb | 14 ----------- .../group_membership_table_row_component.rb | 10 -------- .../admin/group_table_row_component.html.erb | 25 ------------------- .../admin/group_table_row_component.rb | 11 -------- .../tag_group_table_row_component.html.erb | 12 --------- .../admin/tag_group_table_row_component.rb | 10 -------- .../admin/tag_table_row_component.html.erb | 23 ----------------- .../admin/tag_table_row_component.rb | 11 -------- .../tag_user_table_row_component.html.erb | 12 --------- .../admin/tag_user_table_row_component.rb | 10 -------- .../admin/user_table_row_component.html.erb | 7 ------ .../admin/user_table_row_component.rb | 8 ------ 14 files changed, 187 deletions(-) delete mode 100644 app/components/admin/box_table_row_component.html.erb delete mode 100644 app/components/admin/box_table_row_component.rb delete mode 100644 app/components/admin/group_membership_table_row_component.html.erb delete mode 100644 app/components/admin/group_membership_table_row_component.rb delete mode 100644 app/components/admin/group_table_row_component.html.erb delete mode 100644 app/components/admin/group_table_row_component.rb delete mode 100644 app/components/admin/tag_group_table_row_component.html.erb delete mode 100644 app/components/admin/tag_group_table_row_component.rb delete mode 100644 app/components/admin/tag_table_row_component.html.erb delete mode 100644 app/components/admin/tag_table_row_component.rb delete mode 100644 app/components/admin/tag_user_table_row_component.html.erb delete mode 100644 app/components/admin/tag_user_table_row_component.rb delete mode 100644 app/components/admin/user_table_row_component.html.erb delete mode 100644 app/components/admin/user_table_row_component.rb diff --git a/app/components/admin/box_table_row_component.html.erb b/app/components/admin/box_table_row_component.html.erb deleted file mode 100644 index cb3aab948..000000000 --- a/app/components/admin/box_table_row_component.html.erb +++ /dev/null @@ -1,23 +0,0 @@ - - - <%= link_to @box.name, admin_tenant_box_path(Current.tenant, @box) %> - - - <%= @box.uri %> - - <% - case @box_action - when 'add' %> - - <%= form_with model: [:admin, BoxMembership.new(box: @box, user: @user)], class: "contents" do |form| %> - <%= form.hidden_field :box_id %> - <%= form.hidden_field :user_id %> - <%= form.submit 'Add to box' ,class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> - - <% end %> -<% else %> - - <%= link_to 'Edit this box', edit_admin_tenant_box_path(Current.tenant, @box), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> - -<% end %> - diff --git a/app/components/admin/box_table_row_component.rb b/app/components/admin/box_table_row_component.rb deleted file mode 100644 index 6668cea8b..000000000 --- a/app/components/admin/box_table_row_component.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class Admin::BoxTableRowComponent < ViewComponent::Base - with_collection_parameter :box - - def initialize(box:, user: "", box_action: "") - @box = box - @user = user - @box_action = box_action - end -end diff --git a/app/components/admin/group_membership_table_row_component.html.erb b/app/components/admin/group_membership_table_row_component.html.erb deleted file mode 100644 index dcbc9a204..000000000 --- a/app/components/admin/group_membership_table_row_component.html.erb +++ /dev/null @@ -1,14 +0,0 @@ - - - <%= link_to @group_membership.group.name, admin_tenant_group_path(Current.tenant, @group_membership.group) %> - - - <%= @group_membership.group.group_type %> - - - <% if @group_membership.group_membership_modifiable? %> - <%= button_to 'Remove from group', admin_group_membership_path(@group_membership), - method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium cursor-pointer" %> - <% end %> - - diff --git a/app/components/admin/group_membership_table_row_component.rb b/app/components/admin/group_membership_table_row_component.rb deleted file mode 100644 index 8687b529a..000000000 --- a/app/components/admin/group_membership_table_row_component.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -class Admin::GroupMembershipTableRowComponent < ViewComponent::Base - with_collection_parameter :group_membership - - def initialize(group_membership:) - @group_membership = group_membership - end - -end \ No newline at end of file diff --git a/app/components/admin/group_table_row_component.html.erb b/app/components/admin/group_table_row_component.html.erb deleted file mode 100644 index 29ab61eeb..000000000 --- a/app/components/admin/group_table_row_component.html.erb +++ /dev/null @@ -1,25 +0,0 @@ - - - <%= link_to @group.name, admin_tenant_group_path(Current.tenant, @group) %> - - - <%= @group.group_type %> - - <% - case @group_action - when 'add' %> - <% if @group.is_modifiable? %> - - <%= form_with model: [:admin, GroupMembership.new(group: @group, user: @user)], class: "contents" do |form| %> - <%= form.hidden_field :group_id %> - <%= form.hidden_field :user_id %> - <%= form.submit 'Add to group' ,class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> - <% end %> - - <% end %> -<% else %> - - <%= link_to 'Edit this group', edit_admin_tenant_group_path(Current.tenant, @group), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> - -<% end %> - diff --git a/app/components/admin/group_table_row_component.rb b/app/components/admin/group_table_row_component.rb deleted file mode 100644 index 98d775760..000000000 --- a/app/components/admin/group_table_row_component.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class Admin::GroupTableRowComponent < ViewComponent::Base - with_collection_parameter :group - - def initialize(group:, user: '', group_action: '') - @group = group - @user = user - @group_action = group_action - end -end diff --git a/app/components/admin/tag_group_table_row_component.html.erb b/app/components/admin/tag_group_table_row_component.html.erb deleted file mode 100644 index 25ac5897f..000000000 --- a/app/components/admin/tag_group_table_row_component.html.erb +++ /dev/null @@ -1,12 +0,0 @@ - - - <%= link_to @tag_group.tag.name, admin_tenant_tag_path(Current.tenant, @tag_group.tag) %> - - - <%= @tag_group.tag.visible %> - - - <%= button_to 'Unassign tag', admin_tag_group_path(@tag_group), - method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium cursor-pointer" %> - - diff --git a/app/components/admin/tag_group_table_row_component.rb b/app/components/admin/tag_group_table_row_component.rb deleted file mode 100644 index 51d873708..000000000 --- a/app/components/admin/tag_group_table_row_component.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -class Admin::TagGroupTableRowComponent < ViewComponent::Base - with_collection_parameter :tag_group - - def initialize(tag_group:) - @tag_group = tag_group - end - -end diff --git a/app/components/admin/tag_table_row_component.html.erb b/app/components/admin/tag_table_row_component.html.erb deleted file mode 100644 index ff8997bba..000000000 --- a/app/components/admin/tag_table_row_component.html.erb +++ /dev/null @@ -1,23 +0,0 @@ - - - <%= link_to @tag.name, admin_tenant_tag_path(Current.tenant, @tag) %> - - - <%= @tag.visible %> - - <% - case @tag_action - when 'add' %> - - <%= form_with model: [:admin, TagGroup.new(tag_id: @tag.id, group_id: @group.id)], class: "contents" do |form| %> - <%= form.hidden_field :tag_id %> - <%= form.hidden_field :group_id %> - <%= form.submit 'Assign tag' ,class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %> - <% end %> - -<% else %> - - <%= link_to 'Edit this tag', edit_admin_tenant_tag_path(Current.tenant, @tag), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> - -<% end %> - diff --git a/app/components/admin/tag_table_row_component.rb b/app/components/admin/tag_table_row_component.rb deleted file mode 100644 index 2dddc1de5..000000000 --- a/app/components/admin/tag_table_row_component.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -class Admin::TagTableRowComponent < ViewComponent::Base - with_collection_parameter :tag - - def initialize(tag:, group: "", tag_action: "") - @tag = tag - @group = group - @tag_action = tag_action - end -end diff --git a/app/components/admin/tag_user_table_row_component.html.erb b/app/components/admin/tag_user_table_row_component.html.erb deleted file mode 100644 index b49b47ee7..000000000 --- a/app/components/admin/tag_user_table_row_component.html.erb +++ /dev/null @@ -1,12 +0,0 @@ - - - <%= link_to @tag_user.tag.name, admin_tenant_tag_path(Current.tenant, @tag_user.tag) %> - - - <%= @tag_user.tag.visible %> - - - <%#= button_to 'Unassign tag', admin_tag_user_path(@tag_user), - method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium cursor-pointer" %> - - diff --git a/app/components/admin/tag_user_table_row_component.rb b/app/components/admin/tag_user_table_row_component.rb deleted file mode 100644 index 8c4b44346..000000000 --- a/app/components/admin/tag_user_table_row_component.rb +++ /dev/null @@ -1,10 +0,0 @@ -# frozen_string_literal: true - -class Admin::TagUserTableRowComponent < ViewComponent::Base - with_collection_parameter :tag_user - - def initialize(tag_user:) - @tag_user = tag_user - end - -end \ No newline at end of file diff --git a/app/components/admin/user_table_row_component.html.erb b/app/components/admin/user_table_row_component.html.erb deleted file mode 100644 index 2f191e27f..000000000 --- a/app/components/admin/user_table_row_component.html.erb +++ /dev/null @@ -1,7 +0,0 @@ - - <%= link_to @user.name, admin_tenant_user_path(Current.tenant, @user) %> - <%= @user.email %> - - <%= link_to 'Edit this user', edit_admin_tenant_user_path(Current.tenant, @user), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %> - - diff --git a/app/components/admin/user_table_row_component.rb b/app/components/admin/user_table_row_component.rb deleted file mode 100644 index 306dd04c1..000000000 --- a/app/components/admin/user_table_row_component.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -class Admin::UserTableRowComponent < ViewComponent::Base - with_collection_parameter :user - def initialize(user:) - @user = user - end -end From 391131507af257924e61c8c54b3347f59188a344 Mon Sep 17 00:00:00 2001 From: stage-rl Date: Thu, 21 Sep 2023 12:46:52 +0200 Subject: [PATCH 13/21] Clean-up and fix group admin routes --- .../admin/groups/group_form_component.html.erb | 6 +++--- app/components/admin/groups/group_form_component.rb | 4 ++-- .../admin/groups/groups_list_row_component.html.erb | 4 ++-- .../admin/groups/members_list_row_component.html.erb | 3 +-- app/components/admin/groups/user_add_component.html.erb | 9 ++++----- app/controllers/admin/groups_controller.rb | 6 +++++- app/policies/admin/group_policy.rb | 4 ++++ app/views/admin/group_memberships/create.html.erb | 2 +- app/views/admin/groups/edit_members.html.erb | 3 +-- app/views/admin/groups/show_members.html.erb | 1 + config/routes.rb | 4 +++- 11 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 app/views/admin/groups/show_members.html.erb diff --git a/app/components/admin/groups/group_form_component.html.erb b/app/components/admin/groups/group_form_component.html.erb index ba5a5f261..a13ee8cf4 100644 --- a/app/components/admin/groups/group_form_component.html.erb +++ b/app/components/admin/groups/group_form_component.html.erb @@ -13,7 +13,7 @@ <% end %>
- <% if @action.in? [:new, :edit] %> + <% if !@readonly %> <%= form_with url: search_non_members_admin_tenant_group_path(Current.tenant, @group), class:"flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200" do |form| %>
@@ -29,8 +29,8 @@ <% end %>
<% @group.group_memberships.each do |group_membership| %> -
- <% if @action.in? [:new, :edit] %> +
+ <% if !@readonly %> <%= render Admin::Groups::MembersListRowComponent.new(group_membership) %> <% else %> <%= render Admin::Groups::MembersListRowViewOnlyComponent.new(group_membership) %> diff --git a/app/components/admin/groups/group_form_component.rb b/app/components/admin/groups/group_form_component.rb index 221adc19f..62fb5f33d 100644 --- a/app/components/admin/groups/group_form_component.rb +++ b/app/components/admin/groups/group_form_component.rb @@ -1,6 +1,6 @@ class Admin::Groups::GroupFormComponent < ViewComponent::Base - def initialize(group:, action:) + def initialize(group:, readonly: false) @group = group - @action = action + @readonly = readonly end end diff --git a/app/components/admin/groups/groups_list_row_component.html.erb b/app/components/admin/groups/groups_list_row_component.html.erb index 825705209..1a5bb6fce 100644 --- a/app/components/admin/groups/groups_list_row_component.html.erb +++ b/app/components/admin/groups/groups_list_row_component.html.erb @@ -18,14 +18,14 @@
<% if @group.is_modifiable? %> - <%= link_to edit_members_admin_tenant_group_path(@group.tenant, @group), data: { turbo_frame: :modal } do %> + <%= link_to edit_members_admin_tenant_group_path(@group.tenant, @group) do %> <%= render Common::EditButtonComponent.new %> <% end %> <%= button_to admin_tenant_group_path(@group.tenant, @group), method: :delete do %> <%= render Common::DeleteButtonComponent.new %> <% end %> <% else %> - <%= link_to admin_tenant_group_path(@group.tenant, @group), data: { turbo_frame: :modal } do %> + <%= link_to show_members_admin_tenant_group_path(@group.tenant, @group) do %> <%= render Common::ShowButtonComponent.new %> <% end %> <% end %> diff --git a/app/components/admin/groups/members_list_row_component.html.erb b/app/components/admin/groups/members_list_row_component.html.erb index 96ca57e0e..8f5723a84 100644 --- a/app/components/admin/groups/members_list_row_component.html.erb +++ b/app/components/admin/groups/members_list_row_component.html.erb @@ -1,4 +1,3 @@ -
@@ -6,6 +5,6 @@
<%= @user.name %>
<%= @user.email %>
-<%= button_to admin_group_membership_path(@group_membership), method: :delete do %> +<%= button_to admin_tenant_group_group_membership_path(Current.tenant, @group_membership.group, @group_membership), method: :delete do %> <%= render Common::DeleteButtonComponent.new %> <% end %> diff --git a/app/components/admin/groups/user_add_component.html.erb b/app/components/admin/groups/user_add_component.html.erb index f43df8a2d..5ef208dab 100644 --- a/app/components/admin/groups/user_add_component.html.erb +++ b/app/components/admin/groups/user_add_component.html.erb @@ -6,8 +6,7 @@
<%= @user.name %>
<%= @user.email %>
- <%#= button_to controller: :group_memberships, method: :post, action: :create, group_membership: { group_id: @group.id, user_id: @user.id }, do %> - <%= button_to admin_group_memberships_path(group_membership: { group_id: @group.id, user_id: @user.id }), method: :post, data: { turbo_frame: "modal" } do %> - <%= render Common::AddButtonComponent.new %> - <% end %> -
+ <%= button_to admin_tenant_group_group_memberships_path(Current.tenant, @group, group_membership: { group_id: @group.id, user_id: @user.id }), method: :post, data: { turbo_frame: "modal" } do %> + <%= render Common::AddButtonComponent.new %> + <% end %> +
diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index 3f08b1dbe..11578d6d2 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -1,5 +1,5 @@ class Admin::GroupsController < ApplicationController - before_action :set_group, only: %i[show edit update destroy edit_members edit_permissions search_non_members search_non_tags] + before_action :set_group, only: %i[show edit update destroy edit_members show_members edit_permissions search_non_members search_non_tags] def index authorize([:admin, Group]) @@ -25,6 +25,10 @@ def edit_members authorize([:admin, @group]) end + def show_members + authorize([:admin, @group]) + end + def edit_permissions authorize([:admin, @group]) end diff --git a/app/policies/admin/group_policy.rb b/app/policies/admin/group_policy.rb index 665d76109..b4b4ec855 100644 --- a/app/policies/admin/group_policy.rb +++ b/app/policies/admin/group_policy.rb @@ -46,6 +46,10 @@ def edit_members? update? end + def show_members? + update? + end + def edit_permissions? update? end diff --git a/app/views/admin/group_memberships/create.html.erb b/app/views/admin/group_memberships/create.html.erb index a0e330280..cfeca4bc7 100644 --- a/app/views/admin/group_memberships/create.html.erb +++ b/app/views/admin/group_memberships/create.html.erb @@ -1 +1 @@ -<%= render Admin::Groups::GroupFormComponent.new(group: @group, action: :new)%> +<%= render Admin::Groups::GroupFormComponent.new(group: @group, readonly: false)%> diff --git a/app/views/admin/groups/edit_members.html.erb b/app/views/admin/groups/edit_members.html.erb index f532aa6ee..9eb8077f8 100644 --- a/app/views/admin/groups/edit_members.html.erb +++ b/app/views/admin/groups/edit_members.html.erb @@ -1,2 +1 @@ -<%= render Admin::Groups::GroupFormComponent.new(group: @group, step: :new) if params[:step] && params[:step] == 'new' %> -<%= render Admin::Groups::GroupFormComponent.new(group: @group, step: :edit) if !params[:step] || params[:step] != 'edit' %> +<%= render Admin::Groups::GroupFormComponent.new(group: @group, readonly: false) %> diff --git a/app/views/admin/groups/show_members.html.erb b/app/views/admin/groups/show_members.html.erb new file mode 100644 index 000000000..1cf123a8a --- /dev/null +++ b/app/views/admin/groups/show_members.html.erb @@ -0,0 +1 @@ +<%= render Admin::Groups::GroupFormComponent.new(group: @group, readonly: true) %> diff --git a/config/routes.rb b/config/routes.rb index c5c4720cb..0ca2b0e12 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -23,10 +23,12 @@ resources :tenants do resources :groups do get :edit_members, on: :member + get :show_members, on: :member get :edit_permissions, on: :member post :search_non_members, on: :member post :search_non_tags, on: :member - resources :group_memberships, param: :index + resources :group_memberships do + end end resources :users resources :boxes From cb2627db6ec285b8e9d54c9437f7662c5a2021bf Mon Sep 17 00:00:00 2001 From: stage-rl Date: Thu, 21 Sep 2023 13:01:16 +0200 Subject: [PATCH 14/21] Implement debounce --- .../admin/groups/group_form_component.html.erb | 6 ++++-- .../permissions/group_form_component.html.erb | 6 ++++-- app/javascript/controllers/debounce_controller.js | 14 ++++++++++++++ app/javascript/controllers/hello_controller.js | 7 ------- app/javascript/controllers/index.js | 4 ++-- 5 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 app/javascript/controllers/debounce_controller.js delete mode 100644 app/javascript/controllers/hello_controller.js diff --git a/app/components/admin/groups/group_form_component.html.erb b/app/components/admin/groups/group_form_component.html.erb index a13ee8cf4..c16dc4a93 100644 --- a/app/components/admin/groups/group_form_component.html.erb +++ b/app/components/admin/groups/group_form_component.html.erb @@ -14,14 +14,16 @@
<% if !@readonly %> - <%= form_with url: search_non_members_admin_tenant_group_path(Current.tenant, @group), class:"flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200" do |form| %> + <%= form_with url: search_non_members_admin_tenant_group_path(Current.tenant, @group), + data: { controller: 'debounce', debounce_target: 'form'}, + class:"flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200" do |form| %>
<%= render Icons::SearchComponent.new %>
<%= tag.turbo_frame id:'user-search-results' %> <%= form.search_field :name_search, value: params[:name_search], placeholder: "Vyhľadaj používateľa pre pridanie do skupiny", - oninput: "this.form.requestSubmit()", + data: { action: 'input->debounce#search' }, onreset: "this.form.requestSubmit()", class: "block w-full flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6" %>
diff --git a/app/components/admin/permissions/group_form_component.html.erb b/app/components/admin/permissions/group_form_component.html.erb index 3462a580f..85e48d852 100644 --- a/app/components/admin/permissions/group_form_component.html.erb +++ b/app/components/admin/permissions/group_form_component.html.erb @@ -13,14 +13,16 @@ <% end %>
- <%= form_with url: search_non_tags_admin_tenant_group_path(Current.tenant, @group), class:"flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200" do |form| %> + <%= form_with url: search_non_tags_admin_tenant_group_path(Current.tenant, @group), + data: { controller: 'debounce', debounce_target: 'form'}, + class:"flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200" do |form| %>
<%= render Icons::SearchComponent.new %>
<%= tag.turbo_frame id:'tag-search-results' %> <%= form.search_field :name_search, value: params[:name_search], placeholder: "Vyhľadaj štítok", - oninput: "this.form.requestSubmit()", + data: { action: 'input->debounce#search' }, onreset: "this.form.requestSubmit()", class: "block w-full flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6" %>
diff --git a/app/javascript/controllers/debounce_controller.js b/app/javascript/controllers/debounce_controller.js new file mode 100644 index 000000000..cfc3ca74b --- /dev/null +++ b/app/javascript/controllers/debounce_controller.js @@ -0,0 +1,14 @@ +import { Controller } from "@hotwired/stimulus" + +export default class extends Controller { + static targets = [ "form" ] + + connect() { console.log("debounce controller connected") } + + search() { + clearTimeout(this.timeout) + this.timeout = setTimeout(() => { + this.formTarget.requestSubmit() + }, 500) + } +} \ No newline at end of file diff --git a/app/javascript/controllers/hello_controller.js b/app/javascript/controllers/hello_controller.js deleted file mode 100644 index 5975c0789..000000000 --- a/app/javascript/controllers/hello_controller.js +++ /dev/null @@ -1,7 +0,0 @@ -import { Controller } from "@hotwired/stimulus" - -export default class extends Controller { - connect() { - this.element.textContent = "Hello World!" - } -} diff --git a/app/javascript/controllers/index.js b/app/javascript/controllers/index.js index d0685d3b7..1b47ccee3 100644 --- a/app/javascript/controllers/index.js +++ b/app/javascript/controllers/index.js @@ -4,5 +4,5 @@ import { application } from "./application" -import HelloController from "./hello_controller" -application.register("hello", HelloController) +import DebounceController from "./debounce_controller" +application.register("debounce", DebounceController) From 67cc439bebd5d1880cfa6e85ef473ce40d50aa52 Mon Sep 17 00:00:00 2001 From: stage-rl Date: Thu, 21 Sep 2023 13:20:42 +0200 Subject: [PATCH 15/21] Fix debounce time to 300ms --- app/javascript/controllers/debounce_controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/controllers/debounce_controller.js b/app/javascript/controllers/debounce_controller.js index cfc3ca74b..cc4e4ff5b 100644 --- a/app/javascript/controllers/debounce_controller.js +++ b/app/javascript/controllers/debounce_controller.js @@ -9,6 +9,6 @@ export default class extends Controller { clearTimeout(this.timeout) this.timeout = setTimeout(() => { this.formTarget.requestSubmit() - }, 500) + }, 300) } } \ No newline at end of file From 1ef89fc1fd27f55bf174d36a015edcecac25e6a0 Mon Sep 17 00:00:00 2001 From: stage-rl Date: Thu, 21 Sep 2023 13:32:30 +0200 Subject: [PATCH 16/21] Extend CloseButtonComponent to provide also link --- .../admin/boxes/box_form_component.html.erb | 4 +--- .../admin/groups/group_form_component.html.erb | 4 +--- .../groups/member_add_popup_component.html.erb | 4 +--- .../admin/groups/new_group_form_component.html.erb | 4 +--- .../permissions/group_form_component.html.erb | 4 +--- .../permissions/new_group_form_component.html.erb | 4 +--- .../permissions_add_popup_component.html.erb | 4 +--- .../admin/tags/tag_form_component.html.erb | 4 +--- .../admin/tenants/tenant_form_component.html.erb | 4 +--- .../admin/users/user_form_component.html.erb | 4 +--- .../common/close_button_component.html.erb | 14 ++++++++------ app/components/common/close_button_component.rb | 4 ++++ .../settings/rules/actions_form_component.html.erb | 4 +--- .../rules/conditions_form_component.html.erb | 4 +--- .../settings/rules/rule_form_component.html.erb | 4 +--- 15 files changed, 25 insertions(+), 45 deletions(-) diff --git a/app/components/admin/boxes/box_form_component.html.erb b/app/components/admin/boxes/box_form_component.html.erb index 53eb699f6..6c78fcda0 100644 --- a/app/components/admin/boxes/box_form_component.html.erb +++ b/app/components/admin/boxes/box_form_component.html.erb @@ -8,9 +8,7 @@

<%= @action == :new ? 'Nová schránka' : 'Zmena údajov o schránke'%>

Základné informácie o schránke

- <%= link_to admin_tenant_boxes_path(Current.tenant), data: { turbo_frame: "_top" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to: admin_tenant_boxes_path(Current.tenant)) %>
<%= form_with model:[:admin, Current.tenant, @box] do |form| %>
diff --git a/app/components/admin/groups/group_form_component.html.erb b/app/components/admin/groups/group_form_component.html.erb index c16dc4a93..48aad701e 100644 --- a/app/components/admin/groups/group_form_component.html.erb +++ b/app/components/admin/groups/group_form_component.html.erb @@ -8,9 +8,7 @@

<%= @group.name %>

Používatelia v skupine

- <%= link_to admin_tenant_groups_path(Current.tenant), data: { turbo_frame: "_top" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to: admin_tenant_groups_path(Current.tenant)) %>
<% if !@readonly %> diff --git a/app/components/admin/groups/member_add_popup_component.html.erb b/app/components/admin/groups/member_add_popup_component.html.erb index d6b9d9b5f..7b3e1d59b 100644 --- a/app/components/admin/groups/member_add_popup_component.html.erb +++ b/app/components/admin/groups/member_add_popup_component.html.erb @@ -5,9 +5,7 @@

Pridaj používateľa do skupiny

- <%= link_to edit_members_admin_tenant_group_path(Current.tenant, @group), data: { turbo_frame: "modal" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to: edit_members_admin_tenant_group_path(Current.tenant, @group), target_frame: 'modal') %>
diff --git a/app/components/admin/groups/new_group_form_component.html.erb b/app/components/admin/groups/new_group_form_component.html.erb index f6ca64b8c..4a334b5d2 100644 --- a/app/components/admin/groups/new_group_form_component.html.erb +++ b/app/components/admin/groups/new_group_form_component.html.erb @@ -8,9 +8,7 @@

Nová skupina

Názov skupiny

- <%= link_to admin_tenant_groups_path(Current.tenant), data: { turbo_frame: "_top" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to: admin_tenant_groups_path(Current.tenant)) %>
<%= form_with model:[:admin, Current.tenant, @group] do |form| %>
diff --git a/app/components/admin/permissions/group_form_component.html.erb b/app/components/admin/permissions/group_form_component.html.erb index 85e48d852..016d000ab 100644 --- a/app/components/admin/permissions/group_form_component.html.erb +++ b/app/components/admin/permissions/group_form_component.html.erb @@ -8,9 +8,7 @@

Nastaviť prístup

Štítky

- <%= link_to admin_tenant_tag_groups_path(Current.tenant), data: { turbo_frame: "_top" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to admin_tenant_tag_groups_path(Current.tenant)) %>
<%= form_with url: search_non_tags_admin_tenant_group_path(Current.tenant, @group), diff --git a/app/components/admin/permissions/new_group_form_component.html.erb b/app/components/admin/permissions/new_group_form_component.html.erb index f6ca64b8c..4a334b5d2 100644 --- a/app/components/admin/permissions/new_group_form_component.html.erb +++ b/app/components/admin/permissions/new_group_form_component.html.erb @@ -8,9 +8,7 @@

Nová skupina

Názov skupiny

- <%= link_to admin_tenant_groups_path(Current.tenant), data: { turbo_frame: "_top" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to: admin_tenant_groups_path(Current.tenant)) %> <%= form_with model:[:admin, Current.tenant, @group] do |form| %>
diff --git a/app/components/admin/permissions/permissions_add_popup_component.html.erb b/app/components/admin/permissions/permissions_add_popup_component.html.erb index eebb66379..b56f7f86c 100644 --- a/app/components/admin/permissions/permissions_add_popup_component.html.erb +++ b/app/components/admin/permissions/permissions_add_popup_component.html.erb @@ -5,9 +5,7 @@

Pridaj právo na štítok skupine

- <%= link_to edit_permissions_admin_tenant_group_path(Current.tenant, @group), data: { turbo_frame: "modal" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to: edit_permissions_admin_tenant_group_path(Current.tenant, @group), target_frame: 'modal') %>
<% @tags.each do |tag| %> diff --git a/app/components/admin/tags/tag_form_component.html.erb b/app/components/admin/tags/tag_form_component.html.erb index 297a572ae..c0d0e8e0e 100644 --- a/app/components/admin/tags/tag_form_component.html.erb +++ b/app/components/admin/tags/tag_form_component.html.erb @@ -8,9 +8,7 @@

<%= @action == :new ? "Nový štítok" : "Úprava štítku" %>

Názov štítku

- <%= link_to admin_tenant_tags_path(Current.tenant), data: { turbo_frame: "_top" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to: admin_tenant_tags_path(Current.tenant)) %> <%= form_with model:[:admin, Current.tenant, @tag] do |form| %>
diff --git a/app/components/admin/tenants/tenant_form_component.html.erb b/app/components/admin/tenants/tenant_form_component.html.erb index 36e0d0c2a..c88006d45 100644 --- a/app/components/admin/tenants/tenant_form_component.html.erb +++ b/app/components/admin/tenants/tenant_form_component.html.erb @@ -8,9 +8,7 @@

<%= @action == 'new' ? 'Nový tenant' : 'Zmena tenanta'%>

Základné údaje o tenantovi

- <%= link_to admin_tenants_path, data: { turbo_frame: "_top" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to: admin_tenants_path) %> <%= form_with model:[:admin, @tenant] do |form| %>
diff --git a/app/components/admin/users/user_form_component.html.erb b/app/components/admin/users/user_form_component.html.erb index b35ead305..3a197437a 100644 --- a/app/components/admin/users/user_form_component.html.erb +++ b/app/components/admin/users/user_form_component.html.erb @@ -8,9 +8,7 @@

<%= @action == 'new' ? 'Nový používateľ' : 'Zmena používateľa'%>

Základné údaje o používateľovi

- <%= link_to admin_tenant_users_path(Current.tenant), data: { turbo_frame: "_top" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to: admin_tenant_users_path(Current.tenant)) %> <%= form_with model:[:admin, Current.tenant, @user], data: { turbo_frame: "_top" } do |form| %>
diff --git a/app/components/common/close_button_component.html.erb b/app/components/common/close_button_component.html.erb index 1fa3f4068..c808abec5 100644 --- a/app/components/common/close_button_component.html.erb +++ b/app/components/common/close_button_component.html.erb @@ -1,6 +1,8 @@ -
- - - - -
+<%= link_to @link_to, data: { turbo_frame: @target_frame } do %> +
+ + + + +
+<% end %> diff --git a/app/components/common/close_button_component.rb b/app/components/common/close_button_component.rb index b01c7e811..5a5f48884 100644 --- a/app/components/common/close_button_component.rb +++ b/app/components/common/close_button_component.rb @@ -1,4 +1,8 @@ module Common class CloseButtonComponent < ViewComponent::Base + def initialize(link_to:, target_frame: '_top') + @link_to = link_to + @target_frame = target_frame + end end end diff --git a/app/components/settings/rules/actions_form_component.html.erb b/app/components/settings/rules/actions_form_component.html.erb index 20035053c..0432d6331 100644 --- a/app/components/settings/rules/actions_form_component.html.erb +++ b/app/components/settings/rules/actions_form_component.html.erb @@ -9,9 +9,7 @@

Úprava pravidla

Krok 3 z 3 – Akcie pravidla

- <%= link_to settings_automation_rules_path, data: { turbo_frame: "_top" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to: settings_automation_rules_path) %>
<%= render Icons::InfoComponent.new %> diff --git a/app/components/settings/rules/conditions_form_component.html.erb b/app/components/settings/rules/conditions_form_component.html.erb index 930ebc26b..5310c4b32 100644 --- a/app/components/settings/rules/conditions_form_component.html.erb +++ b/app/components/settings/rules/conditions_form_component.html.erb @@ -9,9 +9,7 @@

Úprava pravidla

Krok 2 z 3 – Podmienky pravidla

- <%= link_to settings_automation_rules_path, data: { turbo_frame: "_top" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to: settings_automation_rules_path) %>
<%= render Icons::InfoComponent.new %> diff --git a/app/components/settings/rules/rule_form_component.html.erb b/app/components/settings/rules/rule_form_component.html.erb index fb9700d00..0b8c2d5f7 100644 --- a/app/components/settings/rules/rule_form_component.html.erb +++ b/app/components/settings/rules/rule_form_component.html.erb @@ -9,9 +9,7 @@

Úprava pravidla

Krok 1 z 3 – Hlavička pravidla

- <%= link_to settings_automation_rules_path, data: { turbo_frame: "_top" } do %> - <%= render Common::CloseButtonComponent.new %> - <% end %> + <%= render Common::CloseButtonComponent.new(link_to: settings_automation_rules_path) %>
<%= render Icons::InfoComponent.new %> From 9813a1d37f4c14a6302bdb74de6ba97b4b0169ac Mon Sep 17 00:00:00 2001 From: stage-rl Date: Fri, 22 Sep 2023 07:57:03 +0200 Subject: [PATCH 17/21] Minor fixes and refactors based on PR review --- .../permissions/group_form_component.html.erb | 2 +- .../groups_list_component.html.erb | 4 +- .../groups_list_row_component.html.erb | 4 +- .../permissions/groups_list_row_component.rb | 3 +- .../permissions/permission_add_component.rb | 1 - .../permissions_list_row_component.html.erb | 2 +- .../admin/permissions/tag_component.rb | 2 +- .../admin/tags/tags_list_component.html.erb | 4 +- .../admin/tags/tags_list_row_component.rb | 3 +- .../tags/visibility_toggle_component.html.erb | 2 +- .../common/tag_selector_component.html.erb | 2 +- .../tag_selector_popup_component.html.erb | 58 ++++++++++--------- app/controllers/admin/boxes_controller.rb | 2 - app/controllers/admin/tags_controller.rb | 5 -- app/controllers/messages_controller.rb | 13 ----- app/controllers/sessions_controller.rb | 1 + app/controllers/tags_controller.rb | 17 +++++- app/models/box.rb | 2 +- app/policies/admin/tag_policy.rb | 4 -- app/policies/tag_policy.rb | 4 ++ app/views/boxes/show.html.erb | 25 -------- app/views/layouts/login.html.erb | 16 +++++ app/views/sessions/login.html.erb | 1 - app/views/tags/get_available.html.erb | 1 + config/routes.rb | 8 ++- 25 files changed, 86 insertions(+), 100 deletions(-) create mode 100644 app/views/layouts/login.html.erb create mode 100644 app/views/tags/get_available.html.erb diff --git a/app/components/admin/permissions/group_form_component.html.erb b/app/components/admin/permissions/group_form_component.html.erb index 016d000ab..af72e7e29 100644 --- a/app/components/admin/permissions/group_form_component.html.erb +++ b/app/components/admin/permissions/group_form_component.html.erb @@ -8,7 +8,7 @@

Nastaviť prístup

Štítky

- <%= render Common::CloseButtonComponent.new(link_to admin_tenant_tag_groups_path(Current.tenant)) %> + <%= render Common::CloseButtonComponent.new(link_to: admin_tenant_tag_groups_path(Current.tenant)) %>
<%= form_with url: search_non_tags_admin_tenant_group_path(Current.tenant, @group), diff --git a/app/components/admin/permissions/groups_list_component.html.erb b/app/components/admin/permissions/groups_list_component.html.erb index a1f61b825..05ed96ab7 100644 --- a/app/components/admin/permissions/groups_list_component.html.erb +++ b/app/components/admin/permissions/groups_list_component.html.erb @@ -4,9 +4,7 @@
Skupiny
- <% @groups.each do |group| %> - <%= render Admin::Permissions::GroupsListRowComponent.new(group) %> - <% end %> + <%= render Admin::Permissions::GroupsListRowComponent.with_collection(@groups) %>
diff --git a/app/components/admin/permissions/groups_list_row_component.html.erb b/app/components/admin/permissions/groups_list_row_component.html.erb index 4d2c06059..02f273c62 100644 --- a/app/components/admin/permissions/groups_list_row_component.html.erb +++ b/app/components/admin/permissions/groups_list_row_component.html.erb @@ -17,9 +17,7 @@
- <% @group.tag_groups.each do |tag_group| %> - <%= render Admin::Permissions::TagComponent.new(tag_group.tag) %> - <% end %> + <%= render Admin::Permissions::TagComponent.with_collection(@group.tags) %>
diff --git a/app/components/admin/permissions/groups_list_row_component.rb b/app/components/admin/permissions/groups_list_row_component.rb index 66b141d3e..8bf098a08 100644 --- a/app/components/admin/permissions/groups_list_row_component.rb +++ b/app/components/admin/permissions/groups_list_row_component.rb @@ -1,5 +1,6 @@ class Admin::Permissions::GroupsListRowComponent < ViewComponent::Base - def initialize(group) + with_collection_parameter :group + def initialize(group:) @group = group end end diff --git a/app/components/admin/permissions/permission_add_component.rb b/app/components/admin/permissions/permission_add_component.rb index aa7b75310..f6a0829ca 100644 --- a/app/components/admin/permissions/permission_add_component.rb +++ b/app/components/admin/permissions/permission_add_component.rb @@ -2,6 +2,5 @@ class Admin::Permissions::PermissionAddComponent < ViewComponent::Base def initialize(tag:, group:) @tag = tag @group = group - @new_permission = TagGroup.new({ group_id: @group.id, tag_id: @tag.id }) end end diff --git a/app/components/admin/permissions/permissions_list_row_component.html.erb b/app/components/admin/permissions/permissions_list_row_component.html.erb index a6e69a08e..85b2d947c 100644 --- a/app/components/admin/permissions/permissions_list_row_component.html.erb +++ b/app/components/admin/permissions/permissions_list_row_component.html.erb @@ -1,4 +1,4 @@ -<%= render Admin::Permissions::TagComponent.new(@tag_group.tag) %> +<%= render Admin::Permissions::TagComponent.new(tag: @tag_group.tag) %> <%= button_to admin_tenant_tag_group_path(Current.tenant, @tag_group), method: :delete do %> <%= render Common::DeleteButtonComponent.new %> <% end %> diff --git a/app/components/admin/permissions/tag_component.rb b/app/components/admin/permissions/tag_component.rb index 41767a466..b0981a643 100644 --- a/app/components/admin/permissions/tag_component.rb +++ b/app/components/admin/permissions/tag_component.rb @@ -1,5 +1,5 @@ class Admin::Permissions::TagComponent < ViewComponent::Base - def initialize(tag) + def initialize(tag:) @tag = tag end end diff --git a/app/components/admin/tags/tags_list_component.html.erb b/app/components/admin/tags/tags_list_component.html.erb index 9a68eddb0..8d87ffbc6 100644 --- a/app/components/admin/tags/tags_list_component.html.erb +++ b/app/components/admin/tags/tags_list_component.html.erb @@ -7,9 +7,7 @@ <% end %>
- <% @internal_tags.each do |tag| %> - <%= render Admin::Tags::TagsListRowComponent.new(tag) %> - <% end %> + <%= render Admin::Tags::TagsListRowComponent.with_collection(@internal_tags) %>
<%= render Admin::Tags::ExternalTagsComponent.new(@external_tags) %> diff --git a/app/components/admin/tags/tags_list_row_component.rb b/app/components/admin/tags/tags_list_row_component.rb index 9fee83094..a3aa8ae33 100644 --- a/app/components/admin/tags/tags_list_row_component.rb +++ b/app/components/admin/tags/tags_list_row_component.rb @@ -1,5 +1,6 @@ class Admin::Tags::TagsListRowComponent < ViewComponent::Base - def initialize(tag) + with_collection_parameter :tag + def initialize(tag:) @tag = tag end end diff --git a/app/components/admin/tags/visibility_toggle_component.html.erb b/app/components/admin/tags/visibility_toggle_component.html.erb index 5386261cf..ce4e9ec6c 100644 --- a/app/components/admin/tags/visibility_toggle_component.html.erb +++ b/app/components/admin/tags/visibility_toggle_component.html.erb @@ -1,5 +1,5 @@ <%= tag.turbo_frame id:"@tag-form-visible-#{tag.id}" do %> - <%= form_with url:visibility_toggle_admin_tenant_tag_path(@tag.tenant, @tag), method: :patch do |form| %> + <%= form_with model:[:admin, Current.tenant, @tag], method: :patch do |form| %> <%= form.hidden_field :visible, value:!@tag.visible %> <%= form.button class:"#{@tag.visible ? "bg-indigo-600" : "bg-gray-200"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: :false}, data: @dialog do %> Use setting diff --git a/app/components/common/tag_selector_component.html.erb b/app/components/common/tag_selector_component.html.erb index ba97dd215..48b3e727b 100644 --- a/app/components/common/tag_selector_component.html.erb +++ b/app/components/common/tag_selector_component.html.erb @@ -18,6 +18,6 @@ diff --git a/app/components/common/tag_selector_popup_component.html.erb b/app/components/common/tag_selector_popup_component.html.erb index 046e87a8a..ebc32135d 100644 --- a/app/components/common/tag_selector_popup_component.html.erb +++ b/app/components/common/tag_selector_popup_component.html.erb @@ -1,7 +1,8 @@ -
-
- - + -
-
- - - -
-
- <% @tags.each do |tag|%> -
- <% if @object.class.name == 'MessageThread' %> - <%= form_with model: [MessageThreadsTag.new(message_thread: @object, tag: tag)], class: "contents" do |form| %> - <%= form.hidden_field :message_thread_id %> - <%= form.hidden_field :tag_id %> - <%= form.submit "#{tag.name}" ,class:"text-sm text-left text-blue-600 hover:cursor-pointer" %> - <% end %> - <% else %> - <%= form_with model: [MessagesTag.new(message: @object, tag: tag)], class: "contents" do |form| %> - <%= form.hidden_field :message_id %> - <%= form.hidden_field :tag_id %> - <%= form.submit "#{tag.name}", class:"text-sm text-left text-blue-600 hover:cursor-pointer" %> +
+
+ + + +
+
+ <% @tags.each do |tag|%> +
+ <% if @object.class.name == 'MessageThread' %> + <%= form_with model: [MessageThreadsTag.new(message_thread: @object, tag: tag)], class: "contents" do |form| %> + <%= form.hidden_field :message_thread_id %> + <%= form.hidden_field :tag_id %> + <%= form.submit "#{tag.name}" ,class:"text-sm text-left text-blue-600 hover:cursor-pointer" %> + <% end %> + <% else %> + <%= form_with model: [MessagesTag.new(message: @object, tag: tag)], class: "contents" do |form| %> + <%= form.hidden_field :message_id %> + <%= form.hidden_field :tag_id %> + <%= form.submit "#{tag.name}", class:"text-sm text-left text-blue-600 hover:cursor-pointer" %> + <% end %> <% end %> - <% end %> -
- <% end %> +
+ <% end %> +
- +<% end %> diff --git a/app/controllers/admin/boxes_controller.rb b/app/controllers/admin/boxes_controller.rb index 05c5df65b..f4e127a72 100644 --- a/app/controllers/admin/boxes_controller.rb +++ b/app/controllers/admin/boxes_controller.rb @@ -23,8 +23,6 @@ def edit def create @box = Current.tenant.boxes.new(box_params) authorize([:admin, @box]) - @box.color = Box.colors.keys[Digest::MD5.hexdigest(@box.name).to_i(16) % Box.colors.size] - if @box.save redirect_to admin_tenant_boxes_url(Current.tenant), notice: "Box was successfully created." else diff --git a/app/controllers/admin/tags_controller.rb b/app/controllers/admin/tags_controller.rb index 3d631590c..21cf1d197 100644 --- a/app/controllers/admin/tags_controller.rb +++ b/app/controllers/admin/tags_controller.rb @@ -41,11 +41,6 @@ def update end end - def visibility_toggle - authorize([:admin, @tag]) - @tag.update(tag_params_visibility) - end - def destroy authorize([:admin, @tag]) @tag.destroy diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 1e8582f57..6aa6a1d87 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -6,9 +6,6 @@ def show @message.update(read: true) @message_thread = @message.thread - @available_tags = available_tags - - @notice = notice end def authorize_delivery_notification @@ -28,14 +25,4 @@ def set_message def permit_reply_params params.permit(:reply_title, :reply_text) end - - def available_tags - @tenant = @message.tenant - @tenant.tags.where.not(id: @message.tags.ids).where(visible: true) - .where( - id: TagGroup.select(:tag_id) - .joins(:group, :tag, group: :users) - .where(group: { tenant_id: @tenant.id }, tag: { tenant_id: @tenant.id }, users: { id: Current.user.id }) - ) - end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index be3861f91..926008829 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -3,6 +3,7 @@ class SessionsController < ApplicationController skip_after_action :verify_authorized skip_after_action :verify_policy_scoped skip_before_action :set_menu_context + layout :login def login end diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 3a312b630..2634c1208 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,13 +1,28 @@ class TagsController < ApplicationController - before_action :set_tag + before_action :set_tag, only: %i[show] before_action :set_visible_tags def show authorize [:admin, @tag] end + def get_available + authorize [Tag] + set_object + @tenant = Current.tenant + @tags = + @tenant.tags.where.not(id: @object.tags.ids).where(visible: true) + .where(id: TagGroup.select(:tag_id).joins(:group, :tag, group: :users).where(group: { tenant_id: @tenant.id }, tag: { tenant_id: @tenant.id }, users: { id: Current.user.id })) + respond_to { |format| format.html } + end + private + def set_object + @object = policy_scope(Message).find(params[:object_id]) if params[:object_class] == 'Message' + @object = policy_scope(MessageThread).find(params[:object_id]) if params[:object_class] == 'MessageThread' + end + def set_visible_tags @visible_tags = policy_scope(Tag).where(visible: true) end diff --git a/app/models/box.rb b/app/models/box.rb index 39597e12f..427f55c08 100644 --- a/app/models/box.rb +++ b/app/models/box.rb @@ -17,7 +17,7 @@ class Box < ApplicationRecord has_many :message_threads, through: :folders, extend: MessageThreadsExtensions has_many :message_drafts_imports - before_create { self.color = Box.colors.keys[Digest::MD5.hexdigest(name).to_i(16) % Box.colors.size] if color.blank? } + before_create { self.color = Box.colors.keys[name.hash % Box.colors.size] if color.blank? } enum :color, { diff --git a/app/policies/admin/tag_policy.rb b/app/policies/admin/tag_policy.rb index bb176c700..fa70bced6 100644 --- a/app/policies/admin/tag_policy.rb +++ b/app/policies/admin/tag_policy.rb @@ -38,10 +38,6 @@ def edit? update? end - def visibility_toggle? - update? - end - def destroy? @user.site_admin? || @user.admin? end diff --git a/app/policies/tag_policy.rb b/app/policies/tag_policy.rb index fad809012..55d3078e2 100644 --- a/app/policies/tag_policy.rb +++ b/app/policies/tag_policy.rb @@ -27,4 +27,8 @@ def resolve def show? true end + + def get_available? + true + end end diff --git a/app/views/boxes/show.html.erb b/app/views/boxes/show.html.erb index 36d1a7a22..f05ac20a5 100644 --- a/app/views/boxes/show.html.erb +++ b/app/views/boxes/show.html.erb @@ -2,28 +2,3 @@ <%= form_tag box_sync_path(@box), method: :post do %> <%= submit_tag 'Stiahnúť nové správy' %> <% end %> -
-
-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-

Paleta - kvoli pregenerovaniu CSS

-
diff --git a/app/views/layouts/login.html.erb b/app/views/layouts/login.html.erb new file mode 100644 index 000000000..ebcf927e4 --- /dev/null +++ b/app/views/layouts/login.html.erb @@ -0,0 +1,16 @@ + + + + GovboxPro + + <%= csrf_meta_tags %> + <%= csp_meta_tag %> + <%= stylesheet_link_tag "tailwind", "inter-font", "data-turbo-track": "reload" %> + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> + <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> + + + Vajco vajcovite + <%= turbo_frame_tag :login_screen %> + + diff --git a/app/views/sessions/login.html.erb b/app/views/sessions/login.html.erb index 5f33a2b1f..01f3025c9 100644 --- a/app/views/sessions/login.html.erb +++ b/app/views/sessions/login.html.erb @@ -1,4 +1,3 @@ - <% unless Current.user %> <%= turbo_stream.replace "login_screen" do %> diff --git a/app/components/admin/permissions/group_form_component.html.erb b/app/components/admin/permissions/group_form_component.html.erb index af72e7e29..78709f4ef 100644 --- a/app/components/admin/permissions/group_form_component.html.erb +++ b/app/components/admin/permissions/group_form_component.html.erb @@ -20,7 +20,7 @@ <%= tag.turbo_frame id:'tag-search-results' %> <%= form.search_field :name_search, value: params[:name_search], placeholder: "Vyhľadaj štítok", - data: { action: 'input->debounce#search' }, + data: { action: 'input->debounce#debounce' }, onreset: "this.form.requestSubmit()", class: "block w-full flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6" %> diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 926008829..bf17d36f1 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -3,7 +3,7 @@ class SessionsController < ApplicationController skip_after_action :verify_authorized skip_after_action :verify_policy_scoped skip_before_action :set_menu_context - layout :login + layout 'login' def login end @@ -19,6 +19,6 @@ def destroy end def failure - render html: "Authorization failed (#{request.params['message']})", status: :forbidden + render html: "Authorization failed (#{request.params["message"]})", status: :forbidden end end diff --git a/app/javascript/controllers/debounce_controller.js b/app/javascript/controllers/debounce_controller.js index cc4e4ff5b..f10f6d786 100644 --- a/app/javascript/controllers/debounce_controller.js +++ b/app/javascript/controllers/debounce_controller.js @@ -1,14 +1,14 @@ -import { Controller } from "@hotwired/stimulus" +import { Controller } from "@hotwired/stimulus"; export default class extends Controller { - static targets = [ "form" ] + static targets = ["form"]; - connect() { console.log("debounce controller connected") } + connect() {} - search() { - clearTimeout(this.timeout) + debounce() { + clearTimeout(this.timeout); this.timeout = setTimeout(() => { - this.formTarget.requestSubmit() - }, 300) + this.formTarget.requestSubmit(); + }, 300); } -} \ No newline at end of file +} diff --git a/app/views/layouts/login.html.erb b/app/views/layouts/login.html.erb index ebcf927e4..08c27b419 100644 --- a/app/views/layouts/login.html.erb +++ b/app/views/layouts/login.html.erb @@ -10,7 +10,6 @@ <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %> - Vajco vajcovite - <%= turbo_frame_tag :login_screen %> + <%= yield %> diff --git a/app/views/sessions/login.html.erb b/app/views/sessions/login.html.erb index 01f3025c9..b79f13bc3 100644 --- a/app/views/sessions/login.html.erb +++ b/app/views/sessions/login.html.erb @@ -1,13 +1,19 @@ -<% unless Current.user %> - <%= turbo_stream.replace "login_screen" do %> -