Forum OpenACS Q&A: Response to Manual manipulation of users and groups

Collapse
Posted by Reuven Lerner on

Thanks to everyone for their advice several months ago, I've managed to get just about everything done that I wanted. However, I'm struggling over how to create a new group and give it a composition relation with the main group for the current subsite.

That is: I have several subsites, each of which has its own group of users. (So for the "foo" subsite, OpenACS gives me a "foo parties" group.) I'm trying to create a form that lets me enter information about a new user and the name of a group to which this user should be added. If the named group exists, then we simply add this user to the group. If the named group doesn't exist, then I create the group, give it a composition relation to the subsite's group, and then add the user to the group.

I've been pouring over the documentation, actual OpenACS code, and help that people have given on the bboard, and I'm finding myself stuff. That is, I have the following code:

ns_log Notice "


About to create the new group (community) with id '$group_id'


"

db_transaction {

    # Add the new group
    group::new -group_id $group_id -context_id [ad_conn package_id] -group_name $community_name "group" 

    # Get the group ID for this subsite's default group
    set add_to_group_id [site_node_closest_ancestor_package "acs-subsite"]

    # Create a composition relation between our the subsite's group and our new group
    ns_log Notice "About to execute:


relation_add composition_rel $add_to_group_id $group_id


"

    set relation_id [relation_add "composition_rel" $add_to_group_id $group_id]
    ns_log Notice "New relation_id is $relation_id


"
}

Everything seems to work fine until I invoke relation_add, which fails on me. My "about to execute" log message looks like:

relation_add composition_rel 7272 7653

which seems pretty normal to me, since 7272 is the group for the current subsite, and 7653 is the ID of the new group I just created and want to attach. So I'm guessing that I have failed to understand something having to do with creating a new group (which appears to be working just fine) and/or giving it a composition relation with the subsite's group.

When I run the Pl/PgSQL query by hand, it looks like this:

select composition_rel__new(NULL,'composition_rel','7299',7606,'2537','212.29.241.228');
NOTICE:  Adding missing FROM-clause entry for table "acs_object_id_seq"
NOTICE:  identifier "acs_object__initialize_attributes" will be truncated to "acs_object__initialize_attribut"
NOTICE:  identifier "acs_object_type_get_tree_sortkey" will be truncated to "acs_object_type_get_tree_sortke"
NOTICE:  identifier "acs_object_type_get_tree_sortkey" will be truncated to "acs_object_type_get_tree_sortke"
ERROR:  -20001: composition_rel  violation: Invalid object types. Object 7299 () must be of type  Object 7606 () must be of type 

So:

  • Am I making a mistake when creating my group? (It appears in the groups table, but perhaps that's not enough?)
  • Am I making a mistake when adding the composition relation?
  • Is this simply a bug in OpenACS that I should have been smart enough to avoid?