Index: openacs-4/packages/workflow/sql/oracle/workflow-tables-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/oracle/workflow-tables-create.sql,v diff -u -N -r1.8 -r1.9 --- openacs-4/packages/workflow/sql/oracle/workflow-tables-create.sql 18 Nov 2003 17:57:56 -0000 1.8 +++ openacs-4/packages/workflow/sql/oracle/workflow-tables-create.sql 1 Dec 2003 09:53:19 -0000 1.9 @@ -104,7 +104,11 @@ constraint wf_roles_pretty_name_nn not null, sort_order integer constraint wf_roles_so_nn - not null + not null, + constraint wf_roles_short_name_un + unique (workflow_id, short_name), + constraint wf_roles_pretty_name_un + unique (workflow_id, pretty_name) ); create sequence workflow_roles_seq; @@ -162,7 +166,11 @@ -- When the action to automatically fire. -- A value of 0 means immediately, null means never. -- Other values mean x amount of time after having become enabled - timeout_seconds integer + timeout_seconds integer, + constraint wf_actions_short_name_un + unique (workflow_id, short_name), + constraint wf_actions_pretty_name_un + unique (workflow_id, pretty_name) ); create sequence workflow_actions_seq; @@ -257,7 +265,12 @@ pretty_name varchar(200) constraint wf_fsm_states_pretty_name_nn not null, - hide_fields varchar(4000) + hide_fields varchar(4000), + constraint wf_fsm_states_short_name_un + unique (workflow_id, short_name), + constraint wf_fsm_states_pretty_name_un + unique (workflow_id, pretty_name) + ); create sequence workflow_fsm_states_seq; Index: openacs-4/packages/workflow/sql/oracle/upgrade/upgrade-1.2-2.0d1.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/oracle/upgrade/upgrade-1.2-2.0d1.sql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/workflow/sql/oracle/upgrade/upgrade-1.2-2.0d1.sql 18 Nov 2003 17:57:56 -0000 1.1 +++ openacs-4/packages/workflow/sql/oracle/upgrade/upgrade-1.2-2.0d1.sql 1 Dec 2003 09:53:19 -0000 1.2 @@ -46,3 +46,14 @@ create index workflow_case_log_action_id on workflow_case_log (action_id); create index workflow_case_log_case_id on workflow_case_log (case_id); + +-- Missing unique constraints on names +-- TODO: Test these +alter table workflow_roles add constraint wf_roles_short_name_un unique (workflow_id, short_name); +alter table workflow_roles add constraint wf_roles_pretty_name_un unique (workflow_id, pretty_name); + +alter table workflow_actions add constraint wf_actions_short_name_un unique (workflow_id, short_name); +alter table workflow_actions add constraint wf_actions_pretty_name_un unique (workflow_id, pretty_name); + +alter table workflow_fsm_states add constraint wf_fsm_states_short_name_un unique (workflow_id, short_name); +alter table workflow_fsm_states add constraint wf_fsm_states_pretty_name_un unique (workflow_id, pretty_name); Index: openacs-4/packages/workflow/sql/postgresql/workflow-tables-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/postgresql/workflow-tables-create.sql,v diff -u -N -r1.16 -r1.17 --- openacs-4/packages/workflow/sql/postgresql/workflow-tables-create.sql 18 Nov 2003 17:57:56 -0000 1.16 +++ openacs-4/packages/workflow/sql/postgresql/workflow-tables-create.sql 1 Dec 2003 09:53:19 -0000 1.17 @@ -109,7 +109,11 @@ not null, sort_order integer constraint wf_roles_so_nn - not null + not null, + constraint wf_roles_short_name_un + unique (workflow_id, short_name), + constraint wf_roles_pretty_name_un + unique (workflow_id, pretty_name) ); create sequence workflow_roles_seq; @@ -171,7 +175,11 @@ -- When the action to automatically fire. -- A value of 0 means immediately, null means never. -- Other values mean x amount of time after having become enabled - timeout interval + timeout interval, + constraint wf_actions_short_name_un + unique (workflow_id, short_name), + constraint wf_actions_pretty_name_un + unique (workflow_id, pretty_name) ); create sequence workflow_actions_seq; @@ -273,7 +281,11 @@ pretty_name varchar(200) constraint wf_fsm_states_pretty_name_nn not null, - hide_fields varchar(4000) + hide_fields varchar(4000), + constraint wf_fsm_states_short_name_un + unique (workflow_id, short_name), + constraint wf_fsm_states_pretty_name_un + unique (workflow_id, pretty_name) ); create sequence workflow_fsm_states_seq; Index: openacs-4/packages/workflow/sql/postgresql/upgrade/upgrade-1.2-2.0d1.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/sql/postgresql/upgrade/upgrade-1.2-2.0d1.sql,v diff -u -N -r1.1 -r1.2 --- openacs-4/packages/workflow/sql/postgresql/upgrade/upgrade-1.2-2.0d1.sql 18 Nov 2003 17:57:56 -0000 1.1 +++ openacs-4/packages/workflow/sql/postgresql/upgrade/upgrade-1.2-2.0d1.sql 1 Dec 2003 09:53:19 -0000 1.2 @@ -40,3 +40,14 @@ create index wf_case_enbl_act_action_idx on workflow_case_enabled_actions(action_id); create index wf_case_enbl_act_state_idx on workflow_case_enabled_actions(enabled_state); + +-- Missing unique constraints on names +-- TODO: Test these +alter table workflow_roles add constraint wf_roles_short_name_un unique (workflow_id, short_name); +alter table workflow_roles add constraint wf_roles_pretty_name_un unique (workflow_id, pretty_name); + +alter table workflow_actions add constraint wf_actions_short_name_un unique (workflow_id, short_name); +alter table workflow_actions add constraint wf_actions_pretty_name_un unique (workflow_id, pretty_name); + +alter table workflow_fsm_states add constraint wf_fsm_states_short_name_un unique (workflow_id, short_name); +alter table workflow_fsm_states add constraint wf_fsm_states_pretty_name_un unique (workflow_id, pretty_name); Index: openacs-4/packages/workflow/tcl/action-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/action-procs-oracle.xql,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/workflow/tcl/action-procs-oracle.xql 18 Nov 2003 17:57:56 -0000 1.3 +++ openacs-4/packages/workflow/tcl/action-procs-oracle.xql 1 Dec 2003 09:53:19 -0000 1.4 @@ -27,8 +27,8 @@ a.pretty_name, a.pretty_past_tense, a.edit_fields, - a.assigned_role, - (select short_name from workflow_roles where role_id = a.assigned_role) as assigned_role_short_name, + a.assigned_role as assigned_role_id, + (select short_name from workflow_roles where role_id = a.assigned_role) as assigned_role, a.always_enabled_p, (select case when count(*) = 1 then 't' else 'f' end from workflow_initial_action Index: openacs-4/packages/workflow/tcl/action-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/action-procs-postgresql.xql,v diff -u -N -r1.3 -r1.4 --- openacs-4/packages/workflow/tcl/action-procs-postgresql.xql 18 Nov 2003 17:57:56 -0000 1.3 +++ openacs-4/packages/workflow/tcl/action-procs-postgresql.xql 1 Dec 2003 09:53:19 -0000 1.4 @@ -28,8 +28,8 @@ a.pretty_name, a.pretty_past_tense, a.edit_fields, - a.assigned_role, - (select short_name from workflow_roles where role_id = a.assigned_role) as assigned_role_short_name, + a.assigned_role as assigned_role_id, + (select short_name from workflow_roles where role_id = a.assigned_role) as assigned_role, a.always_enabled_p, (select case when count(*) = 1 then 't' else 'f' end from workflow_initial_action Index: openacs-4/packages/workflow/tcl/action-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/action-procs.tcl,v diff -u -N -r1.11 -r1.12 --- openacs-4/packages/workflow/tcl/action-procs.tcl 18 Nov 2003 17:57:56 -0000 1.11 +++ openacs-4/packages/workflow/tcl/action-procs.tcl 1 Dec 2003 09:53:19 -0000 1.12 @@ -60,11 +60,11 @@ @param edit_fields A space-separated list of the names of form fields which should be opened for editing when this action is carried out. - @param assigned_role The name of an assigned role. Users in this + @param assigned_role The short_name of an assigned role. Users in this role are expected (obliged) to take the action. - @param allowed_roles A list of role names. Users in these roles are + @param allowed_roles A list of role short_names or IDs. Users in these roles are allowed to take the action. @param privileges Users with these privileges on the object @@ -161,13 +161,13 @@ @param action_id The action to edit. - @param workflow_id Optionally specify the workflow_id. If not specified, we will execute a query to find it. + @param workflow_id Optionally specify the workflow_id. If not specified, we will execute a query to find it. @param array Name of an array in the caller's namespace with attributes to edit. - @param internal Set this flag if you're calling this proc from within the corresponding proc - for a particular workflow model. Will cause this proc to not flush the cache - or call workflow::definition_changed_handler, which the caller must then do. + @param internal Set this flag if you're calling this proc from within the corresponding proc + for a particular workflow model. Will cause this proc to not flush the cache + or call workflow::definition_changed_handler, which the caller must then do. @return action_id @@ -186,14 +186,16 @@ -element workflow_id] } + # Handle columns in the workflow_actions table foreach attr { - short_name pretty_name pretty_past_tense edit_fields description description_mime_type + short_name pretty_name pretty_past_tense edit_fields description description_mime_type sort_order always_enabled_p assigned_role timeout_seconds } { if { [info exists row($attr)] } { set varname attr_$attr + # Convert the Tcl value to something we can use in the query switch $attr { always_enabled_p { set $varname [db_boolean [template::util::is_true $row($attr)]] @@ -208,6 +210,7 @@ set $varname $row($attr) } } + # Add the column to the SET clause switch $attr { timeout_seconds { lappend set_clauses [db_map update_timeout_seconds] @@ -388,9 +391,14 @@ @author Peter Marklund @author Lars Pind (lars@collaboraid.biz) - @return An array list with workflow_id, sort_order, short_name, pretty_name, - pretty_past_tense, assigned_role, and always_enabled_p, description, + @return The array will contain the following entries: + workflow_id, sort_order, short_name, pretty_name, + pretty_past_tense, assigned_role (short_name), assigned_role_id, + always_enabled_p, initial_action_p, description, description_mime_type column values for an action. + + @see workflow::action::get_all_info + @see workflow::action::get_all_info_not_cached } { # Select the info into the upvar'ed Tcl Array upvar $array row @@ -956,10 +964,6 @@ @author Peter Marklund } { - # LARS HACK -# return [workflow::action::get_all_info_not_cached \ - # -workflow_id $workflow_id] - return [util_memoize [list workflow::action::get_all_info_not_cached \ -workflow_id $workflow_id] [workflow::cache_timeout]] } Index: openacs-4/packages/workflow/tcl/role-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/role-procs.tcl,v diff -u -N -r1.10 -r1.11 --- openacs-4/packages/workflow/tcl/role-procs.tcl 18 Nov 2003 17:57:57 -0000 1.10 +++ openacs-4/packages/workflow/tcl/role-procs.tcl 1 Dec 2003 09:53:19 -0000 1.11 @@ -45,10 +45,9 @@ -workflow_id $workflow_id \ -table_name "workflow_roles"] } else { - set sort_order_taken_p [db_string select_sort_order_p {}] - if { $sort_order_taken_p } { - db_dml update_sort_order {} - } + workflow::role::update_sort_order \ + -workflow_id $workflow_id \ + -sort_order $sort_order } set role_id [db_nextval "workflow_roles_seq"] @@ -68,11 +67,11 @@ } { Creates a new role for a workflow. - @param workflow_id The ID of the workflow the new role belongs to - @param short_name The short_name of the new role - @param pretty_name The pretty name of the new role - @param callbacks A list of names service-contract implementations. - @return The ID of the new role + @param workflow_id The ID of the workflow the new role belongs to + @param short_name The short_name of the new role + @param pretty_name The pretty name of the new role + @param callbacks A list of names service-contract implementations. + @return role_id @author Peter Marklund @author Lars Pind (lars@collaboraid.biz) @@ -86,16 +85,115 @@ -sort_order $sort_order \ ] - # Set up the assignment rules - foreach callback_name $callbacks { - workflow::role::callback_insert \ + # Callbacks + set edit_array(callbacks) $callbacks + workflow::role::edit \ + -role_id $role_id \ + -array edit_array \ + -internal + } + + # Role info for the workflow is changed, need to flush + workflow::role::flush_cache -workflow_id $workflow_id + + return $role_id +} + +ad_proc -public workflow::role::edit { + {-role_id:required} + {-workflow_id {}} + {-array:required} + {-internal:boolean} +} { + Edit a workflow role. Attributes of the array are: short_name, pretty_name, sort_order, callbacks. + + @param role_id The role to edit. + + @param workflow_id Optionally specify the workflow_id. If not specified, we will execute a query to find it. + + @param array Name of an array in the caller's namespace with attributes to edit. + + @param internal Set this flag if you're calling this proc from within the corresponding proc + for a particular workflow model. Will cause this proc to not flush the cache + or call workflow::definition_changed_handler, which the caller must then do. + + @return role_id + + @see workflow::role::new + + @author Peter Marklund + @author Lars Pind (lars@collaboraid.biz) +} { + upvar 1 $array row + foreach name [array names row] { + set missing_elm($name) 1 + } + + set set_clauses [list] + + if { [empty_string_p $workflow_id] } { + set workflow_id [workflow::role::get_element \ + -role_id $role_id \ + -element workflow_id] + } + + # Handle columns in the workflow_roles table + foreach attr { + short_name pretty_name sort_order + } { + if { [info exists row($attr)] } { + set varname attr_$attr + set $varname $row($attr) + lappend set_clauses "$attr = :$varname" + unset missing_elm($attr) + } + } + + + db_transaction { + + if { [info exists row(sort_order)] } { + workflow::role::update_sort_order \ + -workflow_id $workflow_id \ + -sort_order $row(sort_order) + } + + # Update role + if { [llength $set_clauses] > 0 } { + db_dml update_role " + update workflow_roles + set [join $set_clauses ", "] + where role_id = :role_id + " + } + + # Callbacks + if { [info exists row(callbacks)] } { + db_dml delete_callbacks { + delete from workflow_role_callbacks + where role_id = :role_id + } + foreach callback_name $row(callbacks) { + workflow::role::callback_insert \ -role_id $role_id \ -name $callback_name + } + unset missing_elm(callbacks) } + + # Check that there are no unknown attributes + if { [llength [array names missing_elm]] > 0 } { + error "Trying to set illegal action attributes: [join [array names row] ", "]" + } + + if { !$internal_p } { + workflow::definition_changed_handler -workflow_id $workflow_id + } } - # Role info for the workflow is changed, need to flush - workflow::role::flush_cache -workflow_id $workflow_id + if { !$internal_p } { + workflow::role::flush_cache -workflow_id $workflow_id + } return $role_id } @@ -113,6 +211,22 @@ } } +ad_proc -public workflow::role::get_options { + {-workflow_id:required} +} { + Get a list of roles in a workflow for use in the 'options' property of a form builder form element. + + @author Lars Pind (lars@collaboraid.biz) +} { + set result [list] + foreach role_id [workflow::get_roles -workflow_id $workflow_id] { + workflow::role::get -role_id $role_id -array row + lappend result [list $row(pretty_name) $row(short_name)] + } + # Order by label + return [lsort -index 0 $result] +} + ad_proc -public workflow::role::get_id { {-workflow_id:required} {-short_name:required} @@ -452,3 +566,15 @@ return [array get role_data] } + +ad_proc -private workflow::role::update_sort_order { + {-workflow_id:required} + {-sort_order:required} +} { + Increase the sort_order of other roles, if the new sort_order is already taken. +} { + set sort_order_taken_p [db_string select_sort_order_p {}] + if { $sort_order_taken_p } { + db_dml update_sort_order {} + } +} Index: openacs-4/packages/workflow/tcl/role-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/workflow/tcl/role-procs.xql,v diff -u -N -r1.7 -r1.8 --- openacs-4/packages/workflow/tcl/role-procs.xql 5 Mar 2003 17:18:10 -0000 1.7 +++ openacs-4/packages/workflow/tcl/role-procs.xql 1 Dec 2003 09:53:19 -0000 1.8 @@ -1,24 +1,6 @@ - - - select count(*) - from workflow_roles - where workflow_id = :workflow_id - and sort_order = :sort_order - - - - - - update workflow_roles - set sort_order = sort_order + 1 - where workflow_id = :workflow_id - and sort_order >= :sort_order - - - insert into workflow_roles @@ -78,6 +60,22 @@ + + + select count(*) + from workflow_roles + where workflow_id = :workflow_id + and sort_order = :sort_order + + + + + update workflow_roles + set sort_order = sort_order + 1 + where workflow_id = :workflow_id + and sort_order >= :sort_order + +