auth::sync::job::action (public)
auth::sync::job::action -job_id job_id -operation operation \ -username username [ -array array ]
Defined in packages/acs-authentication/tcl/sync-procs.tcl
Inserts/updates/deletes a user, depending on the operation.
- Switches:
- -job_id (required)
- The job which this is part of for logging purposes.
- -operation (required)
- 'insert', 'update', 'delete', or 'snapshot'.
- -username (required)
- The username which this action refers to.
- -array (optional)
- Name of an array containing the relevant registration elements. Not required if this is a delete operation.
- Returns:
- entry_id of newly created entry
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- sync_actions, sync_snapshot
Source code: if { $operation ne "delete" && $array eq "" } { error "Switch -array is required when operation is not delete" } upvar 1 $array user_info set entry_id {} set user_id {} set authority_id [get_authority_id -job_id $job_id] db_transaction { set user_id [acs_user::get_by_username -authority_id $authority_id -username $username] set success_p 1 array set result { message {} element_messages {} } switch $operation { snapshot { if { $user_id ne "" } { # user exists, it's an update set operation "update" } else { # user does not exist, it's an insert set operation "insert" } } update - delete { if { $user_id eq "" } { # Updating/deleting a user that doesn't exist set success_p 0 set result(message) "A user with username '$username' does not exist" } else { acs_user::get -user_id $user_id -array existing_user_info if {$existing_user_info(member_state) eq "banned"} { # Updating/deleting a user that's already deleted set success_p 0 set result(message) "The user with username '$username' has been deleted (banned)" } } } insert { if { $user_id ne "" } { acs_user::get -user_id $user_id -array existing_user_info if { $existing_user_info(member_state) ne "banned" } { # Inserting a user that already exists (and is not deleted) set success_p 0 set result(message) "A user with username '$username' already exists" } } } } # Only actually perform the action if we didn't already encounter a problem if { $success_p } { ad_try { switch $operation { "insert" { # We set email_verified_p to 't', because we trust the email we get from the remote system set user_info(email_verified_p) t array set result [auth::create_local_account -authority_id $authority_id -username $username -array user_info] if { $result(creation_status) ne "ok" } { set result(message) $result(creation_message) set success_p 0 } else { set user_id $result(user_id) set add_to_dotlrn_p [parameter::get_from_package_key -parameter SyncAddUsersToDotLrnP -package_key "acs-authentication" -default 0] if { $add_to_dotlrn_p } { # Add user to .LRN # Beware that this creates a portal and lots of other things for each user set type [parameter::get_from_package_key -parameter SyncDotLrnUserType -package_key "acs-authentication" -default "student"] set can_browse_p [parameter::get_from_package_key -parameter SyncDotLrnAccessLevel -package_key "acs-authentication" -default 1] set read_private_data_p [parameter::get_from_package_key -parameter SyncDotLrnReadPrivateDataP -package_key "acs-authentication" -default 1] dotlrn::user_add -id $user_info(email) -type $type -can_browse=$can_browse_p -user_id $user_id dotlrn_privacy::set_user_is_non_guest -user_id $user_id -value $read_private_data_p } } # We ignore account_status } "update" { # We set email_verified_p to 't', because we trust the email we get from the remote system set user_info(email_verified_p) t array set result [auth::update_local_account -authority_id $authority_id -username $username -array user_info] if { $result(update_status) ne "ok" } { set result(message) $result(update_message) set success_p 0 } else { set user_id $result(user_id) } } "delete" { array set result [auth::delete_local_account -authority_id $authority_id -username $username] if { $result(delete_status) ne "ok" } { set result(message) $result(delete_message) set success_p 0 } else { set user_id $result(user_id) } } } } on error {errorMsg} { # Get errorInfo and log it ad_log Error "Error during batch synchronization job: $errorMsg" set success_p 0 set result(message) $::errorInfo } } # Make a log entry set entry_id [auth::sync::job::create_entry -job_id $job_id -operation $operation -username $username -user_id $user_id -success=$success_p -message $result(message) -element_messages $result(element_messages)] } return $entry_idGeneric XQL file: packages/acs-authentication/tcl/sync-procs.xql
PostgreSQL XQL file: packages/acs-authentication/tcl/sync-procs-postgresql.xql
Oracle XQL file: packages/acs-authentication/tcl/sync-procs-oracle.xql