• Publicity: Public Only All

application-group-procs.tcl

Procs to manage application groups

Location:
packages/acs-subsite/tcl/application-group-procs.tcl
Created:
2001-02-01
Author:
oumi@arsdigita.com
CVS Identification:
$Id: application-group-procs.tcl,v 1.23.2.3 2022/10/26 14:20:35 gustafn Exp $

Procedures in this file

Detailed information

application_group::child_application_groups (public, deprecated)

 application_group::child_application_groups -node_id node_id \
    [ -package_key package_key ]
Deprecated. Invoking this procedure generates a warning.

DEPRECATED: as of 2022-09-12 this API is not used in upstream codebase, and was still undocumented.

Switches:
-node_id
(required)
-package_key
(optional)

Partial Call Graph (max 5 caller/called nodes):
%3 ad_log_deprecated ad_log_deprecated (public) application_group::group_id_from_package_id application_group::group_id_from_package_id (public) site_node::get_children site_node::get_children (public) application_group::child_application_groups application_group::child_application_groups application_group::child_application_groups->ad_log_deprecated application_group::child_application_groups->application_group::group_id_from_package_id application_group::child_application_groups->site_node::get_children

Testcases:
No testcase defined.

application_group::closest_ancestor_application_group_id (public)

 application_group::closest_ancestor_application_group_id [ -url url ] \
    [ -node_id node_id ] [ -include_self ]

Application group id of the closest ancestor package that has an application group

Switches:
-url
(optional)
URL of the node to start searching from.
-node_id
(optional)
node_id of the node to start searching from (only one of node_id and URL can be specified).
-include_self
(boolean) (optional)
If true, include the current package in the search
Returns:
group_id of the closest ancestor package that has an application group, if any.

Partial Call Graph (max 5 caller/called nodes):
%3 test_subsite_api subsite_api (test acs-subsite) application_group::closest_ancestor_application_group_id application_group::closest_ancestor_application_group_id test_subsite_api->application_group::closest_ancestor_application_group_id application_group::closest_ancestor_element application_group::closest_ancestor_element (public) application_group::closest_ancestor_application_group_id->application_group::closest_ancestor_element

Testcases:
subsite_api

application_group::closest_ancestor_application_group_site_node (public)

 application_group::closest_ancestor_application_group_site_node \
    [ -url url ] [ -node_id node_id ] [ -include_self ]

Starting with the node with the given node_id (or URL), climb up the site map and return the node of the first non null application group

Switches:
-url
(optional)
The URL of the node to start from. You must provide either URL or node_id. An empty URL is taken to mean the main site.
-node_id
(optional)
The id of the node to start from. Takes precedence over any provided URL.
-include_self
(boolean) (optional)
If true, include the current package in the search
Returns:
The node of the first non-null application group in array get format.
Author:
Peter Marklund, Dave Bauer

Partial Call Graph (max 5 caller/called nodes):
%3 test_subsite_api subsite_api (test acs-subsite) application_group::closest_ancestor_application_group_site_node application_group::closest_ancestor_application_group_site_node test_subsite_api->application_group::closest_ancestor_application_group_site_node application_group::group_id_from_package_id application_group::group_id_from_package_id (public) application_group::closest_ancestor_application_group_site_node->application_group::group_id_from_package_id site_node::get site_node::get (public) application_group::closest_ancestor_application_group_site_node->site_node::get site_node::get_url site_node::get_url (public) application_group::closest_ancestor_application_group_site_node->site_node::get_url application_group::closest_ancestor_element application_group::closest_ancestor_element (public) application_group::closest_ancestor_element->application_group::closest_ancestor_application_group_site_node

Testcases:
subsite_api

application_group::closest_ancestor_element (public)

 application_group::closest_ancestor_element [ -node_id node_id ] \
    [ -url url ] -element element [ -include_self ]

Return one element of the site node for the closest ancestor package that has an application group.

Switches:
-node_id
(optional)
node_id of the node to start searching from (only one of node_id and URL can be specified).
-url
(optional)
URL of the node to start searching from.
-element
(required)
-include_self
(boolean) (optional)
If true, include the current package in the search
Returns:
element The desired element of the appropriate site node.

Partial Call Graph (max 5 caller/called nodes):
%3 test_subsite_api subsite_api (test acs-subsite) application_group::closest_ancestor_element application_group::closest_ancestor_element test_subsite_api->application_group::closest_ancestor_element application_group::closest_ancestor_application_group_site_node application_group::closest_ancestor_application_group_site_node (public) application_group::closest_ancestor_element->application_group::closest_ancestor_application_group_site_node application_group::closest_ancestor_application_group_id application_group::closest_ancestor_application_group_id (public) application_group::closest_ancestor_application_group_id->application_group::closest_ancestor_element news_do_notification news_do_notification (public) news_do_notification->application_group::closest_ancestor_element

Testcases:
subsite_api

application_group::contains_party_p (public)

 application_group::contains_party_p [ -package_id package_id ] \
    [ -party_id party_id ] [ -include_self ]

Determines whether the party in question (identified by party_id) is contained by the application group identified by package_id. If package_id is not specified, and we have a connection, then the proc will grab the package_id of the current package (i.e., [ad_conn package_id]).

Switches:
-package_id
(optional)
-party_id
(optional)
-include_self
(boolean) (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_subsite_api subsite_api (test acs-subsite) application_group::contains_party_p application_group::contains_party_p test_subsite_api->application_group::contains_party_p ad_conn ad_conn (public) application_group::contains_party_p->ad_conn db_string db_string (public) application_group::contains_party_p->db_string packages/acs-subsite/www/admin/groups/change-join-policy-2.tcl packages/acs-subsite/ www/admin/groups/change-join-policy-2.tcl packages/acs-subsite/www/admin/groups/change-join-policy-2.tcl->application_group::contains_party_p packages/acs-subsite/www/admin/groups/change-join-policy.tcl packages/acs-subsite/ www/admin/groups/change-join-policy.tcl packages/acs-subsite/www/admin/groups/change-join-policy.tcl->application_group::contains_party_p packages/acs-subsite/www/admin/groups/one.tcl packages/acs-subsite/ www/admin/groups/one.tcl packages/acs-subsite/www/admin/groups/one.tcl->application_group::contains_party_p packages/acs-subsite/www/admin/parties/one.tcl packages/acs-subsite/ www/admin/parties/one.tcl packages/acs-subsite/www/admin/parties/one.tcl->application_group::contains_party_p packages/acs-subsite/www/admin/rel-segments/new-2.tcl packages/acs-subsite/ www/admin/rel-segments/new-2.tcl packages/acs-subsite/www/admin/rel-segments/new-2.tcl->application_group::contains_party_p

Testcases:
subsite_api

application_group::contains_relation_p (public)

 application_group::contains_relation_p [ -package_id package_id ] \
    [ -rel_id rel_id ]

Determines whether the relation in question (identified by rel_id) is contained by the application group identified by package_id. If package_id is not specified, and we have a connection, then the proc will grab the package_id of the current package (i.e., [ad_conn package_id]).

Switches:
-package_id
(optional)
-rel_id
(optional)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/acs-subsite/www/admin/rel-segments/new-2.tcl packages/acs-subsite/ www/admin/rel-segments/new-2.tcl application_group::contains_relation_p application_group::contains_relation_p packages/acs-subsite/www/admin/rel-segments/new-2.tcl->application_group::contains_relation_p packages/acs-subsite/www/admin/rel-segments/new-3.tcl packages/acs-subsite/ www/admin/rel-segments/new-3.tcl packages/acs-subsite/www/admin/rel-segments/new-3.tcl->application_group::contains_relation_p packages/acs-subsite/www/admin/relations/change-member-state.tcl packages/acs-subsite/ www/admin/relations/change-member-state.tcl packages/acs-subsite/www/admin/relations/change-member-state.tcl->application_group::contains_relation_p packages/acs-subsite/www/admin/relations/one.tcl packages/acs-subsite/ www/admin/relations/one.tcl packages/acs-subsite/www/admin/relations/one.tcl->application_group::contains_relation_p packages/acs-subsite/www/admin/relations/remove.tcl packages/acs-subsite/ www/admin/relations/remove.tcl packages/acs-subsite/www/admin/relations/remove.tcl->application_group::contains_relation_p ad_conn ad_conn (public) application_group::contains_relation_p->ad_conn db_string db_string (public) application_group::contains_relation_p->db_string

Testcases:
No testcase defined.

application_group::contains_segment_p (public)

 application_group::contains_segment_p [ -package_id package_id ] \
    [ -segment_id segment_id ]

Determines whether the segment in question (identified by segment_id) "belongs" to the application group identified by package_id. If package_id is not specified, and we have a connection, then the proc will grab the package_id of the current package (i.e., [ad_conn package_id]).

Switches:
-package_id
(optional)
-segment_id
(optional)

Partial Call Graph (max 5 caller/called nodes):
%3 packages/acs-subsite/www/admin/rel-segments/constraints/new.tcl packages/acs-subsite/ www/admin/rel-segments/constraints/new.tcl application_group::contains_segment_p application_group::contains_segment_p packages/acs-subsite/www/admin/rel-segments/constraints/new.tcl->application_group::contains_segment_p packages/acs-subsite/www/admin/rel-segments/edit.tcl packages/acs-subsite/ www/admin/rel-segments/edit.tcl packages/acs-subsite/www/admin/rel-segments/edit.tcl->application_group::contains_segment_p packages/acs-subsite/www/admin/rel-segments/one.tcl packages/acs-subsite/ www/admin/rel-segments/one.tcl packages/acs-subsite/www/admin/rel-segments/one.tcl->application_group::contains_segment_p ad_conn ad_conn (public) application_group::contains_segment_p->ad_conn db_string db_string (public) application_group::contains_segment_p->db_string

Testcases:
No testcase defined.

application_group::delete (public)

 application_group::delete -group_id group_id

Delete the given application group and all relational segments and constraints dependent on it (handled by the PL/[pg]SQL API

Switches:
-group_id
(required)

Partial Call Graph (max 5 caller/called nodes):
%3 test_acs_subsite_application_group_new acs_subsite_application_group_new (test acs-subsite) application_group::delete application_group::delete test_acs_subsite_application_group_new->application_group::delete db_dml db_dml (public) application_group::delete->db_dml db_exec_plsql db_exec_plsql (public) application_group::delete->db_exec_plsql db_flush_cache db_flush_cache (public) application_group::delete->db_flush_cache subsite::default::delete_app_group subsite::default::delete_app_group (public) subsite::default::delete_app_group->application_group::delete

Testcases:
acs_subsite_application_group_new

application_group::group_id_from_package_id (public)

 application_group::group_id_from_package_id [ -no_complain ] \
    [ -package_id package_id ]

Get the application_group of a package. By default, if no application group exists, we throw an error. The -no_complain flag will prevent the error from being thrown, in which case you'll just get an empty string if the application group doesn't exist.

Switches:
-no_complain
(boolean) (optional)
-package_id
(optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_acs_subsite_expose_bug_1144 acs_subsite_expose_bug_1144 (test acs-subsite) application_group::group_id_from_package_id application_group::group_id_from_package_id test_acs_subsite_expose_bug_1144->application_group::group_id_from_package_id test_subsite_api subsite_api (test acs-subsite) test_subsite_api->application_group::group_id_from_package_id acs_object_name acs_object_name (public) application_group::group_id_from_package_id->acs_object_name ad_conn ad_conn (public) application_group::group_id_from_package_id->ad_conn db_string db_string (public) application_group::group_id_from_package_id->db_string application_group::child_application_groups application_group::child_application_groups (public, deprecated) application_group::child_application_groups->application_group::group_id_from_package_id application_group::closest_ancestor_application_group_site_node application_group::closest_ancestor_application_group_site_node (public) application_group::closest_ancestor_application_group_site_node->application_group::group_id_from_package_id group::get_id_not_cached group::get_id_not_cached (private) group::get_id_not_cached->application_group::group_id_from_package_id install::xml::object_id::application-group install::xml::object_id::application-group (public) install::xml::object_id::application-group->application_group::group_id_from_package_id packages/acs-authentication/lib/search.tcl packages/acs-authentication/ lib/search.tcl packages/acs-authentication/lib/search.tcl->application_group::group_id_from_package_id

Testcases:
acs_subsite_expose_bug_1144, subsite_api

application_group::new (public)

 application_group::new [ -group_id group_id ] \
    [ -group_type group_type ] [ -package_id package_id ] \
    [ -group_name group_name ] [ -creation_user creation_user ] \
    [ -creation_ip creation_ip ] [ -email email ] [ -url url ]

Creates an application group (i.e., group of "users/parties of this application") Returns the group_id of the new application group.

Switches:
-group_id
(optional)
-group_type
(defaults to "application_group") (optional)
-package_id
(optional)
-group_name
(optional)
-creation_user
(optional)
-creation_ip
(optional)
-email
(optional)
-url
(optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_acs_subsite_application_group_new acs_subsite_application_group_new (test acs-subsite) application_group::new application_group::new test_acs_subsite_application_group_new->application_group::new ad_conn ad_conn (public) application_group::new->ad_conn db_exec_plsql db_exec_plsql (public) application_group::new->db_exec_plsql db_string db_string (public) application_group::new->db_string db_transaction db_transaction (public) application_group::new->db_transaction subsite::default::create_app_group subsite::default::create_app_group (public) subsite::default::create_app_group->application_group::new

Testcases:
acs_subsite_application_group_new

application_group::package_id_from_group_id (public)

 application_group::package_id_from_group_id -group_id group_id

Returns the package_id of a given application group.

Switches:
-group_id
(required)

Partial Call Graph (max 5 caller/called nodes):
%3 test_subsite_api subsite_api (test acs-subsite) application_group::package_id_from_group_id application_group::package_id_from_group_id test_subsite_api->application_group::package_id_from_group_id db_string db_string (public) application_group::package_id_from_group_id->db_string packages/acs-subsite/www/members/member-state-change.tcl packages/acs-subsite/ www/members/member-state-change.tcl packages/acs-subsite/www/members/member-state-change.tcl->application_group::package_id_from_group_id

Testcases:
subsite_api
[ hide source ] | [ make this the default ]

Content File Source

# /packages/subsite/tcl/application-group-procs.tcl

ad_library {

    Procs to manage application groups

    @author oumi@arsdigita.com
    @creation-date 2001-02-01
    @cvs-id $Id: application-group-procs.tcl,v 1.23.2.3 2022/10/26 14:20:35 gustafn Exp $

}

namespace eval application_group {}

d_proc -public application_group::contains_party_p {
    { -package_id "" }
    { -party_id "" }
    -include_self:boolean
} {
    Determines whether the party in question (identified by party_id) is
    contained by the application group identified by package_id.
    If package_id is not specified, and we have a connection, then the
    proc will grab the package_id of the current package (i.e.,
    [ad_conn package_id]).

} {

    if {$package_id eq "" && [ns_conn isconnected]} {
        set package_id [ad_conn package_id]
    }

    if {$package_id eq ""} {
        error "application_group::contains_party_p - package_id not specified"
    }

    # Check if the party is a member of the application group, OR
    # the party *is* the application group.  This proc considers the
    # application group to contain itself.
    if {$include_self_p} {
    set found_p [db_string app_group_contains_party_p {
        select case when exists (
            select 1
            from application_group_element_map
            where package_id = :package_id
              and element_id = :party_id
          union all
            select 1
            from application_groups
            where package_id = :package_id
              and group_id = :party_id
        ) then 1 else 0 end
        from dual
    }]
    } else {
    set found_p [db_string app_group_contains_party_p {
        select case when exists (
            select 1
            from application_group_element_map
            where package_id = :package_id
              and element_id = :party_id
        ) then 1 else 0 end
        from dual
    }]

    }

    return $found_p

}

d_proc -public application_group::contains_relation_p {
    { -package_id "" }
    { -rel_id "" }
} {
    Determines whether the relation in question (identified by rel_id) is
    contained by the application group identified by package_id.
    If package_id is not specified, and we have a connection, then the
    proc will grab the package_id of the current package (i.e.,
    [ad_conn package_id]).
} {

    if {$package_id eq "" && [ns_conn isconnected]} {
        set package_id [ad_conn package_id]
    }

    if {$package_id eq ""} {
        error "application_group::contains_party_p - package_id not specified"
    }

    # Check if the rel belongs to the application group, OR
    # the party *is* the application group.  This proc considers the
    # application group to contain itself.
    set found_p [db_string app_group_contains_rel_p {
        select case when exists (
            select 1
            from application_group_element_map
            where package_id = :package_id
              and rel_id = :rel_id
        ) then 1 else 0 end
        from dual
    }]

    return $found_p
}

d_proc -public application_group::contains_segment_p {
    { -package_id "" }
    { -segment_id "" }
} {
    Determines whether the segment in question (identified by segment_id)
    "belongs" to the application group identified by package_id.
    If package_id is not specified, and we have a connection, then the
    proc will grab the package_id of the current package (i.e.,
    [ad_conn package_id]).

} {

    if {$package_id eq "" && [ns_conn isconnected]} {
        set package_id [ad_conn package_id]
    }

    if {$package_id eq ""} {
        error "application_group::contains_segment_p - package_id not specified"
    }

    # Check if the party is a member of the application group, OR
    # the party *is* the application group.  This proc considers the
    # application group to contain itself.
    set found_p [db_string app_group_contains_segment_p {
        select case when exists (
            select 1
            from application_group_segments
            where package_id = :package_id
              and segment_id = :segment_id
        ) then 1 else 0 end
        from dual
    }]

    return $found_p
}


d_proc -public application_group::group_id_from_package_id {
    -no_complain:boolean
    { -package_id "" }
} {
    Get the application_group of a package.  By default, if no application
    group exists, we throw an error.  The -no_complain flag will prevent
    the error from being thrown, in which case you'll just get an
    empty string if the application group doesn't exist.
} {

    if { [ns_conn isconnected] && $package_id eq "" } {
        set package_id [ad_conn package_id]
    }

    if {$package_id eq ""} {
        error "application_group::group_id_from_package_id - no package_id specified."
    }

    set group_id [db_string application_group_from_package_id_query {
        select group_id
        from application_groups
        where package_id = :package_id
    } -default ""]

    if {!$no_complain_p && $group_id eq ""} {
        error "No group_id found for package $package_id ([acs_object_name $package_id])"
    }

    return $group_id
}

d_proc -public application_group::package_id_from_group_id {
    -group_id:required
} {

    Returns the package_id of a given application group.

} {
    return [db_string -cache_key application_group_pid_from_gid_${group_id} get {
        select package_id
        from application_groups
        where group_id = :group_id
    }]
}

d_proc -public application_group::new {
    { -group_id "" }
    { -group_type "application_group"}
    { -package_id "" }
    { -group_name "" }
    { -creation_user "" }
    { -creation_ip "" }
    { -email "" }
    { -url "" }
} {
    Creates an application group
    (i.e., group of "users/parties of this application")

    Returns the group_id of the new application group.
} {

    if { [ns_conn isconnected] } {
        # Since we have a connection, default user_id / peeraddr
        # if they're not specified
        if { $creation_user eq "" } {
            set creation_user [ad_conn user_id]
        }
        if { $creation_ip eq "" } {
            set creation_ip [ad_conn peeraddr]
        }
        if { $package_id eq "" } {
            set package_id [ad_conn package_id]
        }
    }

    if {$package_id eq ""} {
        error "application_group::new - package_id not specified"
    }

    if {$group_name eq ""} {
        set group_name [db_string group_name_query {
            select substr(instance_name, 1, 90)
            from apm_packages
            where package_id = :package_id
        }]
        append group_name " Parties"
    }

    db_transaction {
        # creating the new group
        set group_id [db_exec_plsql add_group {}]
    }

    return $group_id

}

d_proc -public application_group::delete {
    -group_id:required
} {
    Delete the given application group and all relational segments and constraints dependent
    on it (handled by the PL/[pg]SQL API
} {
    # LARS HACK:
    # Delete permissions on:
    # - the application group
    # - any relational segment of this group
    # - any relation with this group
    # We really ought to have cascading deletes on acs_permissions.grantee_id (and object_id)
    db_dml delete_perms {
        delete from acs_permissions
        where  grantee_id = :group_id
        or     grantee_id in (select segment_id from rel_segments where group_id = :group_id)
        or     grantee_id in (select rel_id from acs_rels where object_id_one = :group_id or object_id_two = :group_id)
    }

    db_exec_plsql delete {}

    db_flush_cache -cache_key_pattern application_group_*

}

d_proc -public application_group::closest_ancestor_application_group_site_node {
    {-url ""}
    {-node_id ""}
    {-include_self:boolean}
} {
    Starting with the node with the given node_id (or URL),
    climb up the site map and return the node of the first
    non null application group

    @param url          The URL of the node to start from. You must provide
                        either URL or node_id. An empty URL is taken to mean
                        the main site.
    @param node_id      The id of the node to start from. Takes precedence
                        over any provided URL.
    @param include_self If true, include the current package in the search

    @return The node of the first non-null application group in array get format.

    @author Peter Marklund, Dave Bauer
} {
    # Make sure we have a URL to work with
    if { $url eq "" } {
          if { $node_id eq "" } {
              set url "/"
          } else {
              set url [site_node::get_url -node_id $node_id]
          }
    }

    set group_id ""
    while {$group_id eq "" && $url ne ""} {

        if { $include_self_p } {
            array set node_array [site_node::get -url $url]
            set group_id [application_group::group_id_from_package_id \
                             -package_id $node_array(package_id) \
                             -no_complain]
        }

        set include_self_p 1

        # move up a level
        set url [string trimright $url /]
        set url [string range $url 0 [string last / $url]]
    }
    if {$group_id eq ""} {
        array unset -no_complain node_array
    }
    set node_array(application_group_id) $group_id

    return [array get node_array]
}

d_proc -public application_group::closest_ancestor_element {
    {-node_id ""}
    {-url ""}
    {-element:required}
    {-include_self:boolean}
} {
    Return one element of the site node for the closest ancestor package that has an
    application group.

    @param url URL of the node to start searching from.
    @param node_id node_id of the node to start searching from (only one of node_id and URL
           can be specified).
    @param include_self If true, include the current package in the search

    @return element The desired element of the appropriate site node.
} {
    array set site_node \
        [application_group::closest_ancestor_application_group_site_node \
            -include_self=$include_self_p \
            -url $url \
            -node_id $node_id]
    return $site_node($element)
}

d_proc -public application_group::closest_ancestor_application_group_id {
    {-url ""}
    {-node_id ""}
    {-include_self:boolean}
} {
    Application group id of the closest ancestor package that has an application
    group

    @param url URL of the node to start searching from.
    @param node_id node_id of the node to start searching from (only one of node_id and URL
           can be specified).
    @param include_self If true, include the current package in the search

    @return group_id of the closest ancestor package that has an application group, if any.
} {
    return [application_group::closest_ancestor_element \
               -include_self=$include_self_p \
               -url $url \
               -node_id $node_id \
               -element application_group_id]
}

d_proc -deprecated application_group::child_application_groups {
    -node_id:required
    {-package_key ""}
} {
    DEPRECATED: as of 2022-09-12 this API is not used in upstream
    codebase, and was still undocumented.
} {
    set group_list [list]
    set child_packages [site_node::get_children -package_key $package_key -node_id $node_id -element package_id]
    foreach package_id $child_packages {
        if {[set group_id [application_group::group_id_from_package_id -package_id ${package_id} -no_complain]] ne ""} {
            lappend group_list $group_id
        }
    }
    return $group_list
}

# Local variables:
#    mode: tcl
#    tcl-indent-level: 4
#    indent-tabs-mode: nil
# End: