diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e4f0e09a..35e4acb2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -196,4 +196,11 @@ module ApplicationHelper end return providers 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 diff --git a/app/models/ability.rb b/app/models/ability.rb index 9ba3c69a..a7fb93e6 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -99,8 +99,8 @@ class Ability can :manage, SponsorshipLevel, 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, Commercial # , commercialable_type: 'Conference', commercialable_id: conf_ids_for_organizer 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 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 @@ -114,6 +114,8 @@ class Ability conference.make_conference_public == true end + # see commercials too + can :show, Event do |event| event.state == 'confirmed' end diff --git a/app/models/user.rb b/app/models/user.rb index 08541de8..a5c80b30 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -48,10 +48,6 @@ class User < ActiveRecord::Base user end - def get_roles - roles - end - def setup_role self.is_admin = true if User.count == 0 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 # ====Returns # * +Hash+ * -> e.g. 'organizer' => "(conf1, conf2)" - def show_roles + def get_roles result = {} Role::ACTIONABLES.each do |role| resources = self.roles.where(name: role.parameterize.underscore).map{ |myrole| Conference.find(myrole.resource_id).short_title }.join ', ' diff --git a/app/views/admin/users/index.html.haml b/app/views/admin/users/index.html.haml index a6fa2c99..6c654b85 100644 --- a/app/views/admin/users/index.html.haml +++ b/app/views/admin/users/index.html.haml @@ -40,9 +40,9 @@ %td = user.registrations.where(attended: true).count %td - - unless user.show_roles.blank? - = user.show_roles.first(2).map { |x| x[0].titleize + ' ' + x[1] }.join ', ' - - if user.show_roles.count > 2 + - unless user.get_roles.blank? + = show_roles(user.get_roles.first(2)) + - if user.get_roles.count > 2 = '...' - if can? :show, user %td diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index 25cd9d80..ed4632d2 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -1,3 +1,6 @@ +- if can? :edit, @user + .pull-right + = link_to "Edit", edit_admin_user_path(@user), class: 'btn btn-primary' %table.table - @show_attributes.each do |attr| %tr @@ -6,6 +9,6 @@ = attr.capitalize.gsub('_', ' ') - if attr == 'roles' %td - = @user.show_roles.map { |x| x[0].titleize + ' ' + x[1] }.join ', ' + = show_roles(@user.get_roles) - else %td= @user.send(attr) diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index 2d716ebb..f0738891 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -27,7 +27,7 @@ = link_to(admin_conference_path(@conference.short_title)) do %span.fa.fa-tachometer Dashboard - - if can? :update, @conference + - if can? :show, @conference %li{:class=> "#{active_nav_li(edit_admin_conference_path(@conference.short_title))}"} = link_to(edit_admin_conference_path(@conference.short_title)) do %span.fa.fa-home @@ -38,16 +38,16 @@ = link_to(edit_admin_conference_contact_path(@conference.short_title)) do %span.fa.fa-envelope-o Contact - - if can? :index, @conference.commercials.build - %li{:class=> "#{active_nav_li(admin_conference_commercials_path(@conference.short_title))}"} - = link_to(admin_conference_commercials_path(@conference.short_title)) do - %span.fa.fa-film - Commercials - - if can? :update, @conference.photos.build - %li{:class=> "#{active_nav_li(admin_conference_photos_path(@conference.short_title))}"} - = link_to(admin_conference_photos_path(@conference.short_title)) do - %span.fa.fa-picture-o - Photos + - if can? :index, @conference.commercials.build + %li{:class=> "#{active_nav_li(admin_conference_commercials_path(@conference.short_title))}"} + = link_to(admin_conference_commercials_path(@conference.short_title)) do + %span.fa.fa-film + Commercials + - if can? :update, @conference.photos.build + %li{:class=> "#{active_nav_li(admin_conference_photos_path(@conference.short_title))}"} + = link_to(admin_conference_photos_path(@conference.short_title)) do + %span.fa.fa-picture-o + Photos - if can? :update, @conference.events.build %li{:class=> active_nav_li(admin_conference_events_path(@conference.short_title))} = link_to(admin_conference_events_path(@conference.short_title)) do diff --git a/config/routes.rb b/config/routes.rb index f82dad27..ad2b4c84 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,7 +14,7 @@ Osem::Application.routes.draw do post :add_user delete :remove_user end - resource :contact, except: [:index, :new, :create] + resource :contact, except: [:index, :new, :create, :show, :destroy] resources :photos, except: [:show] resource :schedule, only: [:show, :update] resources :commercials, except: [:show] @@ -98,10 +98,10 @@ Osem::Application.routes.draw do resource :schedule, only: [] do get "/" => "schedule#index" end - get "/register" => "conference_registration#register" - patch "/register" => "conference_registration#update" - delete "/register" => "conference_registration#unregister" member do + get "/register" => "conference_registration#register" + patch "/register" => "conference_registration#update" + delete "/register" => "conference_registration#unregister" get "gallery_photos" patch "subscription" => "conference#subscribe" delete "subscription" => "conference#unsubscribe" diff --git a/spec/features/ability_spec.rb b/spec/features/ability_spec.rb index e0d9eda8..ba32a52b 100644 --- a/spec/features/ability_spec.rb +++ b/spec/features/ability_spec.rb @@ -81,7 +81,7 @@ feature 'Has correct abilities' do sign_in user 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?('Registrations')).to be false 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?('Call for papers')).to be true 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) expect(current_path).to eq(root_path) @@ -143,7 +143,7 @@ feature 'Has correct abilities' do sign_in user 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?('Registrations')).to be true expect(page.has_content?('Events')).to be false @@ -205,8 +205,9 @@ feature 'Has correct abilities' do scenario 'when user is volunteer coordinator' do sign_in user 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?('Registrations')).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?('Call for papers')).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) expect(current_path).to eq(root_path)