From f7447bf1a961e41719c82358ea51ec5eb867d67e Mon Sep 17 00:00:00 2001 From: Seb Duggan Date: Tue, 3 Dec 2024 12:33:13 +0000 Subject: [PATCH 1/3] [twgit] Init feature 'feature-PRESIDECMS-2976_formbuilder-without-websiteusers-feature'. From 585876f4cfa0fea80d3916899b3783585de85792 Mon Sep 17 00:00:00 2001 From: Seb Duggan Date: Tue, 3 Dec 2024 12:36:56 +0000 Subject: [PATCH 2/3] PRESIDECMS-2976 Ensure formbuilder works when websiteUsers feature not enabled --- system/handlers/admin/FormBuilder.cfc | 11 ++ .../formbuilder_question_response.cfc | 4 +- .../formbuilder/FormBuilderFilterService.cfc | 4 +- .../formbuilder/FormBuilderService.cfc | 152 +++++++++++------- .../views/admin/formbuilder/submissions.cfm | 14 +- .../admin/formbuilder/viewSubmission.cfm | 14 +- .../_submissionHtml.cfm | 8 +- .../_submissionText.cfm | 4 +- 8 files changed, 133 insertions(+), 78 deletions(-) diff --git a/system/handlers/admin/FormBuilder.cfc b/system/handlers/admin/FormBuilder.cfc index 291ce9d2ad..728f2137f9 100644 --- a/system/handlers/admin/FormBuilder.cfc +++ b/system/handlers/admin/FormBuilder.cfc @@ -383,6 +383,9 @@ component extends="preside.system.base.AdminHandler" { var theQuestion = formBuilderService.getQuestion( questionId ); + if ( !isFeatureEnabled( "websiteUsers" ) ) { + exportFields = ListDeleteAt( exportFields, ListFind( exportFields, "submitted_by" ) ); + } if ( !theQuestion.recordCount ) { event.adminNotFound(); } @@ -415,6 +418,10 @@ component extends="preside.system.base.AdminHandler" { var exportFields = args.exportFields ?: "id,submission_type,submission_reference,submitted_by,datecreated,is_website_user,parent_name"; var exporter = args.exporter ?: "Excel" + if ( !isFeatureEnabled( "websiteUsers" ) ) { + exportFields = ListDeleteAt( exportFields, ListFind( exportFields, "submitted_by" ) ); + } + formBuilderService.exportQuestionResponses( questionId = questionId , exportFields = exportFields @@ -741,6 +748,10 @@ component extends="preside.system.base.AdminHandler" { var viewSubmissionTitle = translateResource( "formbuilder:view.submission.modal.title" ); var deleteSubmissionTitle = translateResource( "formbuilder:delete.submission.prompt" ); + if ( !isFeatureEnabled( "websiteUsers" ) ) { + ArrayDelete( gridFields, "submitted_by" ); + } + for( var record in records ){ for( var field in gridFields ){ records[ field ][ records.currentRow ] = renderField( diff --git a/system/preside-objects/formbuilder/formbuilder_question_response.cfc b/system/preside-objects/formbuilder/formbuilder_question_response.cfc index 5ee3440ce8..38c65e9272 100644 --- a/system/preside-objects/formbuilder/formbuilder_question_response.cfc +++ b/system/preside-objects/formbuilder/formbuilder_question_response.cfc @@ -37,8 +37,8 @@ component displayname="Form builder: global question response" extends="preside. property name="website_user" relationship="many-to-one" relatedto="website_user" required=false excludeDataExport=true adminRenderer="none" feature="websiteUsers"; property name="admin_user" relationship="many-to-one" relatedto="security_user" required=false excludeDataExport=true adminRenderer="none" feature="admin"; - property name="is_website_user" type="boolean" dbtype="boolean" formula="case when ${prefix}website_user is not null then 1 else 0 end" adminRenderer="none"; - property name="is_admin_user" type="boolean" dbtype="boolean" formula="case when ${prefix}admin_user is not null then 1 else 0 end" adminRenderer="none"; + property name="is_website_user" type="boolean" dbtype="boolean" formula="case when ${prefix}website_user is not null then 1 else 0 end" adminRenderer="none" feature="websiteUsers"; + property name="is_admin_user" type="boolean" dbtype="boolean" formula="case when ${prefix}admin_user is not null then 1 else 0 end" adminRenderer="none" feature="admin"; property name="parent_name" type="string" dbtype="varchar" formula="case when ${prefix}submission_type='formbuilder' then ${prefix}submission$form.name else '' end " adminRenderer="none"; diff --git a/system/services/formbuilder/FormBuilderFilterService.cfc b/system/services/formbuilder/FormBuilderFilterService.cfc index fae8ab6818..a81feec941 100644 --- a/system/services/formbuilder/FormBuilderFilterService.cfc +++ b/system/services/formbuilder/FormBuilderFilterService.cfc @@ -317,8 +317,9 @@ component { ) { var submissionsDao = $getPresideObject( "formbuilder_formsubmission" ); var filter = {}; + var websiteUsers = $helpers.isFeatureEnabled( "websiteUsers" ); - if ( Len( arguments.userId ) ) { + if ( websiteUsers && Len( arguments.userId ) ) { filter.submitted_by = arguments.userId; } @@ -551,7 +552,6 @@ component { ); } - public array function prepareFilterForUserHasSubmittedFormFilter( required array formId , boolean _has = true diff --git a/system/services/formbuilder/FormBuilderService.cfc b/system/services/formbuilder/FormBuilderService.cfc index a8e0c4d88c..65693b6cba 100644 --- a/system/services/formbuilder/FormBuilderService.cfc +++ b/system/services/formbuilder/FormBuilderService.cfc @@ -1183,10 +1183,13 @@ component { var extraFilters = []; var sortBy = ListFirst( arguments.orderBy, " " ); var sortOrder = ListLast( arguments.orderBy, " " ); + var websiteUsers = $helpers.isFeatureEnabled( "websiteUsers" ); switch( sortBy ) { case "submitted_by": - sortBy = "submitted_by.display_name"; + if ( websiteUsers ) { + sortBy = "submitted_by.display_name"; + } break; case "datecreated": case "instanceId": @@ -1205,10 +1208,14 @@ component { } if ( Len( Trim( arguments.searchQuery ) ) ) { - extraFilters.append({ - filter = "submitted_by.display_name like :q or formbuilder_formsubmission.form_instance like :q or formbuilder_formsubmission.submitted_data like :q" + var searchFilter = "formbuilder_formsubmission.form_instance like :q or formbuilder_formsubmission.submitted_data like :q"; + if ( websiteUsers ) { + searchFilter = "submitted_by.display_name like :q or " & searchFilter; + } + extraFilters.append( { + filter = searchFilter , filterParams = { q = { type="cf_sql_varchar", value="%#arguments.searchQuery#%" } } - }); + } ); } if ( Len( Trim( sFilterExpression ?: "" ) ) ) { @@ -1229,19 +1236,22 @@ component { } } + var selectFields = [ + "formbuilder_formsubmission.id" + , "formbuilder_formsubmission.submitted_data" + , "formbuilder_formsubmission.form_instance" + , "formbuilder_formsubmission.datecreated" + ]; + if ( websiteUsers ) { + ArrayAppend( selectFields, "submitted_by.id as submitted_by" ); + } result.records = submissionsDao.selectData( filter = { form = arguments.formId } , extraFilters = extraFilters , startRow = arguments.startRow , maxRows = arguments.maxRows , orderBy = "#sortby# #sortorder#" - , selectFields = [ - "formbuilder_formsubmission.id" - , "formbuilder_formsubmission.submitted_data" - , "formbuilder_formsubmission.form_instance" - , "formbuilder_formsubmission.datecreated" - , "submitted_by.id as submitted_by" - ] + , selectFields = selectFields ); result.totalRecords = submissionsDao.selectData( @@ -1439,7 +1449,6 @@ component { switch( sortBy ) { case "submitted_by": - sortBy = "submitted_by"; break; case "datecreated": case "instanceId": @@ -1470,10 +1479,10 @@ component { } if ( Len( Trim( arguments.searchQuery ) ) ) { - extraFilters.append({ + extraFilters.append( { filter = "submitted_by like :q or formbuilder_question_response.response like :q" , filterParams = { q = { type="cf_sql_varchar", value="%#arguments.searchQuery#%" } } - }); + } ); } if ( Len( Trim( arguments.savedFilterExpIdLists ?: "" ) ) ) { @@ -1485,6 +1494,30 @@ component { } } + var selectFields = [ + "formbuilder_question_response.id" + , "formbuilder_question_response.submission" + , "formbuilder_question_response.question" + , "formbuilder_question_response.response" + , "formbuilder_question_response.datecreated" + , "formbuilder_question_response.submitted_by" + , "formbuilder_question_response.submission_type" + , "formbuilder_question_response.submission_reference" + , "submission$form.name as form_name" + , "question.item_type" + ]; + if ( $helpers.isFeatureEnabled( "websiteUsers" ) ) { + ArrayAppend( selectFields, [ + "formbuilder_question_response.website_user" + , "formbuilder_question_response.is_website_user" + ], true ); + } + if ( $helpers.isFeatureEnabled( "admin" ) ) { + ArrayAppend( selectFields, [ + "formbuilder_question_response.admin_user" + , "formbuilder_question_response.is_admin_user" + ], true ); + } result.records = questionResponsesDao.selectData( filter = { question = arguments.questionId } , extraFilters = extraFilters @@ -1492,22 +1525,7 @@ component { , maxRows = arguments.maxRows , orderBy = "#sortby# #sortorder#" , groupBy = "submission, question" - , selectFields = [ - "formbuilder_question_response.id" - , "formbuilder_question_response.submission" - , "formbuilder_question_response.question" - , "formbuilder_question_response.response" - , "formbuilder_question_response.datecreated" - , "formbuilder_question_response.submitted_by" - , "formbuilder_question_response.website_user" - , "formbuilder_question_response.is_website_user" - , "formbuilder_question_response.admin_user" - , "formbuilder_question_response.is_admin_user" - , "formbuilder_question_response.submission_type" - , "formbuilder_question_response.submission_reference" - , "submission$form.name as form_name" - , "question.item_type" - ] + , selectFields = selectFields ); if ( arguments.startRow eq 1 and result.records.recordCount lt arguments.maxRows ) { @@ -1552,11 +1570,12 @@ component { var canLog = StructKeyExists( arguments, "logger" ); var canInfo = canLog && logger.canInfo(); var canReportProgress = StructKeyExists( arguments, "progress" ); + var websiteUsers = $helpers.isFeatureEnabled( "websiteUsers" ); var renderingService = _getFormBuilderRenderingService(); var formItems = getFormItems( arguments.formId ); var spreadsheetLib = _getSpreadsheetLib(); var workbook = spreadsheetLib.new(); - var headers = [ "Submission ID", "Submission date", "Submitted by logged in user", "Form instance ID" ]; + var headers = [ "Submission ID", "Submission date", "Form instance ID" ]; var itemColumnMap = {}; var itemsToRender = []; var submissions = $getPresideObject( "formbuilder_formsubmission" ).selectData( @@ -1564,6 +1583,10 @@ component { , orderBy = "datecreated" ); + if ( websiteUsers ) { + ArrayInsertAt( headers, 3, "Submitted by logged in user" ); + } + if ( canInfo ) { logger.info( "Fetched [#NumberFormat( submissions.recordcount )#] submissions, preparing to export..." ); } @@ -1591,12 +1614,14 @@ component { var row = 1; for( var submission in submissions ) { - var column = 4; - var submittedBy = Len( submission.submitted_by ) ? $renderLabel( "website_user", submission.submitted_by ) : ""; + var column = 4; row++; spreadsheetLib.setCellValue( workbook, submission.id, row, 1, "string" ); spreadsheetLib.setCellValue( workbook, DateTimeFormat( submission.datecreated, "yyyy-mm-dd HH:nn:ss" ), row, 2, "string" ); - spreadsheetLib.setCellValue( workbook, submittedBy, row, 3, "string" ); + if ( websiteUsers ) { + var submittedBy = Len( submission.submitted_by ) ? $renderLabel( "website_user", submission.submitted_by ) : ""; + spreadsheetLib.setCellValue( workbook, submittedBy, row, 3, "string" ); + } spreadsheetLib.setCellValue( workbook, submission.form_instance, row, 4, "string" ); if ( itemsToRender.len() ) { @@ -1705,7 +1730,8 @@ component { , any progress ) { var questionDefinition = getQuestion( arguments.questionId ); - var exportFieldList = listToArray( arguments.exportFields ); + var exportFieldList = listToArray( arguments.exportFields ); + var websiteUsers = $helpers.isFeatureEnabled( "websiteUsers" ); if ( !questionDefinition.recordCount ) { if ( canReportProgress ) { @@ -1756,8 +1782,7 @@ component { var row = 1; for( var response in responses ) { - var column = 0; - var submittedBy = Len( response.submitted_by ) ? $renderLabel( "website_user", response.submitted_by ) : ""; + var column = 0; row++; if ( ArrayContains( exportFieldList, "id" ) ) { @@ -1769,13 +1794,14 @@ component { if ( ArrayContains( exportFieldList, "submission_reference" ) ) { spreadsheetLib.setCellValue( workbook, response.submission_reference, row, ++column, "string" ); } - if ( ArrayContains( exportFieldList, "submitted_by" ) ) { - spreadsheetLib.setCellValue( workbook, response.submitted_by, row, ++column, "string" ); + if ( websiteUsers && ArrayContains( exportFieldList, "submitted_by" ) ) { + var submittedBy = Len( response.submitted_by ) ? $renderLabel( "website_user", response.submitted_by ) : ""; + spreadsheetLib.setCellValue( workbook, submittedBy, row, ++column, "string" ); } if ( ArrayContains( exportFieldList, "datecreated" ) ) { spreadsheetLib.setCellValue( workbook, DateTimeFormat( response.datecreated, "yyyy-mm-dd HH:nn:ss" ), row, ++column, "string" ); } - if ( ArrayContains( exportFieldList, "is_website_user" ) ) { + if ( websiteUsers && ArrayContains( exportFieldList, "is_website_user" ) ) { spreadsheetLib.setCellValue( workbook, response.is_website_user, row, ++column, "string" ); } if ( ArrayContains( exportFieldList, "parent_name" ) ) { @@ -1870,7 +1896,8 @@ component { , any progress ) { var questionDefinition = getQuestion( arguments.questionId ); - var exportFieldList = listToArray( arguments.exportFields ); + var exportFieldList = listToArray( arguments.exportFields ); + var websiteUsers = $helpers.isFeatureEnabled( "websiteUsers" ); if ( !questionDefinition.recordCount ) { if ( canReportProgress ) { @@ -1890,6 +1917,9 @@ component { var writer = _getCsvWriter().newWriter( tmpFile, "," ); for ( var field in exportFields ) { + if ( !websiteUsers && ArrayFind( [ "submitted_by", "is_website_user" ], field ) ) { + continue; + } headers.append( $translateResource( uri="preside-objects.formbuilder_question_response:field.#field#.title" ) ); } @@ -1927,7 +1957,6 @@ component { var rowNumber=1; for( var response in responses ) { row=[]; - var submittedBy = Len( response.submitted_by ) ? $renderLabel( "website_user", response.submitted_by ) : ""; if ( ArrayContains( exportFieldList, "id" ) ) { @@ -1939,13 +1968,14 @@ component { if ( ArrayContains( exportFieldList, "submission_reference" ) ) { row.append( response.submission_reference ); } - if ( ArrayContains( exportFieldList, "submitted_by" ) ) { - row.append( response.submitted_by ); + if ( websiteUsers && ArrayContains( exportFieldList, "submitted_by" ) ) { + var submittedBy = Len( response.submitted_by ) ? $renderLabel( "website_user", response.submitted_by ) : ""; + row.append( submittedBy ); } if ( ArrayContains( exportFieldList, "datecreated" ) ) { row.append( DateTimeFormat( response.datecreated, "yyyy-mm-dd HH:nn:ss" ) ); } - if ( ArrayContains( exportFieldList, "is_website_user" ) ) { + if ( websiteUsers && ArrayContains( exportFieldList, "is_website_user" ) ) { row.append( response.is_website_user ); } if ( ArrayContains( exportFieldList, "parent_name" ) ) { @@ -2371,25 +2401,31 @@ component { } } + var selectFields = [ + "formbuilder_question_response.id" + , "formbuilder_question_response.submission" + , "formbuilder_question_response.question" + , "formbuilder_question_response.response" + , "formbuilder_question_response.datecreated" + , "formbuilder_question_response.submitted_by" + , "formbuilder_question_response.submission_type" + , "formbuilder_question_response.submission_reference" + , "formbuilder_question_response.parent_name" + ]; + if ( $helpers.isFeatureEnabled( "websiteUsers" ) ) { + ArrayAppend( selectFields, "formbuilder_question_response.is_website_user" ); + } + if ( $helpers.isFeatureEnabled( "admin" ) ) { + ArrayAppend( selectFields, "formbuilder_question_response.is_admin_user" ); + } + var questionResponsesDao = $getPresideObject( "formbuilder_question_response" ); var responses = questionResponsesDao.selectData( filter = { question = arguments.questionId } , orderBy = "datecreated" , groupBy = "submission, question" , extraFilters = extraFilters - , selectFields = [ - "formbuilder_question_response.id" - , "formbuilder_question_response.submission" - , "formbuilder_question_response.question" - , "formbuilder_question_response.response" - , "formbuilder_question_response.datecreated" - , "formbuilder_question_response.submitted_by" - , "lformbuilder_question_response.is_website_user" - , "formbuilder_question_response.is_admin_user" - , "formbuilder_question_response.submission_type" - , "formbuilder_question_response.submission_reference" - , "formbuilder_question_response.parent_name" - ] + , selectFields = selectFields ); return responses; diff --git a/system/views/admin/formbuilder/submissions.cfm b/system/views/admin/formbuilder/submissions.cfm index 5f839318e3..abedd364bb 100644 --- a/system/views/admin/formbuilder/submissions.cfm +++ b/system/views/admin/formbuilder/submissions.cfm @@ -1,9 +1,13 @@ - theForm = prc.form ?: QueryNew( '' ); - formId = theForm.id; - canDelete = prc.canDelete = hasCmsPermission( "formbuilder.deleteSubmissions" ); - v2Form = isTrue( theForm.uses_global_questions ?: "" ); + theForm = prc.form ?: QueryNew( '' ); + formId = theForm.id; + canDelete = prc.canDelete = hasCmsPermission( "formbuilder.deleteSubmissions" ); + v2Form = isTrue( theForm.uses_global_questions ?: "" ); + gridFields = [ "datecreated", "form_instance", "submitted_data" ]; + if ( isFeatureEnabled( "websiteUsers" ) ) { + ArrayPrepend( gridFields, "submitted_by" ); + } @@ -21,7 +25,7 @@ , useMultiActions = canDelete , multiActionUrl = event.buildAdminLink( linkTo='formbuilder.deleteSubmissionsAction', querystring="formId=#formId#" ) , datasourceUrl = event.buildAdminLink( linkTo='formbuilder.listSubmissionsForAjaxDataTable', querystring="formId=#formId#" ) - , gridFields = [ "submitted_by", "datecreated", "form_instance", "submitted_data" ] + , gridFields = gridFields , allowSearch = true , filterContextData = { formId=formId } , excludeFilterExpressionTags = v2Form ? "formbuilderV1Form" : "formbuilderV2Form" diff --git a/system/views/admin/formbuilder/viewSubmission.cfm b/system/views/admin/formbuilder/viewSubmission.cfm index e0db4cb78b..acea9da262 100644 --- a/system/views/admin/formbuilder/viewSubmission.cfm +++ b/system/views/admin/formbuilder/viewSubmission.cfm @@ -3,12 +3,14 @@
-

- #renderContent( 'websiteUser', prc.submission.submitted_by, [ "admin" ] )# - - - -

+ +

+ #renderContent( 'websiteUser', prc.submission.submitted_by, [ "admin" ] )# + + + +

+
#translateResource( "preside-objects.formbuilder_formsubmission:field.datecreated.title")#
#renderField( 'formbuilder_formsubmission', 'datecreated', prc.submission.datecreated )#
diff --git a/system/views/email/template/formbuilderSubmissionNotification/_submissionHtml.cfm b/system/views/email/template/formbuilderSubmissionNotification/_submissionHtml.cfm index 6220817d82..026d72ece6 100644 --- a/system/views/email/template/formbuilderSubmissionNotification/_submissionHtml.cfm +++ b/system/views/email/template/formbuilderSubmissionNotification/_submissionHtml.cfm @@ -3,9 +3,11 @@ - - - + + + + + diff --git a/system/views/email/template/formbuilderSubmissionNotification/_submissionText.cfm b/system/views/email/template/formbuilderSubmissionNotification/_submissionText.cfm index 448eb9bfea..b0c1cd9d79 100644 --- a/system/views/email/template/formbuilderSubmissionNotification/_submissionText.cfm +++ b/system/views/email/template/formbuilderSubmissionNotification/_submissionText.cfm @@ -3,8 +3,8 @@ ============== -#translateResource( "preside-objects.formbuilder_formsubmission:field.submitted_by.title")#: #renderContent( 'websiteUser', args.submissionData.submitted_by, [ "textemail" ] )# -#translateResource( "preside-objects.formbuilder_formsubmission:field.datecreated.title")#: #renderField( 'formbuilder_formsubmission', 'datecreated', args.submissionData.datecreated, [ "textemail"] )# +#translateResource( "preside-objects.formbuilder_formsubmission:field.submitted_by.title")#: #renderContent( 'websiteUser', args.submissionData.submitted_by, [ "textemail" ] )# +#translateResource( "preside-objects.formbuilder_formsubmission:field.datecreated.title")#: #renderField( 'formbuilder_formsubmission', 'datecreated', args.submissionData.datecreated, [ "textemail"] )# #translateResource( "preside-objects.formbuilder_formsubmission:field.form_instance.title")#: #renderField( 'formbuilder_formsubmission', 'form_instance', args.submissionData.form_instance, [ "textemail"] )# #translateResource( "preside-objects.formbuilder_formsubmission:field.ip_address.title")#: #renderField( 'formbuilder_formsubmission', 'ip_address', args.submissionData.ip_address, [ "textemail"] )# #translateResource( "preside-objects.formbuilder_formsubmission:field.user_agent.title")#: #renderField( 'formbuilder_formsubmission', 'user_agent', args.submissionData.user_agent, [ "textemail"] )# From 341b98435ed622ad0f09d45e24cdf1084923f7ac Mon Sep 17 00:00:00 2001 From: Seb Duggan Date: Tue, 3 Dec 2024 12:37:23 +0000 Subject: [PATCH 3/3] Fix test directory --- tests/index.cfm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/index.cfm b/tests/index.cfm index bb3e0b3cc0..fe99a6b931 100644 --- a/tests/index.cfm +++ b/tests/index.cfm @@ -1,5 +1,5 @@ - dirs = DirectoryList( path="integration/api", listinfo="name" ); + dirs = DirectoryList( path="unit/api", listinfo="name" ); ArraySort( dirs, "text" );
#renderContent( 'websiteUser', args.submissionData.submitted_by, [ "email" ] )#
#renderContent( 'websiteUser', args.submissionData.submitted_by, [ "email" ] )#
#translateResource( "preside-objects.formbuilder_formsubmission:field.datecreated.title")# #renderField( 'formbuilder_formsubmission', 'datecreated', args.submissionData.datecreated )#