Permalink
Browse files

Merge pull request #18 from alphagov/duplicate_users_for_panopticon_a…

…nd_publisher

Duplicate users for panopticon and publisher
  • Loading branch information...
2 parents a311a54 + 823840d commit ef3c90d31b17822b5fb9eb9553390b0bfeca8640 @john-griffin john-griffin committed Aug 20, 2012
Showing with 39 additions and 11 deletions.
  1. +39 −11 lib/tasks/migrate.rake
View
50 lib/tasks/migrate.rake
@@ -21,17 +21,45 @@ namespace :migrate do
end
end
- desc "Move Artefacts from the 'live' column to having a 'state' column"
- task :move_artefacts_to_state_column => :environment do
- Artefact.observers.disable :update_search_observer, :update_router_observer do
- Artefact.all.each do |artefact|
- if artefact[:live]
- artefact.state = "live"
- else
- artefact.state = "draft"
- end
- artefact.save!
- end
+
+
+
+ desc "Copy all users into app-specific user collections"
+ task :duplicate_users_for_panopticon_and_publisher => :environment do
+ require 'user'
+ # Not really required, but a guard against running with the newer User model
+ class User
+ self.collection_name = "users"
+ end
+
+ class PanopticonUser
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field "name", type: String
+ field "uid", type: String
+ field "version", type: Integer
+ field "email", type: String
+ field "permissions", type: Hash
+ field "remotely_signed_out", type: Boolean, default: false
+ end
+
+ class PublisherUser
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field "name", type: String
+ field "uid", type: String
+ field "version", type: Integer
+ field "email", type: String
+ field "permissions", type: Hash
+ field "remotely_signed_out", type: Boolean, default: false
+ end
+
+ User.all.each do |user|
+ to_keep = user.attributes.reject { |field_name, value| ["_id"].include?(field_name) }
+ PanopticonUser.timeless.create!(to_keep)
+ PublisherUser.timeless.create!(to_keep)
end
end

0 comments on commit ef3c90d

Please sign in to comment.