diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 742ce33..448b9e2 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -323,4 +323,28 @@ @current = Template.current(@template.dmptemplate_id) end + # PUT /org/admin/templates/:id/admin_copy + # ----------------------------------------------------- + def admin_copy + @template = Template.find(params[:id]) + authorize @template + + new_copy = Template.deep_copy(@template) + new_copy.title = "Copy of " + @template.title + new_copy.version = 0 + new_copy.published = false + new_copy.dmptemplate_id = loop do + random = rand 2147483647 + break random unless Template.exists?(dmptemplate_id: random) + end + + if new_copy.save + flash[:notice] = 'Template was successfully copied.' + redirect_to admin_template_template_path(id: new_copy.id, edit: true), notice: _('Information was successfully created.') + else + flash[:alert] = failed_create_error(new_copy, _('template')) + end + + end + end diff --git a/app/policies/template_policy.rb b/app/policies/template_policy.rb index 754e622..006ed23 100644 --- a/app/policies/template_policy.rb +++ b/app/policies/template_policy.rb @@ -57,6 +57,9 @@ user.can_modify_templates? end + def admin_copy? + user.can_modify_templates? && (template.org_id == user.org_id) + end class Scope < Scope def resolve @@ -64,4 +67,4 @@ end end -end \ No newline at end of file +end diff --git a/app/views/contact_us/contacts/new.html.erb b/app/views/contact_us/contacts/new.html.erb index 05ceef9..985a32f 100644 --- a/app/views/contact_us/contacts/new.html.erb +++ b/app/views/contact_us/contacts/new.html.erb @@ -16,36 +16,31 @@