Index: openacs-4/packages/acs-kernel/sql/oracle/groups-body-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-kernel/sql/oracle/groups-body-create.sql,v
diff -u -r1.17 -r1.18
--- openacs-4/packages/acs-kernel/sql/oracle/groups-body-create.sql	14 Feb 2009 19:22:59 -0000	1.17
+++ openacs-4/packages/acs-kernel/sql/oracle/groups-body-create.sql	7 Aug 2017 23:47:56 -0000	1.18
@@ -50,9 +50,10 @@
       raise_application_error(-20000,v_error);
   end if;
 
-  select object_id_one, object_id_two, rel_type
+  select object_id_one, object_id_two, r.rel_type, composable_p
   into v_object_id_one, v_object_id_two, v_rel_type
-  from acs_rels
+  from acs_rels r
+  join acs_rel_types t on (r.rel_type = t.rel_type)
   where rel_id = :new.rel_id;
 
   -- Insert a row for me in the group_member_index.
@@ -67,23 +68,25 @@
     party_approved_member.add(v_object_id_one, v_object_id_two, v_rel_type);
   end if;
 
-  -- For all groups of which I am a component, insert a
-  -- row in the group_member_index.
-  for map in (select distinct group_id
-	      from group_component_map
-	      where component_id = v_object_id_one) loop
-    insert into group_element_index
-     (group_id, element_id, rel_id, container_id,
-      rel_type, ancestor_rel_type)
-    values
-     (map.group_id, v_object_id_two, :new.rel_id, v_object_id_one,
-      v_rel_type, 'membership_rel');
+  if v_composable_p = 't' then
+    -- For all groups of which I am a component, insert a
+    -- row in the group_member_index.
+    for map in (select distinct group_id
+	        from group_component_map
+	        where component_id = v_object_id_one) loop
+          insert into group_element_index
+          (group_id, element_id, rel_id, container_id,
+          rel_type, ancestor_rel_type)
+          values
+          (map.group_id, v_object_id_two, :new.rel_id, v_object_id_one,
+          v_rel_type, 'membership_rel');
 
-    if :new.member_state = 'approved' then
-      party_approved_member.add(map.group_id, v_object_id_two, v_rel_type);
-    end if;
+          if :new.member_state = 'approved' then
+             party_approved_member.add(map.group_id, v_object_id_two, v_rel_type);
+          end if;
 
-  end loop;
+    end loop;
+  end if;
 end;
 /
 show errors
@@ -157,23 +160,25 @@
     party_approved_member.add(v_object_id_one, members.member_id, members.rel_type);
   end loop;
 
-  -- Make my elements be elements of my new composite group
+  -- Make my composable elements be elements of my new composite group
   insert into group_element_index
    (group_id, element_id, rel_id, container_id,
     rel_type, ancestor_rel_type)
   select distinct
    v_object_id_one, element_id, rel_id, container_id,
-   rel_type, ancestor_rel_type
+   m.rel_type, ancestor_rel_type
   from group_element_map m
+  join acs_rel_types t on (m.rel_type = t.rel_type)
   where group_id = v_object_id_two
+  and t.composable_p = 't'
   and not exists (select 1
 		  from group_element_map
 		  where group_id = v_object_id_one
 		  and element_id = m.element_id
 		  and rel_id = m.rel_id);
 
   -- For all direct or indirect containers of my new composite group, 
-  -- add me and add my elements
+  -- add me and add my composable elements
   for map in (select distinct group_id
 	      from group_component_map
 	      where component_id = v_object_id_one) loop
@@ -186,11 +191,13 @@
      (map.group_id, v_object_id_two, :new.rel_id, v_object_id_one,
       v_rel_type, 'composition_rel');
 
-    -- Add rows for my elements
+    -- Add rows for my composable elements
 
     for members in (select distinct member_id, rel_type
                     from group_approved_member_map m
+                     join acs_rel_types t on (m.rel_type = t.rel_type)
                     where group_id = v_object_id_two
+                      and t.composable_p = 't'
                       and not exists (select 1
 		                      from group_element_map
 		                      where group_id = map.group_id
@@ -207,7 +214,9 @@
      map.group_id, element_id, rel_id, container_id,
      rel_type, ancestor_rel_type
     from group_element_map m
+    join acs_rel_types t on (m.rel_type = t.rel_type)
     where group_id = v_object_id_two
+    and t.composable_p = 't'
     and not exists (select 1
 		    from group_element_map
 		    where group_id = map.group_id
@@ -877,7 +886,7 @@
   else
     select count(*)
       into m_result
-      from acs_rels rels, all_object_party_privilege_map perm
+      from acs_rels rels, acs_object_party_privilege_map perm
     where perm.object_id = rels.rel_id
            and perm.privilege = 'read'
            and rels.rel_type = 'membership_rel'
