diff --git a/decidim-admin/app/commands/decidim/admin/create_share_token.rb b/decidim-admin/app/commands/decidim/admin/create_share_token.rb index 0d55b66b18fdf..6de1ebf80aa11 100644 --- a/decidim-admin/app/commands/decidim/admin/create_share_token.rb +++ b/decidim-admin/app/commands/decidim/admin/create_share_token.rb @@ -4,12 +4,44 @@ module Decidim module Admin # A command with all the business logic to create a taxonomy. # This command is called from the controller. - class CreateShareToken < Decidim::Commands::CreateResource - fetch_form_attributes :token, :expires_at, :registered_only, :organization, :user, :token_for + class CreateShareToken < Decidim::Command + # Public: Initializes the command. + # + # form - A form object with the params. + def initialize(form) + @form = form + end - protected + # Executes the command. Broadcasts these events: + # + # - :ok when everything is valid. + # - :invalid if the form wasn't valid and we couldn't proceed. + # + # Returns nothing. + def call + return broadcast(:invalid) if form.invalid? - def resource_class = Decidim::ShareToken + create_share_token + broadcast(:ok) + end + + private + + attr_reader :form + + def create_share_token + Decidim.traceability.create!( + ShareToken, + form.user, + { + token: form.token, + expires_at: form.expires_at, + token_for: form.token_for, + organization: form.organization, + user: form.user + } + ) + end end end end diff --git a/decidim-admin/app/views/decidim/admin/share_tokens/index.html.erb b/decidim-admin/app/views/decidim/admin/share_tokens/index.html.erb index e56b76f57cec8..316ebc3a31c2e 100644 --- a/decidim-admin/app/views/decidim/admin/share_tokens/index.html.erb +++ b/decidim-admin/app/views/decidim/admin/share_tokens/index.html.erb @@ -1,45 +1,58 @@ +<% add_decidim_page_title(t(".title", name: resource_title)) %>
<%= t(".share_tokens_help", clipboard: icon("clipboard-line", class: "inline-block mb-1")).html_safe %>
-<%= sort_link(query, :token, t("models.share_token.fields.token", scope: "decidim.admin"), default_order: :desc) %> | -<%= sort_link(query, :expires_at, t("models.share_token.fields.expires_at", scope: "decidim.admin"), default_order: :desc) %> | -<%= sort_link(query, :registered_only, t("models.share_token.fields.registered_only", scope: "decidim.admin"), default_order: :desc) %> | -<%= sort_link(query, :times_used, t("models.share_token.fields.times_used", scope: "decidim.admin"), default_order: :desc) %> | -<%= t("models.share_token.fields.actions", scope: "decidim.admin") %> | -
---|
<%= share_token.token %> | -<%= share_token.expires_at.present? ? ("#{l(share_token.expires_at, format: :decidim_short)}".html_safe) : content_tag(:em, t(".never")) %> | -<%= t("booleans.#{share_token.registered_only.present?}") %> | -<%= share_token.times_used %> | -- <%= icon_link_to "pencil-line", share_tokens_path(:edit, id: share_token ), t("actions.edit", scope: "decidim.admin.share_tokens"), class: "action-icon--edit" %> - <%= icon_link_to "clipboard-line", "#", t("actions.copy_link", scope: "decidim.admin.share_tokens"), class: "action-icon--copy", data: { "clipboard-copy" => "#js-token-#{share_token.id}", "clipboard-content" => share_token.url,"clipboard-copy-label" => t(".copied"),"clipboard-copy-message" => t(".copy_message") } %> - <%= 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_tokens_path(:destroy, 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") } %> - | +<%= sort_link(query, :token, t("models.share_token.fields.token", scope: "decidim.admin"), default_order: :desc) %> | +<%= sort_link(query, :expires_at, t("models.share_token.fields.expires_at", scope: "decidim.admin"), default_order: :desc) %> | +<%= sort_link(query, :registered_only, t("models.share_token.fields.registered_only", scope: "decidim.admin"), default_order: :desc) %> | +<%= sort_link(query, :times_used, t("models.share_token.fields.times_used", scope: "decidim.admin"), default_order: :desc) %> | +<%= t("models.share_token.fields.actions", scope: "decidim.admin") %> |
---|
<%= t(".empty", new_token_link: link_to(t(".create_new_token"), share_tokens_path(:new) , class: "button button__text-secondary")).html_safe %>
- <% end %> + + + <% @share_tokens.each do |share_token| %> +<%= t(".empty", new_token_link: link_to(t(".create_new_token"), share_tokens_path(:new) , class: "")).html_safe %>
+ <% end %> +