Index: openacs-4/packages/acs-authentication/tcl/sync-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-authentication/tcl/sync-procs.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/acs-authentication/tcl/sync-procs.tcl 9 Sep 2003 07:42:35 -0000 1.2 +++ openacs-4/packages/acs-authentication/tcl/sync-procs.tcl 9 Sep 2003 08:10:47 -0000 1.3 @@ -108,7 +108,7 @@ [ad_system_owner] \ [ad_system_owner] \ "Batch sync completed" \ - "Batch user synchronization is complete.\n\nRunning time: $run_time_seconds seconds\nNumber of actions: $num_actions\nNumber of problems: $num_problems\n\nTo view the log, please visit\n$view_log_url" + "Batch user synchronization is complete.\n\nRunning time: $job(run_time_seconds) seconds\nNumber of actions: $job(num_actions)\nNumber of problems: $job(num_problems)\n\nTo view the log, please visit\n$job(log_url)" } { # We don't fail hard here, just log an error global errorInfo @@ -337,11 +337,21 @@ } { Deletes the users that weren't included in the snapshot. } { - # run through users that belong to the given authority, - # but which don't already have an entry in the log - # and call auth::sync::job::action -operation "delete" on them + set usernames [db_list select_user_ids { + select username + from cc_users + where authority_id = :authority_id + and user_id not in (select user_id from auth_batch_job_entries where job_id = :job_id and authority_id = :authority_id) + and member_state != 'banned' + }] - # TODO + foreach username $usernames { + auth::sync::job::action \ + -job_id $job_id \ + -operation "delete" \ + -authority_id [auth::authority::local] \ + -username $username + } } Index: openacs-4/packages/acs-authentication/tcl/test/sync-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-authentication/tcl/test/sync-test-procs.tcl,v diff -u -N -r1.2 -r1.3 --- openacs-4/packages/acs-authentication/tcl/test/sync-test-procs.tcl 9 Sep 2003 07:42:36 -0000 1.2 +++ openacs-4/packages/acs-authentication/tcl/test/sync-test-procs.tcl 9 Sep 2003 08:10:47 -0000 1.3 @@ -7,7 +7,7 @@ } aa_register_case job_start_end { - Test starting and ending a batch job + Test batch job basics: Starting, getting document, adding entries, ending. } { aa_run_with_teardown \ -rollback \ @@ -70,17 +70,12 @@ } aa_register_case job_actions { - Test starting and ending a batch job + Test job actions: insert, update, } { aa_run_with_teardown \ -rollback \ -test_code { - - # TODO: Add checks that the user info actually look the way it's supposed to ... use the acs_user::get API to verify - - - # Start non-interactive job set job_id [auth::sync::job::start \ @@ -123,6 +118,7 @@ aa_log "entry.element_messages = '$entry(element_messages)'" if { [aa_true "Entry has user_id set" [exists_and_not_null entry(user_id)]] } { + array unset user acs_user::get -user_id $entry(user_id) -array user aa_equals "user.first_names" $user(first_names) $first_names1 @@ -201,6 +197,7 @@ aa_log "entry.element_messages = '$entry(element_messages)'" if { [aa_true "Entry has user_id set" [exists_and_not_null entry(user_id)]] } { + array unset user acs_user::get -user_id $entry(user_id) -array user aa_equals "user.first_names" $user(first_names) $first_names2 @@ -244,14 +241,47 @@ aa_true "first_names, last_name, email, url have problems" [util_sets_equal_p { first_names last_name email url } [array names elm_msgs]] } + ##### + # + # Valid delete action + # + ##### + + aa_log "--- Valid delete --- auth::sync::job::action -opration delete -username $username1" + set entry_id [auth::sync::job::action \ + -job_id $job_id \ + -operation "delete" \ + -authority_id [auth::authority::local] \ + -username $username1] + + array unset entry + auth::sync::job::get_entry \ + -entry_id $entry_id \ + -array entry + + aa_equals "entry.success_p" $entry(success_p) "t" + aa_log "entry.message = '$entry(message)'" + + if { [aa_true "Entry has user_id set" [exists_and_not_null entry(user_id)]] } { + array unset user + acs_user::get -user_id $entry(user_id) -array user + aa_equals "User member state is banned" $user(member_state) "banned" + } + + + ##### + # # End job + # + ##### + array set job [auth::sync::job::end -job_id $job_id] aa_true "Elapsed time less than 30 seconds" [expr $job(run_time_seconds) < 30] aa_false "Not interactive" [template::util::is_true $job(interactive_p)] - aa_equals "Number of actions" $job(num_actions) 4 + aa_equals "Number of actions" $job(num_actions) 5 aa_equals "Number of problems" $job(num_problems) 2 @@ -260,3 +290,150 @@ } } +aa_register_case job_snapshot { + Test a snapshot job +} { + aa_run_with_teardown \ + -rollback \ + -test_code { + + # Start non-interactive job + + set job_id [auth::sync::job::start \ + -authority_id [auth::authority::local]] + + aa_true "Returns a job_id" [exists_and_not_null job_id] + + ##### + # + # Valid insert action + # + ##### + + set username1 [ad_generate_random_string] + set email1 "[ad_generate_random_string]@foo.bar" + set first_names1 [ad_generate_random_string] + set last_name1 [ad_generate_random_string] + set url1 "http://[ad_generate_random_string].com" + aa_log "--- Valid insert --- auth::sync::job::action -opration insert -username $username1 -email $email1" + set entry_id [auth::sync::job::action \ + -job_id $job_id \ + -operation "snapshot" \ + -authority_id [auth::authority::local] \ + -username $username1 \ + -first_names $first_names1 \ + -last_name $last_name1 \ + -email $email1 \ + -url $url1] + + array unset entry + auth::sync::job::get_entry \ + -entry_id $entry_id \ + -array entry + + aa_equals "entry.success_p" $entry(success_p) "t" + aa_equals "entry.message" $entry(message) {} + aa_equals "entry.element_messages" $entry(element_messages) {} + aa_equals "entry.operation" $entry(operation) "insert" + aa_log "entry.user_id = '$entry(user_id)'" + aa_log "entry.message = '$entry(message)'" + aa_log "entry.element_messages = '$entry(element_messages)'" + + if { [aa_true "Entry has user_id set" [exists_and_not_null entry(user_id)]] } { + array unset user + acs_user::get -user_id $entry(user_id) -array user + + aa_equals "user.first_names" $user(first_names) $first_names1 + aa_equals "user.last_name" $user(last_name) $last_name1 + aa_equals "user.email" $user(email) [string tolower $email1] + aa_equals "user.authority_id" $user(authority_id) [auth::authority::local] + aa_equals "user.username" $user(username) $username1 + aa_equals "user.url" $user(url) $url1 + } + + ##### + # + # Valid update action + # + ##### + + set email2 "[ad_generate_random_string]@foo.bar" + set first_names2 [ad_generate_random_string] + set last_name2 [ad_generate_random_string] + set url2 "http://[ad_generate_random_string].com" + aa_log "--- Valid update --- auth::sync::job::action -opration update -username $username1" + set entry_id [auth::sync::job::action \ + -job_id $job_id \ + -operation "snapshot" \ + -authority_id [auth::authority::local] \ + -username $username1 \ + -first_names $first_names2 \ + -last_name $last_name2 \ + -email $email2 \ + -url $url2] + + array unset entry + auth::sync::job::get_entry \ + -entry_id $entry_id \ + -array entry + + aa_equals "entry.success_p" $entry(success_p) "t" + aa_equals "entry.message" $entry(message) {} + aa_equals "entry.element_messages" $entry(element_messages) {} + aa_equals "entry.operation" $entry(operation) "update" + aa_log "entry.user_id = '$entry(user_id)'" + aa_log "entry.message = '$entry(message)'" + aa_log "entry.element_messages = '$entry(element_messages)'" + + if { [aa_true "Entry has user_id set" [exists_and_not_null entry(user_id)]] } { + array unset user + acs_user::get -user_id $entry(user_id) -array user + + aa_equals "user.first_names" $user(first_names) $first_names2 + aa_equals "user.last_name" $user(last_name) $last_name2 + aa_equals "user.email" $user(email) [string tolower $email2] + aa_equals "user.authority_id" $user(authority_id) [auth::authority::local] + aa_equals "user.username" $user(username) $username1 + aa_equals "user.url" $user(url) $url2 + } + + + ##### + # + # Wrap up batch sync job + # + ##### + + # We need this number to check the counts below + set authority_id [auth::authority::local] + set num_users_not_banned [db_string select_num { + select count(*) + from cc_users + where authority_id = :authority_id + and member_state != 'banned' + }] + + auth::sync::job::snapshot_delete_remaining \ + -job_id $job_id \ + -authority_id [auth::authority::local] + + ##### + # + # End job + # + ##### + + array set job [auth::sync::job::end -job_id $job_id] + + aa_true "Elapsed time less than 30 seconds" [expr $job(run_time_seconds) < 30] + + aa_false "Not interactive" [template::util::is_true $job(interactive_p)] + + aa_equals "Number of actions" $job(num_actions) [expr $num_users_not_banned + 1] + + aa_equals "Number of problems" $job(num_problems) 0 + + aa_false "Log URL non-empty" [empty_string_p $job(log_url)] + + } +}