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/assets/images/SD_icon.png b/app/assets/images/SD_icon.png
index 38fd92c51..3d6b19080 100644
Binary files a/app/assets/images/SD_icon.png and b/app/assets/images/SD_icon.png differ
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 @@
-
- <%= render Common::TagSelectorPopupComponent.new(@object) %>
+ <%= tag.turbo_frame id: 'tag-selector-popup', loading: :lazy, src: get_available_tags_path(object_class: @object.class, object_id: @object.id) %>
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.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 @@
-
<%= render Icons::InfoComponent.new %>
diff --git a/app/controllers/admin/boxes_controller.rb b/app/controllers/admin/boxes_controller.rb
index abee6b7b5..f4e127a72 100644
--- a/app/controllers/admin/boxes_controller.rb
+++ b/app/controllers/admin/boxes_controller.rb
@@ -23,9 +23,8 @@ def edit
def create
@box = Current.tenant.boxes.new(box_params)
authorize([:admin, @box])
-
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
@@ -34,7 +33,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
@@ -43,7 +42,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
@@ -53,6 +52,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..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 search_non_members]
+ 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,13 +25,21 @@ def edit_members
authorize([:admin, @group])
end
+ def show_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 +48,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 +57,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 +67,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 +84,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 fd977d643..cbc4ac43c 100644
--- a/app/controllers/admin/tags_controller.rb
+++ b/app/controllers/admin/tags_controller.rb
@@ -1,8 +1,8 @@
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 Tag
+ authorize [:admin, Tag]
@tags = policy_scope([:admin, Tag])
end
@@ -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,7 +35,7 @@ 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
@@ -43,7 +44,7 @@ def update
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 +56,8 @@ def set_tag
def tag_params
params.require(:tag).permit(:name, :visible, :user_id, :tenant_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 058d0ab57..feba69499 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,26 @@ 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
+ redirect_to admin_tenant_users_url(Current.tenant), notice: 'User was successfully created'
+ 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)
+ redirect_to admin_tenant_users_url(Current.tenant), notice: 'User was successfully updated'
+ 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
+ redirect_to admin_tenant_users_url(Current.tenant), notice: 'User was successfully destroyed'
end
private
@@ -69,18 +50,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/messages_controller.rb b/app/controllers/messages_controller.rb
index b61a46cf0..6aa6a1d87 100644
--- a/app/controllers/messages_controller.rb
+++ b/app/controllers/messages_controller.rb
@@ -6,8 +6,6 @@ def show
@message.update(read: true)
@message_thread = @message.thread
-
- @notice = notice
end
def authorize_delivery_notification
@@ -16,7 +14,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
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index be3861f91..bf17d36f1 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
@@ -18,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/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/controllers/tags_controller.rb b/app/controllers/tags_controller.rb
index d353ce046..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 @tag
+ 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/javascript/controllers/debounce_controller.js b/app/javascript/controllers/debounce_controller.js
new file mode 100644
index 000000000..f10f6d786
--- /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() {}
+
+ debounce() {
+ clearTimeout(this.timeout);
+ this.timeout = setTimeout(() => {
+ this.formTarget.requestSubmit();
+ }, 300);
+ }
+}
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)
diff --git a/app/jobs/drafts/parse_import_job.rb b/app/jobs/drafts/parse_import_job.rb
index 40680da35..7576a8ff5 100644
--- a/app/jobs/drafts/parse_import_job.rb
+++ b/app/jobs/drafts/parse_import_job.rb
@@ -77,11 +77,7 @@ def load_import_csv(import, csv_path)
last_message_delivered_at: Time.now
)
- message_thread.tags << Tag.find_or_create_by!(
- name: "Drafts",
- tenant: import.box.tenant,
- visible: true
- )
+ message_thread.tags << Tag.find_by!(name: "Drafts", tenant: import.box.tenant)
MessageDraft.create!(
uuid: uuid,
diff --git a/app/lib/sidebar_menu.rb b/app/lib/sidebar_menu.rb
index 72b1180de..866896645 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 tag_groups automation_rules boxes tenants]) && (Current.user.admin? || Current.user.site_admin?)
default_main_menu
end
@@ -23,25 +23,30 @@ 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'),
- 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)
- ]
+ 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: '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 f693f287f..2da8df232 100644
--- a/app/models/box.rb
+++ b/app/models/box.rb
@@ -18,5 +18,32 @@ class Box < ApplicationRecord
has_many :message_drafts_imports, dependent: :destroy
before_destroy ->(box) { EventBus.publish(:box_destroyed, box.id) }
-end
+ before_create { self.color = Box.colors.keys[name.hash % Box.colors.size] if color.blank? }
+
+ 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 37c17b055..266a63fac 100644
--- a/app/models/govbox/message.rb
+++ b/app/models/govbox/message.rb
@@ -112,6 +112,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/models/tenant.rb b/app/models/tenant.rb
index 31e06a8de..5cf6df7c5 100644
--- a/app/models/tenant.rb
+++ b/app/models/tenant.rb
@@ -17,14 +17,15 @@ class Tenant < ApplicationRecord
has_many :automation_rules, class_name: 'Automation::Rule', dependent: :destroy
has_many :folders, through: :boxes
has_many :tags, dependent: :destroy
- after_create :create_default_groups
+ after_create :create_default_objects
validates_presence_of :name
private
- def create_default_groups
+ def create_default_objects
groups.create!(name: 'all', group_type: 'ALL')
groups.create!(name: 'admins', group_type: 'ADMIN')
+ tags.create!(name: 'Drafts', external: false, visible: true)
end
end
diff --git a/app/policies/admin/group_policy.rb b/app/policies/admin/group_policy.rb
index 73b73b047..b4b4ec855 100644
--- a/app/policies/admin/group_policy.rb
+++ b/app/policies/admin/group_policy.rb
@@ -46,6 +46,14 @@ def edit_members?
update?
end
+ def show_members?
+ update?
+ end
+
+ def edit_permissions?
+ update?
+ end
+
def destroy?
@user.site_admin? || @user.admin?
end
@@ -54,4 +62,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 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/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/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..cfeca4bc7
--- /dev/null
+++ b/app/views/admin/group_memberships/create.html.erb
@@ -0,0 +1 @@
+<%= render Admin::Groups::GroupFormComponent.new(group: @group, readonly: false)%>
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_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/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/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/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 1933ed2d5..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_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/_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..0b419cf11 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: @user, action: :edit) %>
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..65170352e 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: @user, action: :new) %>
diff --git a/app/views/admin/users/show.html.erb b/app/views/admin/users/show.html.erb
deleted file mode 100644
index f8bfcea7b..000000000
--- a/app/views/admin/users/show.html.erb
+++ /dev/null
@@ -1,188 +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
-
-
-
-
- -
-
-
- -
-
-
-
-
Tags Assigned (obsolete)
-
-
-
-
-
-
-
-
diff --git a/app/views/boxes/show.html.erb b/app/views/boxes/show.html.erb
index 522361940..f05ac20a5 100644
--- a/app/views/boxes/show.html.erb
+++ b/app/views/boxes/show.html.erb
@@ -1,5 +1,4 @@
Schránka <%= @box.name %>
-
<%= form_tag box_sync_path(@box), method: :post do %>
<%= submit_tag 'Stiahnúť nové správy' %>
<% end %>
diff --git a/app/views/layouts/login.html.erb b/app/views/layouts/login.html.erb
new file mode 100644
index 000000000..08c27b419
--- /dev/null
+++ b/app/views/layouts/login.html.erb
@@ -0,0 +1,15 @@
+
+
+
+
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 %>
+
+
+ <%= yield %>
+
+
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) %>
diff --git a/app/views/sessions/login.html.erb b/app/views/sessions/login.html.erb
index 46cbf8b15..b79f13bc3 100644
--- a/app/views/sessions/login.html.erb
+++ b/app/views/sessions/login.html.erb
@@ -1,4 +1,19 @@
-
-<% 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" %>
-<% end %>
+
+
+ <%= image_tag("SD_icon.png", alt: "logo", class:"mx-auto h-10 w-auto") %>
+
Prihláste sa do svojho účtu
+
+
+
+
+
+ <%= button_to "Sign in with Google", "/auth/google_oauth2", method: :post, data: { turbo: false }, class: "flex w-full justify-center rounded-md bg-indigo-600 px-3 py-1.5 text-sm font-semibold leading-6 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" %>
+
+
+
+
+ Nemáte účet?
+ Kontaktujte nás
+
+
+
diff --git a/app/views/tags/get_available.html.erb b/app/views/tags/get_available.html.erb
new file mode 100644
index 000000000..ba0800546
--- /dev/null
+++ b/app/views/tags/get_available.html.erb
@@ -0,0 +1 @@
+<%= render Common::TagSelectorPopupComponent.new(@object, @tags) %>
diff --git a/config/routes.rb b/config/routes.rb
index b017e7a50..1695867d3 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,22 @@
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
- resources :group_memberships, param: :index
+ post :search_non_tags, on: :member
+ resources :group_memberships do
+ end
end
resources :users
resources :boxes
resources :tags
+ resources :tag_groups
end
+ end
- resources :group_memberships
- resources :tag_users
-
- resources :tag_groups, only: [:create, :destroy]
+ resources :tags do
+ get :get_available, on: :collection
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..5a45a887b
--- /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[@box.name.hash % 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/migrate/20230922090015_add_draft_tag_to_tenants.rb b/db/migrate/20230922090015_add_draft_tag_to_tenants.rb
new file mode 100644
index 000000000..37c6bfdff
--- /dev/null
+++ b/db/migrate/20230922090015_add_draft_tag_to_tenants.rb
@@ -0,0 +1,8 @@
+class AddDraftTagToTenants < ActiveRecord::Migration[7.0]
+ def change
+ Tenant.all.each do |tenant|
+ tenant.tags.find_or_create_by!(name: 'Drafts', external: false, visible: true)
+ tenant.save!
+ end
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 6b8ead85d..872e55442 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_20_093653) do
+ActiveRecord::Schema[7.0].define(version: 2023_09_22_090015) 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,6 +86,9 @@
t.datetime "updated_at", null: false
t.bigint "tenant_id", 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
@@ -358,6 +362,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, lower((name)::text)", name: "index_tags_on_tenant_id_and_lowercase_name", unique: true
t.index ["tenant_id"], name: "index_tags_on_tenant_id"
t.index ["user_id"], name: "index_tags_on_user_id"
diff --git a/db/seeds.rb b/db/seeds.rb
index 929ca5d11..29af7ad86 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -8,8 +8,8 @@
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")
-Govbox::ApiConnection.find_or_create_by!(sub: "SPL_Irvin_83300252_KK_24022023", box_id: box.id, api_token_private_key: File.read(Rails.root + "security/govbox_api_fix.pem"))
+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 043e1779f..482de69c7 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: MyString2
+ external: false
visible: false
tenant: solver
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