This commit is contained in:
Stella Rouzi 2014-08-13 14:37:15 +03:00
parent 1cbf78df3d
commit aeb28833f1
8 changed files with 39 additions and 30 deletions

View file

@ -196,4 +196,11 @@ module ApplicationHelper
end end
return providers return providers
end end
# Receives a hash, generated from User model, function get_roles
# Outputs the roles of a user, including the conferences for which the user has the roles
# Eg. organizer(oSC13, oSC14), cfp(oSC12, oSC13)
def show_roles(roles)
roles.map { |x| x[0].titleize + ' ' + x[1] }.join ', '
end
end end

View file

@ -99,8 +99,8 @@ class Ability
can :manage, SponsorshipLevel, conference_id: conf_ids_for_organizer can :manage, SponsorshipLevel, conference_id: conf_ids_for_organizer
can :manage, SupporterLevel, conference_id: conf_ids_for_organizer can :manage, SupporterLevel, conference_id: conf_ids_for_organizer
can :manage, Target, conference_id: conf_ids_for_organizer can :manage, Target, conference_id: conf_ids_for_organizer
can :manage, Commercial # , commercialable_type: 'Conference', commercialable_id: conf_ids_for_organizer
can :index, Commercial, commercialable_type: 'Conference' can :index, Commercial, commercialable_type: 'Conference'
can :manage, Commercial, commercialable_type: 'Conference', commercialable_id: conf_ids_for_organizer
# Manage commercials for events that belong to a conference of which user is organizer # Manage commercials for events that belong to a conference of which user is organizer
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(conference_id: conf_ids_for_organizer + conf_ids_for_cfp).pluck(:id) can :manage, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(conference_id: conf_ids_for_organizer + conf_ids_for_cfp).pluck(:id)
can :manage, Contact, conference_id: conf_ids_for_organizer can :manage, Contact, conference_id: conf_ids_for_organizer
@ -114,6 +114,8 @@ class Ability
conference.make_conference_public == true conference.make_conference_public == true
end end
# see commercials too
can :show, Event do |event| can :show, Event do |event|
event.state == 'confirmed' event.state == 'confirmed'
end end

View file

@ -48,10 +48,6 @@ class User < ActiveRecord::Base
user user
end end
def get_roles
roles
end
def setup_role def setup_role
self.is_admin = true if User.count == 0 self.is_admin = true if User.count == 0
end end
@ -59,7 +55,7 @@ class User < ActiveRecord::Base
# Gets the roles of the user, groups them by role.name and returns the resource(s) of each role # Gets the roles of the user, groups them by role.name and returns the resource(s) of each role
# ====Returns # ====Returns
# * +Hash+ * -> e.g. 'organizer' => "(conf1, conf2)" # * +Hash+ * -> e.g. 'organizer' => "(conf1, conf2)"
def show_roles def get_roles
result = {} result = {}
Role::ACTIONABLES.each do |role| Role::ACTIONABLES.each do |role|
resources = self.roles.where(name: role.parameterize.underscore).map{ |myrole| Conference.find(myrole.resource_id).short_title }.join ', ' resources = self.roles.where(name: role.parameterize.underscore).map{ |myrole| Conference.find(myrole.resource_id).short_title }.join ', '

View file

@ -40,9 +40,9 @@
%td %td
= user.registrations.where(attended: true).count = user.registrations.where(attended: true).count
%td %td
- unless user.show_roles.blank? - unless user.get_roles.blank?
= user.show_roles.first(2).map { |x| x[0].titleize + ' ' + x[1] }.join ', ' = show_roles(user.get_roles.first(2))
- if user.show_roles.count > 2 - if user.get_roles.count > 2
= '...' = '...'
- if can? :show, user - if can? :show, user
%td %td

View file

@ -1,3 +1,6 @@
- if can? :edit, @user
.pull-right
= link_to "Edit", edit_admin_user_path(@user), class: 'btn btn-primary'
%table.table %table.table
- @show_attributes.each do |attr| - @show_attributes.each do |attr|
%tr %tr
@ -6,6 +9,6 @@
= attr.capitalize.gsub('_', ' ') = attr.capitalize.gsub('_', ' ')
- if attr == 'roles' - if attr == 'roles'
%td %td
= @user.show_roles.map { |x| x[0].titleize + ' ' + x[1] }.join ', ' = show_roles(@user.get_roles)
- else - else
%td= @user.send(attr) %td= @user.send(attr)

View file

@ -27,7 +27,7 @@
= link_to(admin_conference_path(@conference.short_title)) do = link_to(admin_conference_path(@conference.short_title)) do
%span.fa.fa-tachometer %span.fa.fa-tachometer
Dashboard Dashboard
- if can? :update, @conference - if can? :show, @conference
%li{:class=> "#{active_nav_li(edit_admin_conference_path(@conference.short_title))}"} %li{:class=> "#{active_nav_li(edit_admin_conference_path(@conference.short_title))}"}
= link_to(edit_admin_conference_path(@conference.short_title)) do = link_to(edit_admin_conference_path(@conference.short_title)) do
%span.fa.fa-home %span.fa.fa-home
@ -38,16 +38,16 @@
= link_to(edit_admin_conference_contact_path(@conference.short_title)) do = link_to(edit_admin_conference_contact_path(@conference.short_title)) do
%span.fa.fa-envelope-o %span.fa.fa-envelope-o
Contact Contact
- if can? :index, @conference.commercials.build - if can? :index, @conference.commercials.build
%li{:class=> "#{active_nav_li(admin_conference_commercials_path(@conference.short_title))}"} %li{:class=> "#{active_nav_li(admin_conference_commercials_path(@conference.short_title))}"}
= link_to(admin_conference_commercials_path(@conference.short_title)) do = link_to(admin_conference_commercials_path(@conference.short_title)) do
%span.fa.fa-film %span.fa.fa-film
Commercials Commercials
- if can? :update, @conference.photos.build - if can? :update, @conference.photos.build
%li{:class=> "#{active_nav_li(admin_conference_photos_path(@conference.short_title))}"} %li{:class=> "#{active_nav_li(admin_conference_photos_path(@conference.short_title))}"}
= link_to(admin_conference_photos_path(@conference.short_title)) do = link_to(admin_conference_photos_path(@conference.short_title)) do
%span.fa.fa-picture-o %span.fa.fa-picture-o
Photos Photos
- if can? :update, @conference.events.build - if can? :update, @conference.events.build
%li{:class=> active_nav_li(admin_conference_events_path(@conference.short_title))} %li{:class=> active_nav_li(admin_conference_events_path(@conference.short_title))}
= link_to(admin_conference_events_path(@conference.short_title)) do = link_to(admin_conference_events_path(@conference.short_title)) do

View file

@ -14,7 +14,7 @@ Osem::Application.routes.draw do
post :add_user post :add_user
delete :remove_user delete :remove_user
end end
resource :contact, except: [:index, :new, :create] resource :contact, except: [:index, :new, :create, :show, :destroy]
resources :photos, except: [:show] resources :photos, except: [:show]
resource :schedule, only: [:show, :update] resource :schedule, only: [:show, :update]
resources :commercials, except: [:show] resources :commercials, except: [:show]
@ -98,10 +98,10 @@ Osem::Application.routes.draw do
resource :schedule, only: [] do resource :schedule, only: [] do
get "/" => "schedule#index" get "/" => "schedule#index"
end end
get "/register" => "conference_registration#register"
patch "/register" => "conference_registration#update"
delete "/register" => "conference_registration#unregister"
member do member do
get "/register" => "conference_registration#register"
patch "/register" => "conference_registration#update"
delete "/register" => "conference_registration#unregister"
get "gallery_photos" get "gallery_photos"
patch "subscription" => "conference#subscribe" patch "subscription" => "conference#subscribe"
delete "subscription" => "conference#unsubscribe" delete "subscription" => "conference#unsubscribe"

View file

@ -81,7 +81,7 @@ feature 'Has correct abilities' do
sign_in user sign_in user
visit admin_conference_path(conference2.short_title) visit admin_conference_path(conference2.short_title)
expect(page.has_content?('Basics')).to be false expect(page.has_content?('Basics')).to be true
expect(page.has_content?('Dashboard')).to be true expect(page.has_content?('Dashboard')).to be true
# expect(page.has_content?('Registrations')).to be false # expect(page.has_content?('Registrations')).to be false
expect(page.has_content?('Events')).to be true expect(page.has_content?('Events')).to be true
@ -94,7 +94,7 @@ feature 'Has correct abilities' do
expect(page.has_content?('E-Mails')).to be true expect(page.has_content?('E-Mails')).to be true
expect(page.has_content?('Call for papers')).to be true expect(page.has_content?('Call for papers')).to be true
expect(page.has_content?('Questions')).to be false expect(page.has_content?('Questions')).to be false
# expect(page.has_content?('Commercials')).to be true expect(page.has_content?('Commercials')).to be true
visit edit_admin_conference_path(conference2.short_title) visit edit_admin_conference_path(conference2.short_title)
expect(current_path).to eq(root_path) expect(current_path).to eq(root_path)
@ -143,7 +143,7 @@ feature 'Has correct abilities' do
sign_in user sign_in user
visit admin_conference_path(conference3.short_title) visit admin_conference_path(conference3.short_title)
expect(page.has_content?('Basics')).to be false expect(page.has_content?('Basics')).to be true
expect(page.has_content?('Dashboard')).to be true expect(page.has_content?('Dashboard')).to be true
expect(page.has_content?('Registrations')).to be true expect(page.has_content?('Registrations')).to be true
expect(page.has_content?('Events')).to be false expect(page.has_content?('Events')).to be false
@ -205,8 +205,9 @@ feature 'Has correct abilities' do
scenario 'when user is volunteer coordinator' do scenario 'when user is volunteer coordinator' do
sign_in user sign_in user
visit admin_conference_path(conference4.short_title) visit admin_conference_path(conference4.short_title)
save_and_open_page
expect(page.has_content?('Basics')).to be false expect(page.has_content?('Basics')).to be true
expect(page.has_content?('Dashboard')).to be true expect(page.has_content?('Dashboard')).to be true
# expect(page.has_content?('Registrations')).to be false # expect(page.has_content?('Registrations')).to be false
expect(page.has_content?('Events')).to be false expect(page.has_content?('Events')).to be false
@ -219,7 +220,7 @@ feature 'Has correct abilities' do
expect(page.has_content?('E-Mails')).to be false expect(page.has_content?('E-Mails')).to be false
expect(page.has_content?('Call for papers')).to be false expect(page.has_content?('Call for papers')).to be false
expect(page.has_content?('Questions')).to be false expect(page.has_content?('Questions')).to be false
# expect(page.has_content?('Commercials')).to be true expect(page.has_content?('Commercials')).to be true
visit edit_admin_conference_path(conference4.short_title) visit edit_admin_conference_path(conference4.short_title)
expect(current_path).to eq(root_path) expect(current_path).to eq(root_path)