Index: openacs-4/packages/dotlrn-ecommerce/dotlrn-ecommerce.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/dotlrn-ecommerce.info,v diff -u -r1.32 -r1.33 --- openacs-4/packages/dotlrn-ecommerce/dotlrn-ecommerce.info 1 Sep 2005 12:23:21 -0000 1.32 +++ openacs-4/packages/dotlrn-ecommerce/dotlrn-ecommerce.info 1 Sep 2005 20:58:54 -0000 1.33 @@ -7,21 +7,22 @@ f t - + Roel Canicula Package to tie the dotLRN, Ecommerce, Assessments and dotLRN Catalog packages together 2005-08-10 Solution Grove Package to tie the dotLRN, Ecommerce, Assessments and dotLRN Catalog packages together. Initially intended for the MOS and MGH projects, the goal is to create a reusable module for similar projects. 0 - + + Index: openacs-4/packages/dotlrn-ecommerce/tcl/dotlrn-ecommerce-init.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/tcl/dotlrn-ecommerce-init.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/packages/dotlrn-ecommerce/tcl/dotlrn-ecommerce-init.tcl 25 Aug 2005 19:07:48 -0000 1.4 +++ openacs-4/packages/dotlrn-ecommerce/tcl/dotlrn-ecommerce-init.tcl 1 Sep 2005 20:58:53 -0000 1.5 @@ -13,4 +13,14 @@ ad_schedule_proc -thread t 300 dotlrn_ecommerce::section::check_elapsed_registrations ad_schedule_proc -thread t 600 dotlrn_ecommerce::section::check_and_approve_sections_for_slots ad_schedule_proc -thread t -schedule_proc ns_schedule_daily [list 23 50] dotlrn_ecommerce::notify_admins_of_waitlist -ad_schedule_proc -thread t -once t 660 dotlrn_ecommerce::check_expired_orders_once \ No newline at end of file +ad_schedule_proc -thread t -once t 660 dotlrn_ecommerce::check_expired_orders_once + +# Check if we're allowing access to dotLRN community for approved users, +# this should be done every restart +if { [parameter::get -parameter AllowAheadAccess -package_id [apm_package_id_from_key dotlrn-ecommerce] -default 0] } { + ns_log notice "dotlrn-ecommerce-init.tcl: Allowing community access to approved member states, this modifies dotlrn_member_rels_approved and the membership_rels_up_tr function" + dotlrn_ecommerce::allow_access_to_approved_users +} else { + ns_log notice "dotlrn-ecommerce-init.tcl: Disallowing community access to approved member states, this simply restores dotlrn_member_rels_approved and membership_rels_up_tr" + dotlrn_ecommerce::disallow_access_to_approved_users +} \ No newline at end of file Index: openacs-4/packages/dotlrn-ecommerce/tcl/dotlrn-ecommerce-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-ecommerce/tcl/dotlrn-ecommerce-procs.tcl,v diff -u -r1.6 -r1.7 --- openacs-4/packages/dotlrn-ecommerce/tcl/dotlrn-ecommerce-procs.tcl 31 Aug 2005 02:11:30 -0000 1.6 +++ openacs-4/packages/dotlrn-ecommerce/tcl/dotlrn-ecommerce-procs.tcl 1 Sep 2005 20:58:53 -0000 1.7 @@ -168,3 +168,162 @@ regsub -all {\n} $html_comment "
\n" html_comment return $html_comment } + +ad_proc -public dotlrn_ecommerce::allow_access_to_approved_users { +} { + Allow approved users who haven't completed the registration to access the dotLRN community + + @author Roel Canicula (roelmc@pldtdsl.net) + @creation-date 2005-09-02 + + @return + + @error +} { + db_transaction { + db_dml allow_access_to_approved_users { + create or replace view dotlrn_member_rels_approved + as select * + from dotlrn_member_rels_full + where member_state in ('approved', 'waitinglist approved', 'request approved', 'payment received'); + + drop trigger membership_rels_up_tr on membership_rels; + drop function membership_rels_up_tr (); + + create function membership_rels_up_tr () returns opaque as ' + declare + map record; + begin + + if new.member_state = old.member_state then + return new; + end if; + + for map in select group_id, element_id, rel_type + from group_element_index + where rel_id = new.rel_id + loop + if new.member_state in (''approved'', ''waitinglist approved'', ''request approved'', ''payment received'') then + perform party_approved_member__add(map.group_id, map.element_id, new.rel_id, map.rel_type); + else + perform party_approved_member__remove(map.group_id, map.element_id, new.rel_id, map.rel_type); + end if; + end loop; + + return new; + + end;' language 'plpgsql'; + + create trigger membership_rels_up_tr before update on membership_rels + for each row execute procedure membership_rels_up_tr (); + } + + # Grant permission to current approved users + db_foreach current_users { + select rel_id, community_id, user_id + from dotlrn_member_rels_full + where member_state in ('waitinglist approved', 'request approved', 'payment received') + } { + db_exec_plsql approve_current_users { + declare + map record; + begin + for map in select group_id, element_id, rel_type + from group_element_index + where rel_id = :rel_id + loop + perform party_approved_member__add(map.group_id, map.element_id, :rel_id, map.rel_type); + end loop; + + return 0; + end; + } + + # Dispatch dotlrn applet callbacks + dotlrn_community::applets_dispatch \ + -community_id $community_id \ + -op AddUserToCommunity \ + -list_args [list $community_id $user_id] + } + } +} + +ad_proc -public dotlrn_ecommerce::disallow_access_to_approved_users { +} { + Don't allow approved users who haven't completed the registration to access the dotLRN community + This actually just returns to the default dotLRN state + + @author Roel Canicula (roelmc@pldtdsl.net) + @creation-date 2005-09-02 + + @return + + @error +} { + db_transaction { + db_dml allow_access_to_approved_users { + create or replace view dotlrn_member_rels_approved + as select * + from dotlrn_member_rels_full + where member_state = 'approved'; + + drop trigger membership_rels_up_tr on membership_rels; + drop function membership_rels_up_tr (); + + create or replace function membership_rels_up_tr () returns opaque as ' + declare + map record; + begin + + if new.member_state = old.member_state then + return new; + end if; + + for map in select group_id, element_id, rel_type + from group_element_index + where rel_id = new.rel_id + loop + if new.member_state = ''approved'' then + perform party_approved_member__add(map.group_id, map.element_id, new.rel_id, map.rel_type); + else + perform party_approved_member__remove(map.group_id, map.element_id, new.rel_id, map.rel_type); + end if; + end loop; + + return new; + + end;' language 'plpgsql'; + + create trigger membership_rels_up_tr before update on membership_rels + for each row execute procedure membership_rels_up_tr (); + } + + # Revoke permission to current approved users + db_foreach current_users { + select rel_id, community_id, user_id + from dotlrn_member_rels_full + where member_state in ('waitinglist approved', 'request approved', 'payment received') + } { + db_exec_plsql approve_current_users { + declare + map record; + begin + for map in select group_id, element_id, rel_type + from group_element_index + where rel_id = :rel_id + loop + perform party_approved_member__remove(map.group_id, map.element_id, :rel_id, map.rel_type); + end loop; + + return 0; + end; + } + + # Dispatch dotlrn applet callbacks + dotlrn_community::applets_dispatch \ + -community_id $community_id \ + -op RemoveUserFromCommunity \ + -list_args [list $community_id $user_id] + } + } +} \ No newline at end of file