Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/solver-it-sro/govbox-pro in…
Browse files Browse the repository at this point in the history
…to GO-200/admin_others_target_UX
  • Loading branch information
stage-rl committed Sep 12, 2023
2 parents 1cfe7dc + a14d6f1 commit 6a196f2
Show file tree
Hide file tree
Showing 75 changed files with 856 additions and 638 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ yarn-debug.log*
.yarn-integrity

.env.local
.env.test

/app/assets/builds/*
!/app/assets/builds/.keep
2 changes: 1 addition & 1 deletion app/components/layout/message_thread_sidebar_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Layout::MessageThreadSidebarComponent < ViewComponent::Base
def initialize(message:)
@selected_message = message
@thread_messages = @selected_message.thread.messages.order(delivered_at: :desc)
@thread_messages = @selected_message.thread.messages_visible_to_user(Current.user).order(delivered_at: :asc)
end
end
18 changes: 11 additions & 7 deletions app/components/message_drafts_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@
</div>
</div>

<%= form_tag message_draft_path(@message), method: :put, class: "w-full", id: "reply_form" do %>
<div class="flex flex-col justify-strech items-start self-stretch flex-grow-0 flex-shrink-0 relative gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200">
<div class="mb-3 pt-0 w-full">
<%= text_field_tag "message_title", @message.title, placeholder: "Predmet", onchange: 'document.getElementById("reply_form").submit();', disabled: !@message.not_yet_submitted?, class:"mb-3 px-3 py-4 placeholder-slate-300 text-slate-í00 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full" %>
<%= text_area_tag "message_text", @message.metadata["message_body"], placeholder: "Text", onchange: 'document.getElementById("reply_form").submit();', rows: 10, disabled: !@message.not_yet_submitted?, class:"px-3 py-4 placeholder-slate-300 text-slate-í00 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full h-full" %>
<% if @message.custom_visualization? %>
<%= form_tag message_draft_path(@message), method: :put, class: "w-full", id: "reply_form" do %>
<div class="flex flex-col justify-strech items-start self-stretch flex-grow-0 flex-shrink-0 relative gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200">
<div class="mb-3 pt-0 w-full">
<%= text_field_tag "message_title", @message.title, placeholder: "Predmet", onchange: 'document.getElementById("reply_form").submit();', disabled: !@message.editable?, class:"mb-3 px-3 py-4 placeholder-slate-300 text-slate-í00 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full" %>
<%= text_area_tag "message_text", @message.metadata["message_body"], placeholder: "Text", onchange: 'document.getElementById("reply_form").submit();', rows: 10, disabled: !@message.editable?, class:"px-3 py-4 placeholder-slate-300 text-slate-í00 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full h-full" %>
</div>
</div>
</div>
<% end %>
<% end %>
<% else %>
<%= @message.html_visualization&.html_safe %>
<% end %>

<% if @message.not_yet_submitted? || @message.objects.present? %>
<div class="border-b w-full">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>
</div>
</div>
<%= link_to message_path(@message_thread.last_message_id), class:"flex justify-stretch overflow-clip items-center grow gap-2" do %>
<%= link_to @message_thread, class:"flex justify-stretch overflow-clip items-center grow gap-2" do %>
<div class="flex flex-col truncate justify-start items-stretch grow gap-1">
<p title="<%= @message_thread.title%>" class="truncate text-lg text-gray-900 <%="font-semibold" unless @message_thread.read? %>"><%= @message_thread.title %></p>
<p class="text-base text-left text-gray-500"><%= @message_thread.with_whom %></p>
Expand Down
10 changes: 2 additions & 8 deletions app/components/settings/rules/condition_form_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ def initialize(form:, index:, enabled: true)

def before_render
@condition_type_list = Automation::Condition.subclasses.map { |subclass| [t(subclass.name), subclass.name] }
# TODO: Toto som chcel vytiahnut ako ENUM, nepodarilo sa
@attr_list = [
[t('sender_name'), 'sender_name'],
[t('recipient_name'), 'recipient_name'],
[t('sender_uri'), 'sender_uri'],
[t('recipient_uri'), 'recipient_uri']
]
@attr_list = Automation::Condition::ATTR_LIST.map { |attr| [t(attr), attr] }
end
end
end
1 change: 1 addition & 0 deletions app/controllers/admin/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def index

def show
authorize([:admin, @group])
@other_tags = other_tags
end

def new
Expand Down
30 changes: 30 additions & 0 deletions app/controllers/admin/tag_groups_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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

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."
end

def destroy
authorize([:admin, @tag_group])
@tag_group.destroy
redirect_back fallback_location:"/", notice: "Tag permission was successfully destroyed."
end

private

def set_tag_group
@tag_group = policy_scope([:admin, TagGroup]).find(params[:id])
end

# Only allow a list of trusted parameters through.
def tag_group_params
params.require(:tag_group).permit(:tag_id, :group_id)
end
end
44 changes: 0 additions & 44 deletions app/controllers/drafts_controller.rb

This file was deleted.

44 changes: 28 additions & 16 deletions app/controllers/message_drafts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
class MessageDraftsController < ApplicationController
before_action :set_message, only: :create
before_action :set_message_draft, except: :create
before_action :load_message_drafts, only: [:index, :submit_all]
before_action :load_message, only: :create
before_action :load_draft, except: [:index, :create, :submit_all]

def index
@message_drafts = @message_drafts.order(created_at: :desc)
end

def create
authorize @message

@message_draft = MessageDraft.create_from_message(@message)
@message_draft = MessageDraft.create_message_reply(original_message: @message, author: Current.user)

redirect_to message_draft_path(@message_draft)
end
Expand All @@ -20,40 +25,47 @@ def update

permitted_params = message_params

@message_draft.title = permitted_params["message_title"]
@message_draft.metadata["message_body"] = permitted_params["message_text"]
@message_draft.save!
@message_draft.update_content(title: permitted_params["message_title"], body: permitted_params["message_text"])
end

def submit
authorize @message_draft

if @message_draft.submittable?
Govbox::SubmitMessageDraftJob.perform_later(@message_draft)

@message_draft.metadata["status"] = "being_submitted"
@message_draft.save!

redirect_to message_path(@message_draft.original_message), notice: "Správa bola zaradená na odoslanie."
if @message_draft.submit
redirect_path = @message_draft.original_message.present? ? message_path(@message_draft.original_message) : message_drafts_path
redirect_to redirect_path, notice: "Správa bola zaradená na odoslanie."
else
# TODO prisposobit chybovu hlasku aj importovanym draftom
redirect_to message_draft_path(@message_draft), notice: "Vyplňte predmet a text odpovede."
end
end

def submit_all
@message_drafts.each(&:submit)
end

def destroy
authorize @message_draft

redirect_path = @message_draft.original_message.present? ? message_path(@message_draft.original_message) : message_drafts_path

@message_draft.destroy
redirect_to message_path(@message_draft.original_message)

redirect_to redirect_path
end

private

def set_message
def load_message_drafts
authorize MessageDraft
@message_drafts = policy_scope(MessageDraft)
end

def load_message
@message = policy_scope(Message).find(params[:original_message_id])
end

def set_message_draft
def load_draft
@message_draft = policy_scope(MessageDraft).find(params[:id])
@menu = SidebarMenu.new(controller_name, action_name, { message: @message_draft })
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
class Drafts::ImportsController < ApplicationController
class MessageDraftsImportsController < ApplicationController
def create
authorize Drafts::Import, policy_class: Drafts::ImportPolicy
authorize MessageDraftsImport

file_storage = FileStorage.new

zip_content = params[:content]
import = Drafts::Import.create!(
import = MessageDraftsImport.create!(
name: "#{Time.now.to_i}_#{zip_content.original_filename}",
box: Current.box
)

import_path = file_storage.store("imports", import_path(import), zip_content.read.force_encoding("UTF-8"))
Drafts::ParseImportJob.perform_later(import, import_path)

redirect_to drafts_path
redirect_to message_drafts_path
end

def upload_new
authorize Drafts::Import, policy_class: Drafts::ImportPolicy
authorize MessageDraftsImport
end

private
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/message_threads_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class MessageThreadsController < ApplicationController
before_action :set_message_thread, only: %i[show, update]
before_action :set_message_thread, only: %i[show update]

def show
authorize @message_thread

redirect_to @message_thread.messages.where(read: false).order(delivered_at: :asc).first || @message_thread.messages_visible_to_user(Current.user).order(delivered_at: :desc).first
end

def update
Expand Down Expand Up @@ -50,7 +52,7 @@ def merge
end
@selected_message_threads.merge_threads
flash[:notice] = 'Vlákna boli úspešne spojené'
redirect_to @selected_message_threads.first.messages.first
redirect_to @selected_message_threads.first
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/settings/automation_actions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def create
authorize @automation_rule, policy_class: Settings::AutomationRulePolicy
end

def edit
def edit_form
authorize @automation_rule, policy_class: Settings::AutomationRulePolicy
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def create
authorize @automation_rule, policy_class: Settings::AutomationRulePolicy
end

def edit
def edit_form
authorize @automation_rule, policy_class: Settings::AutomationRulePolicy
end

Expand Down
10 changes: 6 additions & 4 deletions app/jobs/drafts/finish_import_job.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
class Drafts::FinishImportJob < ApplicationJob
def perform(batch, params)
batch.properties[:import].drafts.find_each do |draft|
if draft.valid?(:validate_data)
draft.loading_done!
batch.properties[:import].message_drafts.find_each do |message_draft|
if message_draft.valid?(:validate_data)
message_draft.metadata["status"] = "created"
else
draft.invalid_data!
message_draft.metadata["status"] = "invalid"
end

message_draft.save
end

Utils.delete_file(batch.properties[:zip_path])
Expand Down
Loading

0 comments on commit 6a196f2

Please sign in to comment.