Skip to content

Commit

Permalink
Merge branch 'main' into GO-246/site_admin_cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-rl committed Dec 4, 2023
2 parents 6833400 + 8592c14 commit edbc7e4
Show file tree
Hide file tree
Showing 49 changed files with 309 additions and 205 deletions.
1 change: 1 addition & 0 deletions app/components/admin/groups/group_form_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<%= tag.turbo_frame id: "modal" do %>
<%= render Common::AlertComponent.new %>
<div class="fixed inset-0 z-40 p-2" role="dialog" aria-modal="true">
<div class="fixed inset-0 transition-opacity bg-gray-400 bg-opacity-75" aria-hidden="true"></div>
<div class="relative flex items-center justify-center h-full">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="grow shrink basis-0 flex-col justify-start items-start gap-1 inline-flex">
<div class="text-center text-gray-900 text-lg font-medium leading-loose">
<% if @group.renamable? %>
<%= render Common::InlineRenameComponent.new(name: @group.name, model: [:admin, @group.tenant, @group], url: admin_tenant_group_path(@group.tenant, @group)) %>
<%= render Common::InlineRenameComponent.new(name: @group.name, model: @group, url: admin_tenant_group_path(@group.tenant, @group)) %>
<% else %>
<%= @group.name %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<div class="w-16 h-16 justify-center items-center flex">
<img class="w-16 h-16 rounded-full" src="https://via.placeholder.com/64x64" />
<img class="w-16 h-16 rounded-full" src="https://via.placeholder.com/64x64">
</div>
<div class="grow shrink basis-0 flex-col justify-start items-start gap-1 inline-flex">
<div class="text-center text-gray-900 text-lg font-medium leading-loose"><%= @user.name %></div>
<div class="text-center text-gray-500 text-base font-normal leading-normal"><%= @user.email %></div>
</div>
<%= button_to admin_tenant_group_group_membership_path(Current.tenant, @group_membership.group, @group_membership), method: :delete do %>
<%= render Common::DeleteButtonComponent.new %>
<% if Pundit.policy(Current.user, [:admin, @group_membership]).destroy? %>
<%= button_to admin_tenant_group_group_membership_path(Current.tenant, @group_membership.group, @group_membership), method: :delete do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
<% end %>
19 changes: 0 additions & 19 deletions app/components/admin/tags/external_tags_component.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/components/admin/tags/external_tags_component.rb

This file was deleted.

8 changes: 4 additions & 4 deletions app/components/admin/tags/tag_form_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
<div class="flex flex-col justify-start items-start overflow-hidden rounded-lg bg-white border border-gray-300" style="box-shadow: 1px 1px 4px 0 rgba(0,0,0,0.1);">
<div class="flex justify-start items-center self-stretch flex-grow-0 flex-shrink-0 overflow-hidden gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200">
<div class="flex flex-col justify-start items-start flex-grow relative">
<p class="self-stretch flex-grow-0 flex-shrink-0 text-xl font-semibold text-left text-gray-900"><%= @action == :new ? "Nový štítok" : "Úprava štítku" %></p>
<p class="self-stretch flex-grow-0 flex-shrink-0 text-xl font-semibold text-left text-gray-900"><%= @tag.new_record? ? "Nový štítok" : "Úprava štítku" %></p>
<p class="flex-grow-0 flex-shrink-0 text-xs text-left text-gray-500">Názov štítku</p>
</div>
<%= render Common::CloseButtonComponent.new(link_to: admin_tenant_tags_path(Current.tenant)) %>
</div>
<%= form_with model: [:admin, Current.tenant, @tag] do |form| %>
<%= form_with model: @tag, url: (@tag.new_record? ? admin_tenant_tags_path(Current.tenant) : admin_tenant_tag_path(@tag.tenant, @tag)) do |form| %>
<div class="flex flex-col justify-start items-start self-stretch flex-grow-0 flex-shrink-0 w-400">
<div 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">
<div class="flex flex-col justify-start items-start self-stretch flex-grow overflow-hidden gap-2 rounded-md">
Expand All @@ -20,10 +20,10 @@
</div>
<div class="flex justify-start items-start self-stretch flex-grow-0 flex-shrink-0 gap-2 p-6">
<%= link_to admin_tenant_tags_path(Current.tenant), class: "flex justify-center items-center flex-grow relative overflow-hidden gap-2.5 px-3.5 py-2.5 rounded-md bg-white border border-gray-300", data: { turbo_frame: "_top" } do %>
<p class="flex-grow-0 flex-shrink-0 text-base font-medium text-left text-gray-900"><%= @action == :new ? "Zahodiť" : "Zahodiť zmeny" %></p>
<p class="flex-grow-0 flex-shrink-0 text-base font-medium text-left text-gray-900">Zrušiť</p>
<% end %>
<%= form.button class: "flex justify-center items-center flex-grow relative overflow-hidden gap-2.5 px-3.5 py-2.5 rounded-md bg-blue-600", data: { turbo_frame: "_top" } do %>
<p class="flex-grow-0 flex-shrink-0 text-base font-medium text-left text-white"><%= @action == :new ? "Vytvoriť" : "Uložiť zmeny" %></p>
<p class="flex-grow-0 flex-shrink-0 text-base font-medium text-left text-white"><%= @tag.new_record? ? "Vytvoriť" : "Uložiť zmeny" %></p>
<% end %>
</div>
<% end %>
Expand Down
3 changes: 1 addition & 2 deletions app/components/admin/tags/tag_form_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Admin::Tags::TagFormComponent < ViewComponent::Base
def initialize(tag:, action:)
def initialize(tag:)
@tag = tag
@actio = action
end
end
5 changes: 2 additions & 3 deletions app/components/admin/tags/tags_list_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
<div class="self-stretch bg-white rounded-md border border-gray-200 flex-col justify-start items-start flex">
<div class="self-stretch p-6 border-b border-gray-200 justify-start items-center gap-4 inline-flex">
<div class="grow shrink basis-0 text-gray-900 text-xl font-semibold leading-[35px]">Štítky</div>
<%= 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 %>
<%= link_to new_admin_tenant_tag_path, data: { turbo_frame: "modal" }, class: "px-3.5 py-2.5 bg-blue-600 rounded-md justify-center items-center gap-2.5 flex" do %>
<p class="text-white text-base font-medium leading-normal">Vytvoriť štítok</p>
<% end %>
</div>
<div class="self-stretch flex-col justify-start items-start flex">
<%= render Admin::Tags::TagsListRowComponent.with_collection(@internal_tags) %>
<%= render Admin::Tags::TagsListRowComponent.with_collection(@simple_tags) %>
</div>
</div>
<%= render Admin::Tags::ExternalTagsComponent.new(@external_tags) %>
<div class="self-stretch bg-white rounded-md border border-gray-200 flex-col justify-start items-start flex">
<div class="self-stretch p-6 border-b border-gray-200 justify-start items-center gap-4 inline-flex">
<div class="w-8 h-8 relative">
Expand Down
5 changes: 2 additions & 3 deletions app/components/admin/tags/tags_list_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Admin::Tags::TagsListComponent < ViewComponent::Base
def initialize(external_tags:, internal_tags:)
@external_tags = external_tags
@internal_tags = internal_tags
def initialize(simple_tags:)
@simple_tags = simple_tags
end
end
18 changes: 12 additions & 6 deletions app/components/admin/tags/tags_list_row_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<div class="self-stretch p-6 border-b border-gray-200 justify-start items-center gap-4 inline-flex">
<div class="grow shrink basis-0 flex-col justify-start items-start gap-1 inline-flex">
<div class="text-center text-gray-900 text-lg font-medium leading-loose">
<%= render Common::InlineRenameComponent.new(name: @tag.name, model: [:admin, @tag.tenant, @tag]) %>
<div class="self-stretch p-6 border-b border-gray-200 items-center gap-4 inline-flex">
<div class="grow shrink basis-0 gap-1">
<div class="text-gray-900 text-lg font-medium leading-loose">
<%= tag.turbo_frame id: "tag-name-#{@tag.id}" do %>
<%= render Common::InlineRenameComponent.new(name: @tag.name, model: @tag, url: admin_tenant_tag_path(@tag.tenant, @tag)) %>
<% end %>
<% if @tag.external_name.present? %>
<span class="text-sm text-gray-600 px-2 py-1 rounded-md bg-gray-50 border border-gray-300"><%= @tag.external_name %></span>
<% end %>
</div>
</div>
<%= render Admin::Tags::VisibilityToggleComponent.new(@tag) %>
<div class="justify-start items-start gap-2 flex">
<%= link_to edit_admin_tenant_tag_path(@tag.tenant, @tag) do %>
<%= link_to edit_admin_tenant_tag_path(@tag.tenant, @tag), data: { turbo_frame: "modal" } do %>
<%= render Common::EditButtonComponent.new %>
<% end %>
<%= button_to admin_tenant_tag_path(@tag.tenant, @tag), data: { turbo_confirm: "Naozaj zmazať štítok? Štítok bude zmazaný aj zo všetkých vlákien!" }, method: :delete do %>
<%= button_to admin_tenant_tag_path(@tag.tenant, @tag), method: :delete, data: { turbo_confirm: "Naozaj chcete zmazať štítok '#{@tag.name}'? Štítok bude zmazaný aj zo všetkých vlákien!" } do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<%= tag.turbo_frame id:"@tag-form-visible-#{tag.id}" do %>
<%= form_with model: [:admin, Current.tenant, @tag], method: :patch do |form| %>
<%= form.hidden_field :visible, value:[email protected] %>
<%= 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 %>
<%= tag.turbo_frame id: "tag-form-visible-#{@tag.id}" do %>
<%= form_with model: @tag, url: admin_tenant_tag_path(Current.tenant, @tag), method: :patch do |form| %>
<%= form.hidden_field :visible, value: [email protected] %>
<%= 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: @tag.visible.to_s } do %>
<span class="sr-only">Use setting</span>
<span aria-hidden="true" class="<%= @tag.visible ? "translate-x-5" : "translate-x-0" %> pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"></span>
<% end %>
Expand Down
3 changes: 0 additions & 3 deletions app/components/admin/tags/visibility_toggle_component.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
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
1 change: 1 addition & 0 deletions app/components/admin/users/users_list_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%= render Common::AlertComponent.new %>
<div class="w-full p-4 flex-col justify-start items-start gap-4 inline-flex">
<div class="self-stretch bg-white rounded-md border border-gray-200 flex-col justify-start items-start flex">
<div class="self-stretch p-6 border-b border-gray-200 justify-start items-center gap-4 inline-flex">
Expand Down
6 changes: 4 additions & 2 deletions app/components/admin/users/users_list_row_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
<%= link_to edit_admin_tenant_user_path(@user.tenant, @user) do %>
<%= render Common::EditButtonComponent.new %>
<% end %>
<%= button_to admin_tenant_user_path(@user.tenant, @user), method: :delete do %>
<%= render Common::DeleteButtonComponent.new %>
<% if Pundit.policy(Current.user, [:admin, @user]).destroy? %>
<%= button_to admin_tenant_user_path(@user.tenant, [:admin, @user]), method: :delete do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
<% end %>
</div>
</div>
2 changes: 1 addition & 1 deletion app/components/common/alert_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="fixed top-20 inset-x-0 m-4 z-30">
<div class="fixed top-20 inset-x-0 m-4 z-50">
<div class="flex flex-col items-end space-y-4">
<% flash.each do |type, msg| %>
<div data-controller="dismissible-alert" class="max-w-sm w-full pointer-events-auto rounded-md <%= type == 'notice' ? "bg-green-50" : "bg-red-50" %> p-4">
Expand Down
2 changes: 1 addition & 1 deletion app/components/common/inline_rename_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
>
<div data-action="click->dropdown#toggle click@window->dropdown#hide" role="button" data-dropdown-target="button" tabindex="0" class="inline-block select-none">
<button type="button" class="flex items-center" aria-expanded="false" aria-haspopup="true">
<span class="text-xl font-semibold text-left text-gray-900"><%= @name %></span>
<span class="text-xl text-left text-gray-900"><%= @name %></span>
</button>
</div>
<div data-dropdown-target="menu" class="transform transition hidden scale-95">
Expand Down
14 changes: 9 additions & 5 deletions app/controllers/admin/group_memberships_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Admin::GroupMembershipsController < ApplicationController
before_action :set_group_membership, only: %i[destroy]
# TODO - rediscuss the whole concept of SITE_ADMIN vs TENANT admin responsibilities and functionality
# TODO: - rediscuss the whole concept of SITE_ADMIN vs TENANT admin responsibilities and functionality

def create
# TODO: Takto mi teoreticky moze vzniknut neopravneny membership, lebo nekontrolujem tenanta. Ako spravit tak, aby som nezacal pisat exlpicitne rucne kontroly?
Expand All @@ -17,15 +17,19 @@ def create

def destroy
authorize([:admin, @group_membership])
@group_membership.destroy
redirect_to edit_members_admin_tenant_group_path(Current.tenant, @group_membership.group),
notice: 'Group was membership was successfully deleted'
if @group_membership.destroy
redirect_to edit_members_admin_tenant_group_path(Current.tenant, @group_membership.group),
notice: 'Group was membership was successfully deleted'
else
flash[:alert] = @group_membership.errors.full_messages[0]
redirect_to edit_members_admin_tenant_group_path(Current.tenant, @group_membership.group)
end
end

private

def set_group_membership
@group_membership = policy_scope([:admin,GroupMembership]).find(params[:id])
@group_membership = policy_scope([:admin, GroupMembership]).find(params[:id])
end

def group_membership_params
Expand Down
46 changes: 21 additions & 25 deletions app/controllers/admin/tags_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
class Admin::TagsController < ApplicationController
before_action :set_tag, only: %i[show edit update destroy visibility_toggle]
before_action :set_tag, only: %i[show edit update destroy]

include TagCreation

def index
authorize [:admin, Tag]
tags = policy_scope([:admin, Tag]).order(:name)
tags = policy_scope([:admin, Tag]).includes(:tenant).order(:name)

@external_tags = tags.where(external: true)
@internal_tags = tags.where(external: false)
@simple_tags = tags.simple
end

def show
Expand All @@ -15,56 +16,51 @@ def show
end

def new
@tag = Current.tenant.tags.new
authorize([:admin, @tag])
@tag = SimpleTag.new
authorize(@tag, policy_class: Admin::TagPolicy)
end

def edit
authorize([:admin, @tag])
authorize(@tag, policy_class: Admin::TagPolicy)
end

def create
@tag = Current.tenant.tags.new(tag_params)
@tag.user_id = Current.user.id
authorize([:admin, @tag])
@tag = SimpleTag.new(simple_tag_params.merge(simple_tag_creation_params))
authorize(@tag, policy_class: Admin::TagPolicy)

if @tag.save
redirect_to admin_tenant_tags_path(Current.tenant), notice: 'Tag was successfully created'
redirect_to admin_tenant_tags_path(Current.tenant), notice: "Štítok bol úspešne vytvorený"
else
render :new, status: :unprocessable_entity
end
end

def update
authorize([:admin, @tag])
if @tag.update(tag_params)
redirect_to admin_tenant_tags_path(Current.tenant), notice: 'Tag was successfully updated'
authorize(@tag, policy_class: Admin::TagPolicy)

if @tag.update(simple_tag_params)
redirect_to admin_tenant_tags_path(Current.tenant), notice: "Štítok bol úspešne upravený"
else
render :edit, status: :unprocessable_entity
end
end

def destroy
authorize([:admin, @tag])
authorize(@tag, policy_class: Admin::TagPolicy)
if @tag.destroy
redirect_to admin_tenant_tags_path(Current.tenant), notice: 'Tag was successfully destroyed'
redirect_to admin_tenant_tags_path(Current.tenant), notice: "Štítok bol úspešne odstránený"
else
flash[:alert] = @tag.errors.full_messages[0]
redirect_to admin_tenant_tags_path(Current.tenant)
redirect_to admin_tenant_tags_path(Current.tenant), alert: @tag.errors.full_messages[0]
end
end

private

def set_tag
@tag = Tag.find(params[:id])
end

def tag_params
params.require(:tag).permit(:name, :visible, :user_id, :tenant_id)
@tag = SimpleTag.find(params[:id])
end

def tag_params_visibility
params.permit(:visible)
def simple_tag_params
params.require(:simple_tag).permit(:name, :visible)
end
end
8 changes: 6 additions & 2 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ def update

def destroy
authorize([:admin, @user])
@user.destroy
redirect_to admin_tenant_users_url(Current.tenant), notice: 'User was successfully destroyed'
if @user.destroy
redirect_to admin_tenant_users_url(Current.tenant), notice: 'User was successfully destroyed'
else
flash[:alert] = @user.errors.full_messages[0]
redirect_to admin_tenant_users_url(Current.tenant)
end
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/tag_creation.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module TagCreation
def tag_creation_params
def simple_tag_creation_params
{
owner: Current.user,
tenant: Current.tenant,
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/message_threads/bulk/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def prepare
end

def create_tag
new_tag = Tag.new(tag_creation_params.merge(name: params[:new_tag].strip))
authorize(new_tag, "create?")
new_tag = SimpleTag.new(simple_tag_creation_params.merge(name: params[:new_tag].strip))
authorize(new_tag, "create?", policy_class: TagPolicy)

@tags_changes = TagsChanges.new(
tag_scope: tag_scope,
Expand Down Expand Up @@ -61,7 +61,7 @@ def update
private

def tag_scope
Current.tenant.tags.visible.order(:name)
Current.tenant.simple_tags.visible.order(:name)
end

def message_thread_policy_scope
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/message_threads/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def prepare
end

def create_tag
new_tag = Tag.new(tag_creation_params.merge(name: params[:new_tag].strip))
authorize(new_tag, "create?")
new_tag = SimpleTag.new(simple_tag_creation_params.merge(name: params[:new_tag].strip))
authorize(new_tag, "create?", policy_class: TagPolicy)

@tags_changes = TagsChanges.new(
tag_scope: tag_scope,
Expand Down Expand Up @@ -64,7 +64,7 @@ def set_message_thread
end

def tag_scope
Current.tenant.tags.visible.order(:name)
Current.tenant.simple_tags.visible.order(:name)
end

def message_thread_policy_scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ def perform(govbox_message)

message.update(collapsed: true)

delivery_notification_tag = Tag.find_by!(
system_name: Govbox::Message::DELIVERY_NOTIFICATION_TAG,
tenant: message.thread.box.tenant,
)
delivery_notification_tag = Upvs::DeliveryNotificationTag.find_or_create_for_tenant!(message.thread.box.tenant)

message.tags.delete(delivery_notification_tag) if message.tags.include?(delivery_notification_tag)
unless message.thread.messages.any?(&:can_be_authorized?)
Expand Down
Loading

0 comments on commit edbc7e4

Please sign in to comment.