Skip to content

Commit

Permalink
add edit and update method to controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ElviaBth committed Jul 15, 2024
1 parent d3e8266 commit 0ac71f5
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2 deletions.
11 changes: 11 additions & 0 deletions decidim-admin/app/commands/decidim/admin/update_share_token.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Decidim
module Admin
# A command with all the business logic to create a taxonomy.
# This command is called from the controller.
class UpdateShareToken < Decidim::Commands::UpdateResource
fetch_form_attributes :token, :expires_at, :organization, :user, :token_for
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ def create
end
end

def edit
@form = form(ShareTokenForm).from_model(share_token)
end

def update
@form = form(ShareTokenForm).from_params(params, component:)

UpdateShareToken.call(@form) do
on(:ok) do
flash[:notice] = I18n.t("share_tokens.update.success", scope: "decidim.admin")
redirect_to share_tokens_path(component)
end

on(:invalid) do
flash.now[:alert] = I18n.t("share_tokens.update.error", scope: "decidim.admin")
render :edit
end
end
end

def destroy
enforce_permission_to(:destroy, :share_token, share_token:)

Expand Down
20 changes: 20 additions & 0 deletions decidim-admin/app/views/decidim/admin/share_tokens/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<% add_decidim_page_title(t(".title")) %>
<div class="item_show__header">
<h1 class="item_show__header-title">
<%= t ".title", component_name: translated_attribute(component.name) %>
</h1>
</div>
<div class="item__edit-form">
<%= decidim_form_for(@form, html: { class: "form-defaults form edit_component_share_token" }) do |f| %>
<div class="card">
<div class="card-section">
<%= render partial: "form", object: f %>
</div>
</div>
<div class="item__edit-sticky">
<div class="item__edit-sticky-container">
<%= f.submit t(".update"), class: "button button__sm button__secondary" %>
</div>
</div>
<% end %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<td></td>
<td><%= share_token.times_used %></td>
<td class="table-list__actions">
<%= icon_link_to "pencil-line", share_token.url, t("actions.edit", scope: "decidim.admin.share_tokens"), class: "action-icon--edit", target: :blank %>
<%= icon_link_to "pencil-line", edit_component_share_token_path(id: share_token ), t("actions.edit", scope: "decidim.admin.share_tokens"), class: "action-icon--edit", target: :blank %>
<%= icon_link_to "file-copy-line", share_token.url, t("actions.copy_link", scope: "decidim.admin.share_tokens"), class: "action-icon--share", target: :blank %>
<%= icon_link_to "eye-line", share_token.url, t("actions.preview", scope: "decidim.admin.share_tokens"), class: "action-icon--preview", target: :blank %>
<%= icon_link_to "delete-bin-line", share_token_path(component, id: share_token ), t("actions.destroy", scope: "decidim.admin.share_tokens"), class: "action-icon--remove", method: :delete, data: { confirm: t("actions.confirm_destroy", scope: "decidim.admin.share_tokens") } %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</h1>
</div>
<div class="item__edit-form">
<%= decidim_form_for(@form, url: share_tokens_path(component), html: { class: "form-defaults form ew_component_share_token" }) do |f| %>
<%= decidim_form_for(@form, url: share_tokens_path(component), html: { class: "form-defaults form new_component_share_token" }) do |f| %>
<div class="card">
<div class="card-section">
<%= render partial: "form", object: f %>
Expand Down
6 changes: 6 additions & 0 deletions decidim-admin/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@ en:
destroy:
error: There was a problem destroying the token.
success: Token destroyed successfully.
edit:
title: 'Edit sharing tokens for component: %{component_name}'
update: Update
form:
automatic: Automatic
custom: Custom
Expand All @@ -987,6 +990,9 @@ en:
empty: There are no active tokens.
help: These tokens are used to publicly share this unpublished resource to any user. They will be hidden when the resource is published. Click on the token's share icon to visit the shareable URL.
title: Share tokens
update:
invalid: There was a problem updating the token.
success: Token updated successfully.
shared:
adjacent_navigation:
next: Next
Expand Down

0 comments on commit 0ac71f5

Please sign in to comment.