From 6cf37bfee2d047938457e5d0d4a5b550d4ffc6c1 Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Mon, 26 May 2003 03:06:43 +0000 Subject: [PATCH] implemented common sysadmin E-mail message editor and three E-mail message editors --- conf/std_render_macro_library.vm | 2 + conf/venice-db-init-mysql.sql | 15 +- .../dynamo/velocity/StdObject.java | 6 + venice-data/scripts/sysadmin/confirm_email.js | 40 ++++++ .../scripts/sysadmin/pwchange_email.js | 40 ++++++ .../scripts/sysadmin/pwremind_email.js | 42 ++++++ venice-data/util/sysadmin/edit-email.js | 129 ++++++++++++++++++ venice-data/velocity/VM_global_library.vm | 2 + .../velocity/stylesheets/normal_base.vm | 5 + venice-data/velocity/sysadmin/edit-email.vm | 51 +++++++ 10 files changed, 329 insertions(+), 3 deletions(-) create mode 100644 venice-data/scripts/sysadmin/confirm_email.js create mode 100644 venice-data/scripts/sysadmin/pwchange_email.js create mode 100644 venice-data/scripts/sysadmin/pwremind_email.js create mode 100644 venice-data/util/sysadmin/edit-email.js create mode 100644 venice-data/velocity/sysadmin/edit-email.vm diff --git a/conf/std_render_macro_library.vm b/conf/std_render_macro_library.vm index f84e493..da62ded 100644 --- a/conf/std_render_macro_library.vm +++ b/conf/std_render_macro_library.vm @@ -17,6 +17,8 @@ *# ## Define macros around the "std" object. +#macro( dollarprefix $data )$std.dollarPrefix($data)#end + #macro( formatURL $type $url )$std.formatURL($type,$url)#end #macro( encodeHTML $data )$std.encodeHTML($data)#end diff --git a/conf/venice-db-init-mysql.sql b/conf/venice-db-init-mysql.sql index 3a9f113..f71e8ca 100644 --- a/conf/venice-db-init-mysql.sql +++ b/conf/venice-db-init-mysql.sql @@ -591,6 +591,15 @@ INSERT INTO menuitems (menuid, sequence, itemtype, text, linktype, link) VALUES INSERT INTO menus (menuid, menu_nsid, menu_name, title, subtitle) VALUES (3, 13, 'system.admin', 'System Administration', NULL); INSERT INTO menuitems (menuid, sequence, itemtype, text, linktype, link, perm_nsid, perm_name) VALUES - (3, 0, 'TEXT', 'Set Frame Look-And-Feel Parameters', 'SERVLET', 'sysadmin/frame_laf.js.vs', 1, 'set.property'), - (3, 1, 'TEXT', 'Set E-Mail Parameters', 'SERVLET', 'sysadmin/email.js.vs', 5, 'set.property'), - (3, 2, 'TEXT', 'Set Session Parameters', 'SERVLET', 'sysadmin/session.js.vs', 7, 'set.property'); + (3, 0, 'TEXT', 'Set Frame Look-And-Feel Parameters', 'SERVLET', 'sysadmin/frame_laf.js.vs', 1, + 'set.property'), + (3, 1, 'TEXT', 'Set E-Mail Parameters', 'SERVLET', 'sysadmin/email.js.vs', 5, + 'set.property'), + (3, 2, 'TEXT', 'Set Session Parameters', 'SERVLET', 'sysadmin/session.js.vs', 7, + 'set.property'), + (3, 3, 'TEXT', 'Edit Confirmation E-Mail Message', 'SERVLET', 'sysadmin/confirm_email.js.vs', 12, + 'set.property'), + (3, 4, 'TEXT', 'Edit Password Changed E-Mail Message', 'SERVLET', 'sysadmin/pwchange_email.js.vs', 12, + 'set.property'), + (3, 5, 'TEXT', 'Edit Password Reminder E-Mail Message', 'SERVLET', 'sysadmin/pwremind_email.js.vs', 12, + 'set.property'); diff --git a/src/dynamo-framework/com/silverwrist/dynamo/velocity/StdObject.java b/src/dynamo-framework/com/silverwrist/dynamo/velocity/StdObject.java index b63c40a..ebc5923 100644 --- a/src/dynamo-framework/com/silverwrist/dynamo/velocity/StdObject.java +++ b/src/dynamo-framework/com/silverwrist/dynamo/velocity/StdObject.java @@ -49,6 +49,12 @@ public class StdObject *-------------------------------------------------------------------------------- */ + public String dollarPrefix(String data) + { + return "$" + data; + + } // end dollarPrefix + public String formatURL(String type, String url) { if (m_rewriter==null) diff --git a/venice-data/scripts/sysadmin/confirm_email.js b/venice-data/scripts/sysadmin/confirm_email.js new file mode 100644 index 0000000..19107ad --- /dev/null +++ b/venice-data/scripts/sysadmin/confirm_email.js @@ -0,0 +1,40 @@ +// The contents of this file are subject to the Mozilla Public License Version 1.1 +// (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at . +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT +// WARRANTY OF ANY KIND, either express or implied. See the License for the specific +// language governing rights and limitations under the License. +// +// The Original Code is the Venice Web Communities System. +// +// The Initial Developer of the Original Code is Eric J. Bowersox , +// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +// Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +// +// Contributor(s): + +importPackage(java.util); +importPackage(Packages.com.silverwrist.dynamo.iface); +importPackage(Packages.com.silverwrist.dynamo.util); +importClass(Packages.com.silverwrist.venice.VeniceNamespaces); + +req = bsf.lookupBean("request"); + +// Set up the parameters to call the edit-email.js script. +my_ns = "/util/sysadmin/edit-email.js"; +req.setObject(my_ns,"namespace",VeniceNamespaces.MAIL_MESSAGES_NAMESPACE); +req.setObject(my_ns,"subject.property","confirm.message.title"); +req.setObject(my_ns,"body.block","confirm.message"); +req.setObject(my_ns,"caller","sysadmin/confirm_email.js.vs"); +req.setObject(my_ns,"returnto","sysadmin/main.js.vs"); +req.setObject(my_ns,"title","E-Mail Confirmation"); + +// Set up the varmap. +varmap = new TreeMap(); +varmap.put("username","The name of the user account being confirmed"); +varmap.put("confnum","The confirmation number"); +req.setObject(my_ns,"varmap",varmap); + +// Execute and return the value from the common script. +dynamo.scriptOutput(dynamo.exec(my_ns)); diff --git a/venice-data/scripts/sysadmin/pwchange_email.js b/venice-data/scripts/sysadmin/pwchange_email.js new file mode 100644 index 0000000..b92daa2 --- /dev/null +++ b/venice-data/scripts/sysadmin/pwchange_email.js @@ -0,0 +1,40 @@ +// The contents of this file are subject to the Mozilla Public License Version 1.1 +// (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at . +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT +// WARRANTY OF ANY KIND, either express or implied. See the License for the specific +// language governing rights and limitations under the License. +// +// The Original Code is the Venice Web Communities System. +// +// The Initial Developer of the Original Code is Eric J. Bowersox , +// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +// Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +// +// Contributor(s): + +importPackage(java.util); +importPackage(Packages.com.silverwrist.dynamo.iface); +importPackage(Packages.com.silverwrist.dynamo.util); +importClass(Packages.com.silverwrist.venice.VeniceNamespaces); + +req = bsf.lookupBean("request"); + +// Set up the parameters to call the edit-email.js script. +my_ns = "/util/sysadmin/edit-email.js"; +req.setObject(my_ns,"namespace",VeniceNamespaces.MAIL_MESSAGES_NAMESPACE); +req.setObject(my_ns,"subject.property","password.change.message.title"); +req.setObject(my_ns,"body.block","password.change.message"); +req.setObject(my_ns,"caller","sysadmin/pwchange_email.js.vs"); +req.setObject(my_ns,"returnto","sysadmin/main.js.vs"); +req.setObject(my_ns,"title","Password Changed by Password Recovery"); + +// Set up the varmap. +varmap = new TreeMap(); +varmap.put("username","The name of the user account with the password changed"); +varmap.put("password","The new password"); +req.setObject(my_ns,"varmap",varmap); + +// Execute and return the value from the common script. +dynamo.scriptOutput(dynamo.exec(my_ns)); diff --git a/venice-data/scripts/sysadmin/pwremind_email.js b/venice-data/scripts/sysadmin/pwremind_email.js new file mode 100644 index 0000000..3d560ae --- /dev/null +++ b/venice-data/scripts/sysadmin/pwremind_email.js @@ -0,0 +1,42 @@ +// The contents of this file are subject to the Mozilla Public License Version 1.1 +// (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at . +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT +// WARRANTY OF ANY KIND, either express or implied. See the License for the specific +// language governing rights and limitations under the License. +// +// The Original Code is the Venice Web Communities System. +// +// The Initial Developer of the Original Code is Eric J. Bowersox , +// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +// Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +// +// Contributor(s): + +importPackage(java.util); +importPackage(Packages.com.silverwrist.dynamo.iface); +importPackage(Packages.com.silverwrist.dynamo.util); +importClass(Packages.com.silverwrist.venice.VeniceNamespaces); + +req = bsf.lookupBean("request"); + +// Set up the parameters to call the edit-email.js script. +my_ns = "/util/sysadmin/edit-email.js"; +req.setObject(my_ns,"namespace",VeniceNamespaces.MAIL_MESSAGES_NAMESPACE); +req.setObject(my_ns,"subject.property","reminder.message.title"); +req.setObject(my_ns,"body.block","reminder.message"); +req.setObject(my_ns,"caller","sysadmin/pwremind_email.js.vs"); +req.setObject(my_ns,"returnto","sysadmin/main.js.vs"); +req.setObject(my_ns,"title","Password Reminder"); + +// Set up the varmap. +varmap = new TreeMap(); +varmap.put("username","The name of the user account to remind on"); +varmap.put("reminder","The password reminder message"); +varmap.put("uid","The user ID of the user account"); +varmap.put("auth","The authentication string for use in password recovery"); +req.setObject(my_ns,"varmap",varmap); + +// Execute and return the value from the common script. +dynamo.scriptOutput(dynamo.exec(my_ns)); diff --git a/venice-data/util/sysadmin/edit-email.js b/venice-data/util/sysadmin/edit-email.js new file mode 100644 index 0000000..75244da --- /dev/null +++ b/venice-data/util/sysadmin/edit-email.js @@ -0,0 +1,129 @@ +// The contents of this file are subject to the Mozilla Public License Version 1.1 +// (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at . +// +// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT +// WARRANTY OF ANY KIND, either express or implied. See the License for the specific +// language governing rights and limitations under the License. +// +// The Original Code is the Venice Web Communities System. +// +// The Initial Developer of the Original Code is Eric J. Bowersox , +// for Silverwrist Design Studios. Portions created by Eric J. Bowersox are +// Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. +// +// Contributor(s): + +// Parameters to this script are passed in the request with a namespace of "/util/sysadmin/edit-email.js": +// namespace = Namespace of the subject property and message text block +// subject.property = Name of property where the subject text is stored +// body.block = Name of block where message text is stored +// caller = SERVLET URL of caller, so form can POST back to it +// returnto = SERVLET URL of page to bounce back to after update completed +// title = Title of the message being edited +// varmap = A Map which contains the variable replacement definitions to display below the body text box (optional) + +importClass(Packages.com.silverwrist.dynamo.Namespaces); +importPackage(Packages.com.silverwrist.dynamo.except); +importPackage(Packages.com.silverwrist.dynamo.iface); +importPackage(Packages.com.silverwrist.dynamo.security); +importPackage(Packages.com.silverwrist.dynamo.util); +importPackage(Packages.com.silverwrist.venice.content); + +req = bsf.lookupBean("request"); // get request +rhelp = bsf.lookupBean("request_help"); // get request helper +user = vlib.getUser(req); + +// Get the namespace and name parameters. +my_ns = "/util/sysadmin/edit-email.js"; +namespace = req.getObject(my_ns,"namespace"); +subject_property = req.getObject(my_ns,"subject.property"); +body_block = req.getObject(my_ns,"body.block"); +return_URL = req.getObject(my_ns,"returnto"); +vlib.setOnError(req,return_URL); +vlib.setOnErrorType(req,"SERVLET"); + +// Make sure we are permitted to be here. +srm = cast.querySecurityReferenceMonitor(rhelp.getRequestObject(Namespaces.DYNAMO_OBJECT_NAMESPACE,"srm")); +acl = srm.getGlobalAcl(); +if (!(acl.testPermission(user,namespace,"set.property") && acl.testPermission(user,namespace,"set.block"))) + dynamo.scriptReturn(vlib.stdErrorBox(req,"Security Error", + "You are not permitted to edit the system E-mail messages.")); + +// Get the global properties store. +globals = vcast.getGlobalPropertiesStore(req); +blocks = vcast.getGlobalBlocksStore(req); + +error_message = null; +rc = null; +subject_text = ""; +body_text = ""; + +if (rhelp.isVerb("GET")) +{ // load the initial values of the text fields + subject_text = globals.getObject(namespace,subject_property); + body_text = blocks.getObject(namespace,body_block); + +} // end if +else +{ // did they click Cancel? + if (rhelp.isImageButtonClicked("cancel")) + rc = new Redirect("SERVLET",return_URL); + else + { // retrieve the form parameters + subject_text = rhelp.getParameterString("subject"); + body_text = rhelp.getParameterString("body"); + + if (stringutils.isEmpty(subject_text)) + error_message = "Subject text not specified."; + else if (stringutils.isEmpty(body_text)) + error_message = "Body text not specified."; + else if (body_text.length()>65535) + error_message = "Body text is too long."; + + if (error_message==null) + { // attempt to set the properties! + try + { // set the two properties + globals.setObject(user,namespace,subject_property,subject_text.toString()); + blocks.setObject(user,namespace,body_block,body_text.toString()); + + // all done - bounce back to return location + rc = new Redirect("SERVLET",return_URL); + + } // end try + catch (e) + { // thrown an exception from the above process - what sort? + etype = dynamo.exceptionType(e) + ""; + logger.error("Caught exception of type " + etype); + if (etype.match(/DatabaseException/)) + rc = new ErrorBox("Database Error",e,"SERVLET",return_URL); + else if (etype.match(/DynamoSecurityException/)) + rc = new ErrorBox("Security Error",e,"SERVLET",return_URL); + else + rc = new ErrorBox("Unknown Exception",e,"SERVLET",return_URL); + + } // end catch + + } // end if + + } // end else + +} // end else + +if (rc==null) +{ // generate the form as a Velocity object + rc = new VelocityView("Edit E-Mail Message","sysadmin/edit-email.vm"); + rc.setParameter("msgtitle",req.getObject(my_ns,"title")); + rc.setParameter("action",req.getObject(my_ns,"caller")); + rc.setParameter("subject",subject_text); + rc.setParameter("body",body_text); + tmp = PropertyUtils.getPropertyNoErr(req,my_ns,"varmap"); + if (tmp!=null) + rc.setParameter("varmap",tmp); + if (error_message!=null) + rc.setParameter("error_message",error_message); + +} // end if + +dynamo.scriptOutput(rc); diff --git a/venice-data/velocity/VM_global_library.vm b/venice-data/velocity/VM_global_library.vm index 1449374..bd87c0f 100644 --- a/venice-data/velocity/VM_global_library.vm +++ b/venice-data/velocity/VM_global_library.vm @@ -17,6 +17,8 @@ *# ## Define macros around the "std" object. +#macro( dollarprefix $data )$std.dollarPrefix($data)#end + #macro( formatURL $type $url )$std.formatURL($type,$url)#end #macro( encodeHTML $data )$std.encodeHTML($data)#end diff --git a/venice-data/velocity/stylesheets/normal_base.vm b/venice-data/velocity/stylesheets/normal_base.vm index 5dd86c3..f10bf5a 100644 --- a/venice-data/velocity/stylesheets/normal_base.vm +++ b/venice-data/velocity/stylesheets/normal_base.vm @@ -122,3 +122,8 @@ td.sideboxtop { td.sidebox { padding: 2px; } + +.formerror { + font-weight: bold; + font-color: red; + } diff --git a/venice-data/velocity/sysadmin/edit-email.vm b/venice-data/velocity/sysadmin/edit-email.vm new file mode 100644 index 0000000..b0393ff --- /dev/null +++ b/venice-data/velocity/sysadmin/edit-email.vm @@ -0,0 +1,51 @@ +#* + The contents of this file are subject to the Mozilla Public License Version 1.1 + (the "License"); you may not use this file except in compliance with the License. + You may obtain a copy of the License at . + + Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + WARRANTY OF ANY KIND, either express or implied. See the License for the specific + language governing rights and limitations under the License. + + The Original Code is the Venice Web Communities System. + + The Initial Developer of the Original Code is Eric J. Bowersox , + for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + Copyright (C) 2003 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + + Contributor(s): +*# +#* + Parameters: + msgtitle = Title of the E-mail message being edited. + action = Action URL to which the form should be posted. + subject = Default subject for the message. + body = Default body for the message. + varmap = Listing of variables in the input, with explanations; a Map (may be null) + error_message = Error message to be displayed for this form (may be null). +*# +#header2( "Edit E-Mail Message" $msgtitle ) +#if( $error_message ) +
#encodeHTML( $error_message ) Please try again.
+#end +
+ + + + #if( $varmap ) + + #end + +
+ Subject: +
+ +
+ Variables: + #foreach( $var in $varmap.keySet() ) +
#dollarprefix( $var ) = #encodeHTML( ${varmap.get($var)} ) + #end +
+ #button( "INPUT" "update" )  #button( "INPUT" "cancel" ) +
+