Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. # Find out when the user was deleted
  2.  
  3. User::Archive.find(user_id).deleted_at
  4.  
  5. # Using their archive_user_id (which shows up on the Deleted Users page next to the username, find their user_id
  6.  
  7. User::Archive.find(user_id).attributes['id']
  8.  
  9. # Find the customer id of the destroyed user, usually from the Deleted Users tab in BASS
  10. User::Archive.find_by_email('<domain_owner_email>').customer_id
  11.  
  12. customer_id = ###;
  13.  
  14. # Set up
  15. archived_customer = Customer::Archive.where(:id => customer_id).first;
  16. archived_user = User::Archive.where(:customer_id => archived_customer.id).first;
  17. archived_subscription = Subscription::Archive.where(:customer_id => customer_id).first;
  18. archived_account = Office365::Account::Archive.where(:customer_id => customer_id).first;
  19. archived_active_directory = Office365::ActiveDirectory::Archive.where(:account_id => archived_account.id).first;
  20. archived_members = Office365::Member::Archive.where(:customer_id => customer_id);
  21. archived_seats = Office365::Seat::Archive.where(:customer_id => customer_id);
  22. archived_services = Service::Archive.where(:customer_id => customer_id);
  23. archived_line_items = LineItem::Archive.where(:subscription_id => archived_subscription.id);
  24.  
  25. # Restore the Customer
  26. Customer.copy_from_archive("archived_customers.id" => archived_customer.attributes["id"])
  27.  
  28. # Restore the User
  29. User.copy_from_archive("archived_users.id" => archived_user.attributes["id"])
  30.  
  31. # Restore the Subscription
  32. Subscription.copy_from_archive("archived_subscriptions.id" => archived_subscription.attributes["id"])
  33.  
  34. # Restore the Account
  35. Office365::Account.copy_from_archive("archived_accounts.id" => archived_account.attributes["id"])
  36.  
  37. # Restore the Active Directory
  38. Office365::ActiveDirectory.copy_from_archive("archived_active_directories.id" => archived_active_directory.attributes["id"])
  39.  
  40. # Restore the Seats
  41. archived_seats.each do |aseat|
  42. id = aseat.attributes["id"]
  43. Office365::Seat.copy_from_archive("archived_seats.id" => id)
  44. puts "Successfully Restored #{id}:#{aseat.type} service for #{aseat.principal_name}."
  45. end;
  46.  
  47. # Restore the Members
  48. archived_members.each do |amem|
  49. id = amem.attributes["id"]
  50. Office365::Member.copy_from_archive("archived_members.id" => id)
  51. puts "Successfully Restored #{id}: #{amem.principal_name}."
  52. end;
  53.  
  54. # Restore the Services
  55. archived_services.each do |as|
  56. id = as.attributes["id"]
  57. Service::copy_from_archive("archived_services.id" => id)
  58. puts "Successfully Restored #{id}:#{as.type} service for #{as.account_name}."
  59. end;
  60.  
  61. # Restore the Line Items
  62. archived_line_items.each do |ali|
  63. id = ali.attributes["id"]
  64. LineItem.copy_from_archive("archived_line_items.id" => id)
  65. puts "Successfully Restored #{id}"
  66. end;
  67.  
  68. # Relink services to seats
  69. seats = Office365::Seat.where(:customer_id => customer_id);
  70. services = Service.where(:customer_id => customer_id);
  71.  
  72. seats.each do |seat|
  73. services_to_link = services.where(:account_name => seat.principal_name)
  74. services_to_link.each{|s| s.seat = seat; s.save!; puts s.account_name}
  75. end;
  76.  
  77. # Generate backup slots
  78. services.each { |s| BackupSlot.generate_schedule_for_service(s); puts "Generated for #{s.id}"};
  79.  
  80. # Recreate SSO entry
  81.  
  82. u.user_sso_id = nil
  83. u.insert_user_sso
  84. u.save!
  85.  
  86. # If the reinstated user already has an sso id:
  87.  
  88. u.user_sso_id = ""
  89. => ""
  90. u.insert_user_sso
  91. u.save!
  92. u.reload
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement