The Toolkit for Online Communities
17221 Community Members, 0 members online, 1984 visitors today
Log In Register
OpenACS Home : Forums : OpenACS Development : Howto: Expand and Use acs-subsite Based Member Roles : One Message

Forum OpenACS Development: Re: Howto: Expand and Use acs-subsite Based Member Roles

Posted by Randy O'Meara on
As I sharpened my filet knife I realized that the roles and types I had created were general-purpose roles that I may want to use in other packages and such. So instead of carving the roles from the system, I refactored the code that creates roles, types, and associates thier use with Application Groups so that it would extend whatever roles were present with the roles that were not present. Here's the new code. BTW, this makes it a very simple matter to extend the roles further by adding a single entry in the roles_rel list structure. Maybe this is a canditate to add to the acs-subsite admin UI?

ad_proc -private rel_types_extend {
} {

    Extend the standard oacs application group roles and relation types of
    Members and Administrators with Guests and Managers.

    Since these additional roles/types are general purpose, we'll leave
    them installed when our package is removed. We'll also use the roles
    if they already exist, whether we created them or something else did.

    When this proc completes, the following will exist:

    	--Role--      --Rel--
    	Guest	      guest_rel (extension)
    	Member	      membership_rel (standard)
    	Manager	      manager_rel (extension)
    	Administrator admin_rel (standard)

    There is the assumption that, if a required role already exists,
    then it is correctly configured with the proper rel_type and that 
    it is also a registered type for Application Groups. Conversely,
    if the role does not yet exist, then the role, its rel_type, and
    association with group type Application Group is configured.
} {

    # Map required roles to rels (add new roles & rels here)
    #                     --Role--      --Pretty--    --Plural--     --Rel Type--
    set roles_rels "[list guest	        Guest         Guests         guest_rel] \
		    [list member        Member        Members        membership_rel] \
		    [list manager       Manager       Managers       manager_rel] \
		    [list admin         Administrator Administrators admin_rel]"

    foreach {role pn pp rel} $roles_rels {

	# Base existence check on existing role
	if {[db_0or1row role_exists {
	    select r.pretty_name from acs_rel_roles r where r.role=:role
	}]} {

	} else {

	    # Extend roles
	    db_1row new_role {select acs_rel_type__create_role(:role, :pn, :pp)}

	    # Extend rel types
	    set m_rel_type [rel_types::new -supertype "membership_rel" \
			    -role_one "" -role_two $role \
			    $rel $pn $pp "group" "0" "" "person" "0" "1"]

	    # Associate with group type Application Group
	    rel_types::add_permissible application_group $rel