Skip to content

Commit

Permalink
Fixed membership add for first user/admin
Browse files Browse the repository at this point in the history
  • Loading branch information
augustf committed May 6, 2012
1 parent 57b8f7b commit b786d8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
13 changes: 10 additions & 3 deletions app/controllers/concerto_devise/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ def create
build_resource
#If there are no users, the first one created will be an admin
if User.all.empty?
#set the first user to be an admin and mark setup as being complete
first_user_setup = true
#set the first user to be an admin
resource.is_admin = true
ConcertoConfig.set("setup_complete", "true")
end
if resource.save
if resource.save
if first_user_setup == true
ConcertoConfig.set("setup_complete", "true")
#let's be idempotent here...
group = Group.find_or_create_by_name(:name => "Concerto Admins")
#create the membership only after we have the user
Membership.create(:user_id => resource.id, :group_id => group.id, :level => Membership::LEVELS[:leader])
end
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_in(resource_name, resource)
Expand Down
3 changes: 0 additions & 3 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
#Create an initial group
Group.find_or_create_by_name(:name => "Concerto Admins")

#Associate user with initial group
Membership.create(:user_id => 1, :group_id => 1, :level => 9)

#Put in default configuration parameters
ConcertoConfig.find_or_create_by_key(:key => "default_upload_type", :value => "graphic", :value_default => "graphic", :value_type => "string")
ConcertoConfig.find_or_create_by_key(:key => "public_concerto", :value => "true", :value_default => "true", :value_type => "boolean")
Expand Down

0 comments on commit b786d8d

Please sign in to comment.