add is_admin attribute to users

This commit is contained in:
Stella Rouzi 2014-07-18 14:43:49 +03:00
parent 07877f3256
commit 0418924d8e
7 changed files with 25 additions and 21 deletions

View file

@ -4,6 +4,7 @@ module Admin
def index def index
@users = User.all @users = User.all
@roles = Role.all.where(resource_type: nil)
end end
def show def show

View file

@ -48,8 +48,6 @@ class AdminAbility
cannot :manage, :schedule cannot :manage, :schedule
can :manage, :schedule can :manage, :schedule
# cannot :manage, Registration
# can :manage, Registration, conference: { id: conf_ids_for_organizer}
# Authorize explicitely, so that it doesn't look for a 'conference_id' # Authorize explicitely, so that it doesn't look for a 'conference_id'
can :manage, :volunteer can :manage, :volunteer
@ -64,9 +62,11 @@ class AdminAbility
# can :manage, Role, resource_id: conf_ids_for_organizer # can :manage, Role, resource_id: conf_ids_for_organizer
end end
if user.is_organizer? # A user can have 'organizer' role not associated to specific conference if user.is_admin # is_admin is an attribute of User
can :create, Conference can :create, Conference
# Can manage /admin/conference # any organizer of any conference and anyone who can create a conf can view the /admin/conference can :index, Conference # this will allow the Conference to appear in the menu
can :view, Conference # for /admin/conference overview
can :manage, User # to make other users admins
end end
## Authorization for CfP ## Authorization for CfP
@ -107,9 +107,5 @@ class AdminAbility
can :manage, Vday, conference_id: conf_ids_for_volunteer_coordinator can :manage, Vday, conference_id: conf_ids_for_volunteer_coordinator
can :manage, :volunteer can :manage, :volunteer
end end
# Allow access to event_attachments that belong to events (via event_id), which
# events belong to a conference (via conference_id) that has an organizer role for current user
# can :manage, EventAttachment, event_id: (Event.where(conference_id: conf_ids_for_organizer).pluck(:id))
end end
end end

View file

@ -53,7 +53,7 @@ class User < ActiveRecord::Base
end end
def setup_role def setup_role
roles << Role.where(name: 'organizer') if User.count == 0 is_admin = true if User.count == 0
roles << Role.where(name: 'participant') if roles.empty? roles << Role.where(name: 'participant') if roles.empty?
end end

View file

@ -0,0 +1,12 @@
- if current_user == user
You cannot modify your own role!
%br
%button{:class=> "btn btn-danger", "data-dismiss"=> "modal", "aria-hidden"=>"true"}
Cancel
- else
= "Give #{user.name} (#{user.email}) the following roles:"
= semantic_form_for(user, :url => admin_user_path(user), :method => :put) do |f|
= f.input :roles, :label => false, collection: @roles
%button{:class=> "btn btn-danger", "data-dismiss"=> "modal", "aria-hidden"=>"true"}
Cancel
= f.action :submit, :as => :button, :button_html => {:value => "Save", :class => "btn btn-primary"}

View file

@ -49,18 +49,7 @@
%h3{:id => "role-selector-header-#{user.id}"} %h3{:id => "role-selector-header-#{user.id}"}
Modifying Roles Modifying Roles
.modal-body .modal-body
- if current_user == user = render partial: 'roles', locals: { user: user }
You cannot modify your own role!
%br
%button{:class=> "btn btn-danger", "data-dismiss"=> "modal", "aria-hidden"=>"true"}
Cancel
- else
= "Give #{user.name} (#{user.email}) the following roles:"
= semantic_form_for(user, :url => admin_user_path(user), :method => :put) do |f|
= f.input :roles, :label => false
%button{:class=> "btn btn-danger", "data-dismiss"=> "modal", "aria-hidden"=>"true"}
Cancel
= f.action :submit, :as => :button, :button_html => {:value => "Save", :class => "btn btn-primary"}
- if can? :update, Role - if can? :update, Role
=link_to "#{user.roles.map { |role| role.name }.join ', '}", "#", "data-toggle" => "modal", "data-target" => "#user-role-selection-#{user.id}",id: "user-modify-role-#{user.id}" =link_to "#{user.roles.map { |role| role.name }.join ', '}", "#", "data-toggle" => "modal", "data-target" => "#user-role-selection-#{user.id}",id: "user-modify-role-#{user.id}"
- else - else

View file

@ -0,0 +1,5 @@
class AddIsAdminToUsers < ActiveRecord::Migration
def change
add_column :users, :is_admin, :boolean
end
end

View file

@ -474,6 +474,7 @@ ActiveRecord::Schema.define(version: 20140724113107) do
t.string "tshirt" t.string "tshirt"
t.string "languages" t.string "languages"
t.text "volunteer_experience" t.text "volunteer_experience"
t.boolean "is_admin"
end end
add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true add_index "users", ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true