Index: openacs-4/contrib/packages/simulation/simulation.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/Attic/simulation.info,v
diff -u -r1.7 -r1.8
--- openacs-4/contrib/packages/simulation/simulation.info 14 Nov 2003 14:03:42 -0000 1.7
+++ openacs-4/contrib/packages/simulation/simulation.info 6 Jan 2004 16:10:55 -0000 1.8
@@ -19,8 +19,10 @@
-
+
+
+
Index: openacs-4/contrib/packages/simulation/tcl/apm-callback-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/apm-callback-procs.tcl,v
diff -u -r1.9 -r1.10
--- openacs-4/contrib/packages/simulation/tcl/apm-callback-procs.tcl 19 Dec 2003 14:52:21 -0000 1.9
+++ openacs-4/contrib/packages/simulation/tcl/apm-callback-procs.tcl 6 Jan 2004 16:09:33 -0000 1.10
@@ -47,3 +47,83 @@
set group_id [application_group::group_id_from_package_id -package_id $package_id]
group::delete $group_id
}
+
+ad_proc -private simulation::apm::after_mount {
+ {-package_id:required}
+ {-node_id:required}
+} {
+ Executed by APM after a simulation package instance has been mounted.
+} {
+ setup_permission_groups -package_id $package_id
+}
+
+ad_proc -private simulation::apm::setup_permission_groups {
+ {-package_id:required}
+} {
+ Set up subsite groups related to permissions.
+} {
+ # Only setup the groups if they don't already exist
+ set existing_parent_group [simulation::permission_group_id -package_id $package_id]
+ if { [empty_string_p $existing_parent_group] } {
+ # Create a new permission group
+ set parent_group_id [group::new -group_name [simulation::permission_group_name]]
+
+ # Make permission group a child of the subsite group
+ set subsite_group_id [simulation::subsite_group_id -package_id $package_id]
+ relation_add composition_rel $subsite_group_id $parent_group_id
+
+ # Create the permission groups
+ foreach {group_name privilege_list} {
+ "Sim Admins" {sim_admin}
+ "Template Authors" {sim_template_creator sim_inst sim_object_create}
+ "Case Authors" {sim_inst sim_object_create}
+ "Service Admins" {}
+ "City Admins" {sim_set_map_p sim_object_writer}
+ "Actors" {}
+ } {
+ set permission_group_id [group::new -group_name $group_name]
+
+ # Make permission group a child of the parent group
+ relation_add composition_rel $parent_group_id $permission_group_id
+
+ # Grant privileges to the group
+ foreach privilege $privilege_list {
+ permission::grant -party_id $permission_group_id -object_id $package_id -privilege $privilege
+ }
+ }
+ }
+}
+
+ad_proc -private simulation::apm::before_unmount {
+ {-package_id:required}
+ {-node_id:required}
+} {
+ Executed by the APM before a simulation package instance is unmounted.
+} {
+ teardown_permission_groups -package_id $package_id
+}
+
+ad_proc -private simulation::apm::teardown_permission_groups {
+ {-package_id:required}
+} {
+ Teardown subsite groups related to permissions.
+} {
+ # Only attempt teardown if groups exist
+ set existing_parent_group [simulation::permission_group_id -package_id $package_id]
+ if { ![empty_string_p $existing_parent_group] } {
+ # Delete the children first
+ set child_groups [db_list permission-groups {
+ select object_id_two
+ from acs_rels
+ where object_id_one = :existing_parent_group
+ and rel_type = 'composition_rel'
+ }]
+
+ foreach child_group $child_groups {
+ group::delete $child_group
+ }
+
+ # Delete the parent
+ group::delete $existing_parent_group
+ }
+}
Index: openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/simulation/tcl/Attic/simulation-procs.tcl,v
diff -u -r1.19 -r1.20
--- openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 19 Dec 2003 13:03:20 -0000 1.19
+++ openacs-4/contrib/packages/simulation/tcl/simulation-procs.tcl 6 Jan 2004 16:09:33 -0000 1.20
@@ -177,12 +177,8 @@
@author Peter Marklund
} {
- # lookup package_id of the nearest subsite
- subsite::get -array closest_subsite
-
# Lookup the application group of the subsite
- set subsite_group_id [application_group::group_id_from_package_id \
- -package_id $closest_subsite(package_id)]
+ set subsite_group_id [subsite_group_id]
# Get all groups related to (children of) the subsite group (only one level down)
set enrollment_clause [ad_decode $enrolled_only_p "0" "" "and exists (select 1
@@ -192,6 +188,7 @@
and type = 'auto_enroll'
)"]
set groups_list [list]
+ set permission_group_name [permission_group_name]
db_foreach subsite_group_options "
select g.group_name,
g.group_id,
@@ -211,6 +208,7 @@
where pamm.party_id = g.group_id
and pamm.member_id = u.user_id
)
+ and g.group_name <> :permission_group_name
$enrollment_clause
" {
lappend groups_list $group_id [list $group_name $n_users]
@@ -219,6 +217,61 @@
return $groups_list
}
+ad_proc -private simulation::permission_group_name {} {
+ Returns the name of the group holding all the user groups governing
+ permission in the simulation package.
+} {
+ return "Simulation Permission Groups"
+}
+
+ad_proc -private simulation::permission_group_id {
+ {-package_id ""}
+} {
+ Returns the id of the group holding all the user groups governing
+ permission in the simulation package.
+
+ @return The id of the permission group or
+
+ @see simulation::permission_group_name
+} {
+ if { [empty_string_p $package_id] } {
+ set package_id [ad_conn package_id]
+ }
+
+ set subsite_group_id [subsite_group_id -package_id $package_id]
+
+ set permission_group_name [permission_group_name]
+
+ # The permission group is a child of the subsite application group with a certain name
+ return [db_string permission_group_id {
+ select g.group_id
+ from acs_rels ar,
+ groups g
+ where ar.object_id_one = :subsite_group_id
+ and ar.object_id_two = g.group_id
+ and g.group_name = :permission_group_name
+ } -default ""]
+}
+
+ad_proc -private simulation::subsite_group_id {
+ {-package_id ""}
+} {
+ if { [empty_string_p $package_id] } {
+ set package_id [ad_conn package_id]
+ }
+
+ # lookup package_id of the nearest subsite
+ array set package_info [site_node::get_from_object_id -object_id $package_id]
+ set subsite_package_id [site_node::closest_ancestor_package -node_id $package_info(node_id) -package_key acs-subsite]
+ array set closest_subsite [site_node::get_from_object_id -object_id $subsite_package_id]
+
+ # Lookup the application group of the subsite
+ set subsite_group_id [application_group::group_id_from_package_id \
+ -package_id $closest_subsite(package_id)]
+
+ return $subsite_group_id
+}
+
template_tag relation { params } {
publish::process_tag relation $params
}
Index: openacs-4/packages/simulation/simulation.info
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/simulation.info,v
diff -u -r1.7 -r1.8
--- openacs-4/packages/simulation/simulation.info 14 Nov 2003 14:03:42 -0000 1.7
+++ openacs-4/packages/simulation/simulation.info 6 Jan 2004 16:10:55 -0000 1.8
@@ -19,8 +19,10 @@
-
+
+
+
Index: openacs-4/packages/simulation/tcl/apm-callback-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/apm-callback-procs.tcl,v
diff -u -r1.9 -r1.10
--- openacs-4/packages/simulation/tcl/apm-callback-procs.tcl 19 Dec 2003 14:52:21 -0000 1.9
+++ openacs-4/packages/simulation/tcl/apm-callback-procs.tcl 6 Jan 2004 16:09:33 -0000 1.10
@@ -47,3 +47,83 @@
set group_id [application_group::group_id_from_package_id -package_id $package_id]
group::delete $group_id
}
+
+ad_proc -private simulation::apm::after_mount {
+ {-package_id:required}
+ {-node_id:required}
+} {
+ Executed by APM after a simulation package instance has been mounted.
+} {
+ setup_permission_groups -package_id $package_id
+}
+
+ad_proc -private simulation::apm::setup_permission_groups {
+ {-package_id:required}
+} {
+ Set up subsite groups related to permissions.
+} {
+ # Only setup the groups if they don't already exist
+ set existing_parent_group [simulation::permission_group_id -package_id $package_id]
+ if { [empty_string_p $existing_parent_group] } {
+ # Create a new permission group
+ set parent_group_id [group::new -group_name [simulation::permission_group_name]]
+
+ # Make permission group a child of the subsite group
+ set subsite_group_id [simulation::subsite_group_id -package_id $package_id]
+ relation_add composition_rel $subsite_group_id $parent_group_id
+
+ # Create the permission groups
+ foreach {group_name privilege_list} {
+ "Sim Admins" {sim_admin}
+ "Template Authors" {sim_template_creator sim_inst sim_object_create}
+ "Case Authors" {sim_inst sim_object_create}
+ "Service Admins" {}
+ "City Admins" {sim_set_map_p sim_object_writer}
+ "Actors" {}
+ } {
+ set permission_group_id [group::new -group_name $group_name]
+
+ # Make permission group a child of the parent group
+ relation_add composition_rel $parent_group_id $permission_group_id
+
+ # Grant privileges to the group
+ foreach privilege $privilege_list {
+ permission::grant -party_id $permission_group_id -object_id $package_id -privilege $privilege
+ }
+ }
+ }
+}
+
+ad_proc -private simulation::apm::before_unmount {
+ {-package_id:required}
+ {-node_id:required}
+} {
+ Executed by the APM before a simulation package instance is unmounted.
+} {
+ teardown_permission_groups -package_id $package_id
+}
+
+ad_proc -private simulation::apm::teardown_permission_groups {
+ {-package_id:required}
+} {
+ Teardown subsite groups related to permissions.
+} {
+ # Only attempt teardown if groups exist
+ set existing_parent_group [simulation::permission_group_id -package_id $package_id]
+ if { ![empty_string_p $existing_parent_group] } {
+ # Delete the children first
+ set child_groups [db_list permission-groups {
+ select object_id_two
+ from acs_rels
+ where object_id_one = :existing_parent_group
+ and rel_type = 'composition_rel'
+ }]
+
+ foreach child_group $child_groups {
+ group::delete $child_group
+ }
+
+ # Delete the parent
+ group::delete $existing_parent_group
+ }
+}
Index: openacs-4/packages/simulation/tcl/simulation-procs.tcl
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/simulation/tcl/simulation-procs.tcl,v
diff -u -r1.19 -r1.20
--- openacs-4/packages/simulation/tcl/simulation-procs.tcl 19 Dec 2003 13:03:20 -0000 1.19
+++ openacs-4/packages/simulation/tcl/simulation-procs.tcl 6 Jan 2004 16:09:33 -0000 1.20
@@ -177,12 +177,8 @@
@author Peter Marklund
} {
- # lookup package_id of the nearest subsite
- subsite::get -array closest_subsite
-
# Lookup the application group of the subsite
- set subsite_group_id [application_group::group_id_from_package_id \
- -package_id $closest_subsite(package_id)]
+ set subsite_group_id [subsite_group_id]
# Get all groups related to (children of) the subsite group (only one level down)
set enrollment_clause [ad_decode $enrolled_only_p "0" "" "and exists (select 1
@@ -192,6 +188,7 @@
and type = 'auto_enroll'
)"]
set groups_list [list]
+ set permission_group_name [permission_group_name]
db_foreach subsite_group_options "
select g.group_name,
g.group_id,
@@ -211,6 +208,7 @@
where pamm.party_id = g.group_id
and pamm.member_id = u.user_id
)
+ and g.group_name <> :permission_group_name
$enrollment_clause
" {
lappend groups_list $group_id [list $group_name $n_users]
@@ -219,6 +217,61 @@
return $groups_list
}
+ad_proc -private simulation::permission_group_name {} {
+ Returns the name of the group holding all the user groups governing
+ permission in the simulation package.
+} {
+ return "Simulation Permission Groups"
+}
+
+ad_proc -private simulation::permission_group_id {
+ {-package_id ""}
+} {
+ Returns the id of the group holding all the user groups governing
+ permission in the simulation package.
+
+ @return The id of the permission group or
+
+ @see simulation::permission_group_name
+} {
+ if { [empty_string_p $package_id] } {
+ set package_id [ad_conn package_id]
+ }
+
+ set subsite_group_id [subsite_group_id -package_id $package_id]
+
+ set permission_group_name [permission_group_name]
+
+ # The permission group is a child of the subsite application group with a certain name
+ return [db_string permission_group_id {
+ select g.group_id
+ from acs_rels ar,
+ groups g
+ where ar.object_id_one = :subsite_group_id
+ and ar.object_id_two = g.group_id
+ and g.group_name = :permission_group_name
+ } -default ""]
+}
+
+ad_proc -private simulation::subsite_group_id {
+ {-package_id ""}
+} {
+ if { [empty_string_p $package_id] } {
+ set package_id [ad_conn package_id]
+ }
+
+ # lookup package_id of the nearest subsite
+ array set package_info [site_node::get_from_object_id -object_id $package_id]
+ set subsite_package_id [site_node::closest_ancestor_package -node_id $package_info(node_id) -package_key acs-subsite]
+ array set closest_subsite [site_node::get_from_object_id -object_id $subsite_package_id]
+
+ # Lookup the application group of the subsite
+ set subsite_group_id [application_group::group_id_from_package_id \
+ -package_id $closest_subsite(package_id)]
+
+ return $subsite_group_id
+}
+
template_tag relation { params } {
publish::process_tag relation $params
}