Skip to content

Commit

Permalink
Allow drafts "unsiging"
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-rl committed Dec 4, 2023
1 parent 61f1f0b commit 1a53af3
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 33 deletions.
5 changes: 2 additions & 3 deletions app/components/message_draft_body_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
<div class="flex flex-col justify-stretch items-start relative gap-4 p-6 border-t-0 border-r-0 border-b border-l-0 border-gray-200">
<% if @message.custom_visualization? %>
<% message_title_id = dom_id(@message, :title)
message_text_id = dom_id(@message, :text)
%>
message_text_id = dom_id(@message, :text) %>
<%= content_tag(:div,
{
"data-controller": "message-drafts",
Expand All @@ -43,7 +42,7 @@
<%= text_field_tag message_title_id, @message.title, placeholder: "Predmet", "data-action": "change->message-drafts#update", class: "mb-3 px-3 py-4 placeholder-slate-300 text-slate-900 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_id, @message.metadata["message_body"], autofocus: @is_last, placeholder: "Text", "data-action": "change->message-drafts#update", rows: 10, class: "px-3 py-4 placeholder-slate-300 text-slate-900 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full h-full" %>
<% else %>
<%= link_to enable_edit_message_draft_path(@message), data: { turbo_frame: "modal" } do %>
<%= link_to locked_message_draft_path(@message), data: { turbo_frame: "modal" } do %>
<%= text_field_tag message_title_id, @message.title, placeholder: "Predmet", readonly: true, class: "mb-3 px-3 py-4 placeholder-slate-300 text-slate-900 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_id, @message.metadata["message_body"], autofocus: @is_last, readonly: true, placeholder: "Text", rows: 10, class: "px-3 py-4 placeholder-slate-300 text-slate-900 relative bg-white bg-white rounded-lg text-base border-0 shadow outline-none focus:outline-none focus:ring w-full h-full" %>
<% end %>
Expand Down
16 changes: 0 additions & 16 deletions app/components/message_draft_enable_edit_component.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/components/message_draft_enable_edit_component.rb

This file was deleted.

25 changes: 25 additions & 0 deletions app/components/message_draft_locked_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<%= render Common::ModalComponent.new do |modal| %>
<% modal.with_header do %>
Draft nie je možné upravovať
<% end %>
<% modal.with_modal_content do %>
<div class="mt-2">
<p class="text-sm text-gray-500">
<% if @message.reason_for_readonly == :form_signed %>
<%= t "message_draft.form_signed" %>
<% elsif @message.reason_for_readonly == :form_submitted %>
<%= t "message_draft.form_submitted" %>
<% else %>
<%= t "message_draft.read_only_agenda" %>
<% end %>
</p>
</div>
<%= render Common::ModalActionsComponent.new do |actions| %>
<% if @message.reason_for_readonly == :form_signed %>
<% actions.with_submit_button do %>
<%= link_to 'Odstrániť podpisy', enable_edit_message_draft_path(@message), class: 'flex justify-center items-center px-2.5 py-1.5 rounded-md bg-blue-600 text-sm font-medium text-white', data: { turbo_frame: "_top" } %>
<% end %>
<% end %>
<% end %>
<% end %>
<% end %>
5 changes: 5 additions & 0 deletions app/components/message_draft_locked_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class MessageDraftLockedComponent < ViewComponent::Base
def initialize(message)
@message = message
end
end
9 changes: 9 additions & 0 deletions app/controllers/message_drafts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ def destroy

def enable_edit
authorize @message
if @message.remove_form_signature
redirect_to message_thread_path(@message.thread), notice: "Podpisy boli úspešne odstránené, správu je možné upravovať"
else
redirect_to message_thread_path(@message.thread), alert: "Nastala neočakávaná chyba, nepodarilo sa odstrániť podpisy"
end
end

def locked
authorize @message
end

private
Expand Down
6 changes: 6 additions & 0 deletions app/models/message_draft.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ def original_message
Message.find(metadata["original_message_id"]) if metadata["original_message_id"]
end

def remove_form_signature
return false unless form

form.remove_signature
end

private

def validate_metadata
Expand Down
16 changes: 11 additions & 5 deletions app/models/message_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,18 @@ def destroyable?
message.draft? && message.not_yet_submitted? && !form?
end

def asice?
mimetype == 'application/vnd.etsi.asic-e+zip'
end
def remove_signature
return false unless form?
return false unless is_signed

def destroyable?
message.draft? && message.not_yet_submitted? && !form?
unsigned_object = nested_message_objects&.first
return false unless unsigned_object

transaction do
update(name: unsigned_object.name, mimetype: unsigned_object.mimetype, is_signed: false)
message_object_datum.update(blob: unsigned_object.content)
unsigned_object.destroy
end
end

private
Expand Down
4 changes: 4 additions & 0 deletions app/policies/message_draft_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def destroy?
create?
end

def locked?
enable_edit?
end

def enable_edit?
create?
end
Expand Down
3 changes: 0 additions & 3 deletions app/views/message_drafts/enable_edit.html.erb

This file was deleted.

3 changes: 3 additions & 0 deletions app/views/message_drafts/locked.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= tag.turbo_frame id: "modal" do %>
<%= render MessageDraftLockedComponent.new(@message) %>
<% end %>
2 changes: 1 addition & 1 deletion config/locales/sk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,6 @@ sk:
one: "Úprava štítkov v jednom vlákne"
other: "Úprava štítkov v %{count} vláknach"
message_draft:
form_signed: "Draftbol podpísaný. Podpísaný draft nie je možné ďalej upravovať. V prípade potreby pripravte novú správu a odošlite ju."
form_signed: "Správabola podpísaná. Podpísanú správu nie je možné ďalej upravovať. V prípade potreby zmien kliknite na tlačidlo Odstrániť podpisy. Všetky podpisy budú odstránené, správu bude ďalej možné upravovať. Následne ju bude potrebné znova podpísať."
form_submitted: "Správa už bola odoslaná. Odoslanú správu nie je možné ďalej upravovať. V prípade potreby pripravte novú správu a odošlite ju."
read_only_agenda: "Správu nie je možné ďalej upravovať. V prípade potreby pripravte novú správu a odošlite ju."
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@

resources :message_drafts do
member do
get 'locked'
get 'enable_edit'
post 'submit'
end
Expand Down

0 comments on commit 1a53af3

Please sign in to comment.