Skip to content

Commit

Permalink
refs frab#124: fix add_example_users rake tasks and conference user v…
Browse files Browse the repository at this point in the history
…alidations
  • Loading branch information
manno committed Mar 20, 2014
1 parent 5ff9a60 commit a4ad807
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
6 changes: 2 additions & 4 deletions app/models/conference_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ class ConferenceUser < ActiveRecord::Base

belongs_to :conference
belongs_to :user
attr_accessible :role, :conference_id
attr_accessible :role, :conference_id, :user_id

validates :conference, presence: true
validates :user, presence: true
validates_presence_of :role
validates :conference, :user, :role, presence: true
validate :user_role_is_crew
validate :role_is_valid

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class ConvertToConferenceBasedRoles < ActiveRecord::Migration
def up
User.where(role: %w{orga coordinator reviewer}).each { |user|
puts "Changing #{user.email} from #{user.role} to 'crew'"
user.role = 'crew'
user.save
}
Expand Down
31 changes: 25 additions & 6 deletions lib/tasks/example_users.rake
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,21 @@ namespace :frab do
password = ENV['password'] || PASSWORD

PaperTrail.enabled = false
%w{admin orga coordinator reviewer submitter}.each do |role|
puts "create user #{mail_user}+#{role}@#{mail_domain} with password #{password}"
create_user role, get_mail(mail_user, role, mail_domain)
ActiveRecord::Base.transaction do
conference = Conference.first
if not conference.present?
puts "No conference crew created, since no conference exists"
# create full admin
email = get_mail(mail_user, 'admin', mail_domain)
create_user email, 'admin', password
else
puts "Creating crew for conference #{conference.acronym}"
%w{orga coordinator reviewer}.each do |crew_role|
email = get_mail(mail_user, "crew.#{crew_role}", mail_domain)
user_id = create_user email, 'crew', password
add_conference_rights(user_id, conference.id, crew_role)
end
end
end
end

Expand All @@ -34,21 +46,28 @@ namespace :frab do
"#{user}+#{role}@#{domain}"
end

def create_user(role, email)
def create_user(email, role, password)
puts "create user #{email} with password #{password}"

person = Person.create!(
email: email,
public_name: role,
)

user = User.new(
email: person.email,
password: PASSWORD,
password_confirmation: PASSWORD,
password: password,
password_confirmation: password,
)
user.person = person
user.role = role
user.confirmed_at = Time.now
user.save!
user.id
end

def add_conference_rights(user_id, conference_id, crew_role)
ConferenceUser.create! user_id: user_id, conference_id: conference_id, role: crew_role
end

end

0 comments on commit a4ad807

Please sign in to comment.