From 95b9b2aa765feb1ba4a47cef0e027f5d120251c5 Mon Sep 17 00:00:00 2001 From: KennyTV Date: Tue, 14 Jul 2020 20:23:17 +0200 Subject: [PATCH] Form calls --- .../projects/channels/helper/modalManage.ftlh | 10 +++--- .../templates/projects/channels/list.ftlh | 13 ++++---- .../templates/projects/settings.ftlh | 31 ++++++++++--------- .../templates/projects/versions/create.ftlh | 21 +++++++------ .../templates/projects/versions/view.ftlh | 27 ++++++++-------- .../resources/templates/projects/view.ftlh | 10 +++--- .../resources/templates/users/memberList.ftlh | 18 ++++++----- src/main/resources/templates/users/view.ftlh | 19 +++++------- .../resources/templates/utils/editor.ftlh | 16 ++++++---- src/main/resources/templates/utils/form.ftlh | 4 +-- 10 files changed, 91 insertions(+), 78 deletions(-) diff --git a/src/main/resources/templates/projects/channels/helper/modalManage.ftlh b/src/main/resources/templates/projects/channels/helper/modalManage.ftlh index 07248df4e..b110aa56b 100644 --- a/src/main/resources/templates/projects/channels/helper/modalManage.ftlh +++ b/src/main/resources/templates/projects/channels/helper/modalManage.ftlh @@ -1,6 +1,8 @@ <#import "/spring.ftl" as spring /> <#import "*/utils/hangar.ftlh" as hangar /> <#import "*/projects/channels/helper/popoverColorPicker.ftlh" as popoverColorPicker /> +<#import "*/utils/form.ftlh" as form> +<#import "*/utils/csrf.ftlh" as csrf> @import ore.OreConfig @import views.html.helper.{CSRF, form} @@ -16,13 +18,13 @@ - @form(action = routes.Application.showHome()) { - @CSRF.formField + <@form.form action=routes.getRouteUrl("showHome") method="GET"> + <@csrf.formField /> diff --git a/src/main/resources/templates/projects/channels/list.ftlh b/src/main/resources/templates/projects/channels/list.ftlh index 1a028d29a..fd39d9823 100644 --- a/src/main/resources/templates/projects/channels/list.ftlh +++ b/src/main/resources/templates/projects/channels/list.ftlh @@ -1,6 +1,8 @@ <#import "/spring.ftl" as spring /> <#import "*/utils/hangar.ftlh" as hangar /> <#import "*/projects/channels/helper/modalManage.ftlh" as modalManage /> +<#import "*/utils/form.ftlh" as form> +<#import "*/utils/csrf.ftlh" as csrf> @import controllers.sugar.Requests.OreRequest @import models.viewhelper.ProjectData @@ -58,12 +60,11 @@ id="channel-delete-${channel.id}" data-channel-delete="safe-delete" data-channel-id="${channel.id}"> - @form(action = routes.getRouteUrl("channels.delete", - p.project.ownerName, p.project.slug, channel.name), - Symbol("id") -> s"form-delete-${channel.id}", - Symbol("class") -> "form-channel-delete") { - @CSRF.formField - } + <@form.form method="POST" action=routes.getRouteUrl("channels.delete", p.project.ownerName, p.project.slug, channel.name) + id="form-delete-${channel.id}" + class="form-channel-delete"> + <@csrf.formField /> + Delete diff --git a/src/main/resources/templates/projects/settings.ftlh b/src/main/resources/templates/projects/settings.ftlh index 264e5177b..6173cea48 100644 --- a/src/main/resources/templates/projects/settings.ftlh +++ b/src/main/resources/templates/projects/settings.ftlh @@ -1,5 +1,7 @@ <#import "/spring.ftl" as spring /> <#import "*/utils/hangar.ftlh" as hangar /> +<#import "*/utils/form.ftlh" as form> +<#import "*/utils/csrf.ftlh" as csrf> @import controllers.sugar.Requests.OreRequest @import models.viewhelper.{ProjectData, ScopedProjectData} @@ -210,14 +212,13 @@ - @form(action = routes.getRouteUrl("projects.save", p.project.ownerName, p.project.slug), Symbol("id") -> "save", - Symbol("class") -> "pull-right") { - @CSRF.formField + <@form.form action=routes.getRouteUrl("projects.save", p.project.ownerName, p.project.slug) method="POST" id="save" class="pull-right"> + <@csrf.formField /> - } + @@ -249,13 +250,13 @@ @@ -271,19 +272,19 @@ - @form(action = routes.getRouteUrl("projects.softDelete", p.project.ownerName, p.project.slug)) { + <@form.form action=routes.getRouteUrl("projects.softDelete", p.project.ownerName, p.project.slug) method="POST"> - } + diff --git a/src/main/resources/templates/projects/versions/create.ftlh b/src/main/resources/templates/projects/versions/create.ftlh index 193635b28..fe9000972 100644 --- a/src/main/resources/templates/projects/versions/create.ftlh +++ b/src/main/resources/templates/projects/versions/create.ftlh @@ -1,6 +1,8 @@ <#import "/spring.ftl" as spring /> <#import "*/utils/hangar.ftlh" as hangar /> <#import "*/layout/base.ftlh" as base /> +<#import "*/utils/form.ftlh" as form> +<#import "*/utils/csrf.ftlh" as csrf> @import controllers.sugar.Requests.OreRequest @import models.querymodels.ViewTag @@ -148,32 +150,31 @@ } - @form(action = routes.getRouteUrl("versions.upload", ownerName, projectSlug), - Symbol("enctype") -> "multipart/form-data", Symbol("id") -> "form-upload") { - @CSRF.formField + <@form.form action=routes.getRouteUrl("versions.upload", ownerName, projectSlug) method="POST" + enctype="multipart/form-data" id="form-upload"> + <@csrf.formField /> ${projects.helper.alertFile()} - } + <#if pending??> @* Ready to go! *@ @defining(pending.get) { version: PendingVersion => - @form(action = routes.getRouteUrl("versions.publish", - ownerName, projectSlug, version.versionString), - Symbol("id") -> "form-publish", Symbol("class") -> "pull-right") { - @CSRF.formField + <@form.form method="POST" action=routes.getRouteUrl("versions.publish", ownerName, projectSlug, version.versionString) + id="form-publish" class="pull-right"> + <@csrf.formField /> + value="${config.defaultChannelColor.hex}" />
" class="btn btn-primary" />
- } + } diff --git a/src/main/resources/templates/projects/versions/view.ftlh b/src/main/resources/templates/projects/versions/view.ftlh index 81986d9fe..8b8c26b15 100644 --- a/src/main/resources/templates/projects/versions/view.ftlh +++ b/src/main/resources/templates/projects/versions/view.ftlh @@ -1,5 +1,7 @@ <#import "/spring.ftl" as spring /> <#import "*/utils/hangar.ftlh" as hangar /> +<#import "*/utils/form.ftlh" as form> +<#import "*/utils/csrf.ftlh" as csrf> @import controllers.sugar.Requests.OreRequest @import models.viewhelper.{ScopedProjectData, VersionData} @@ -69,13 +71,12 @@
<#if !v.isRecommended && sp.perms(Permission.EditVersion) && v.v.visibility != Visibility.SoftDelete> - @form(action = versionRoutes.setRecommended( - v.p.project.ownerName, v.p.project.slug, v.v.versionString), Symbol("class") -> "form-inline") { - @CSRF.formField + <@form.form method="POST" action=routes.getRouteUrl("versions.setRecommended", v.p.project.ownerName, v.p.project.slug, v.v.versionString) class="form-inline"> + <@csrf.formField /> - } + <#if request.headerData.globalPerm(Permission.Reviewer)> @@ -233,21 +234,21 @@
- @form(action = versionRoutes.softDelete(v.p.project.ownerName, v.p.project.slug, v.v.versionString)) { + <@form.form method="POST" action=routes.getRouteUrl("versions.softDelete", v.p.project.ownerName, v.p.project.slug, v.v.versionString)> - } + @@ -264,20 +265,20 @@ - @form(action = versionRoutes.restore(v.p.project.ownerName, v.p.project.slug, v.v.versionString)) { + <@form.form method="POST" action=routes.getRouteUrl("versions.restore", v.p.project.ownerName, v.p.project.slug, v.v.versionString)> - } + @@ -292,20 +293,20 @@ - @form(action = versionRoutes.delete(v.p.project.ownerName, v.p.project.slug, v.v.versionString)) { + <@form.form method="POST" action=routes.getRouteUrl("versions.delete", v.p.project.ownerName, v.p.project.slug, v.v.versionString)> - } + diff --git a/src/main/resources/templates/projects/view.ftlh b/src/main/resources/templates/projects/view.ftlh index cf69dfb06..72aac6773 100644 --- a/src/main/resources/templates/projects/view.ftlh +++ b/src/main/resources/templates/projects/view.ftlh @@ -140,9 +140,11 @@ TODO: this is a layout, should we move/rename it? - @form(action = Projects.flag( - p.project.ownerName, p.project.slug)) { - @CSRF.formField + <#import "*/utils/form.ftlh" as form> + <#-- todo: Projects.flag --> + <@form.form action=Projects.flag( p.project.ownerName, p.project.slug)> + <#import "*/utils/csrf.ftlh" as csrf> + <@csrf.formField /> - } + diff --git a/src/main/resources/templates/users/memberList.ftlh b/src/main/resources/templates/users/memberList.ftlh index 6a2d1f0e7..99daa10fa 100644 --- a/src/main/resources/templates/users/memberList.ftlh +++ b/src/main/resources/templates/users/memberList.ftlh @@ -1,5 +1,7 @@ <#import "/spring.ftl" as spring /> <#import "*/utils/hangar.ftlh" as hangar /> +<#import "*/utils/form.ftlh" as form> +<#import "*/utils/csrf.ftlh" as csrf> @import ore.OreConfig @import ore.models.user.role.UserRoleModel @@ -49,14 +51,15 @@ @@ -81,13 +84,14 @@ <#if saveCall??> - @form(action = saveCall, Symbol("id") -> "save") { - @CSRF.formField + <#-- todo: saveCall, gotten from settings template --> + <@form.form action=saveCall method="POST" id="save"> + <@csrf.formField /> - } + @@ -99,7 +103,7 @@
  • @userAvatar(Some(user.name), user.avatarUrl, clazz = "user-avatar-xs") - @user.name + ${user.name} <#if editable && perms.has(Permission.ManageSubjectMembers) && !role.role.permissions.has(Permission.IsOrganizationOwner)> diff --git a/src/main/resources/templates/users/view.ftlh b/src/main/resources/templates/users/view.ftlh index e66b942e2..6ac04deb2 100644 --- a/src/main/resources/templates/users/view.ftlh +++ b/src/main/resources/templates/users/view.ftlh @@ -4,6 +4,8 @@ <#import "*/utils/modal.ftlh" as modal /> <#import "*/utils/prompt.ftlh" as prompt /> <#import "*/utils/userAvatar.ftlh" as userAvatar /> +<#import "*/utils/form.ftlh" as form> +<#import "*/utils/csrf.ftlh" as csrf> <#-- @(u: UserData, o: Option[(OrganizationData, ScopedOrganizationData)], additionalScripts: Html = Html(""))(content: Html)(implicit messages: Messages, flash: Flash, request: OreRequest[_], config: OreConfig, assetsFinder: AssetsFinder) @@ -160,21 +162,16 @@ <@modal.modal "user.tagline.edit" "modal-tagline" "label-tagline"> - @form(action = routes.Users.saveTagline(u.user.name)) { - @CSRF.formField + <@form.form action=routes.getRouteUrl("users.saveTagline", u.user.name) method="POST"> + <@csrf.formField /> @@ -94,12 +97,13 @@ <#if savable> - @form(action = saveCall, Symbol("id") -> "form-editor-save") { - @CSRF.formField + <#-- todo: where does this come from ._. --> + <@form.form action=saveCall id="form-editor-save"> + <@csrf.formField /> <#if extraFormValue??> - } + diff --git a/src/main/resources/templates/utils/form.ftlh b/src/main/resources/templates/utils/form.ftlh index dd7e0fbff..64af656e5 100644 --- a/src/main/resources/templates/utils/form.ftlh +++ b/src/main/resources/templates/utils/form.ftlh @@ -1,5 +1,5 @@ -<#macro form action method id=""> -
    id="${id}"> +<#macro form action method id="" class="" enctype=""> + id="${id}" <#if class??>class="${class}" <#if enctype??>enctype="${enctype}"> <#nested>