From 1c9891215d27a9d4764c7fae7e3bd7fca96df71b Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Thu, 20 Jul 2017 18:14:38 +0530 Subject: [PATCH 1/9] Authorize ticket purchase --- app/controllers/ticket_purchases_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/ticket_purchases_controller.rb b/app/controllers/ticket_purchases_controller.rb index 792122e2..f15fc993 100644 --- a/app/controllers/ticket_purchases_controller.rb +++ b/app/controllers/ticket_purchases_controller.rb @@ -2,6 +2,7 @@ class TicketPurchasesController < ApplicationController before_filter :authenticate_user! load_resource :conference, find_by: :short_title authorize_resource :conference_registrations, class: Registration + authorize_resource def create current_user.ticket_purchases.by_conference(@conference).unpaid.destroy_all From 34456fa205da4dce4eee16944c716fa7733e0911 Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Fri, 21 Jul 2017 04:13:23 +0530 Subject: [PATCH 2/9] Remove float point number on y axis --- app/assets/javascripts/osem-dashboard.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/osem-dashboard.js b/app/assets/javascripts/osem-dashboard.js index c8d5b853..83d2b468 100644 --- a/app/assets/javascripts/osem-dashboard.js +++ b/app/assets/javascripts/osem-dashboard.js @@ -55,7 +55,6 @@ $(function() { } function draw_line_chart(animation, $canvas){ - var options = get_animation({}, animation); var chart_data = create_dataset($canvas); var weeks = $canvas.parent().data('weeks'); var data = { @@ -63,10 +62,27 @@ $(function() { datasets : chart_data } + var options = get_animation(wholeNumberAxisFix(data), animation); var ctx = $canvas.get(0).getContext("2d"); new Chart(ctx).Line(data, options); } + function wholeNumberAxisFix(data){ + var maxValue = false; + for(datasetIndex = 0; datasetIndex < data.datasets.length; ++datasetIndex){ + var setMax = Math.max.apply(null, data.datasets[datasetIndex].data); + if (maxValue === false || setMax > maxValue) maxValue = setMax; + } + + var steps = maxValue; + var stepWidth = 1; + if (maxValue > 10) { + stepWidth = Math.floor(maxValue / 10); + steps = Math.ceil(maxValue / stepWidth); + } + return { scaleOverride: true, scaleSteps: steps, scaleStepWidth: stepWidth, scaleStartValue: 0 }; + } + function create_dataset($canvas){ var selected = getSelectedConferences($canvas); var chart_data = $canvas.parent().data('chart'); From d0a961099261fbb6ed0569957caf5e87eddcdb66 Mon Sep 17 00:00:00 2001 From: nikhilgupta1211 Date: Sun, 20 Aug 2017 16:27:35 +0530 Subject: [PATCH 3/9] Made Sidebar collapsible for small screens Added a hamburger button in _admin_html.haml for navbar collapse Fixes #853 --- app/assets/stylesheets/osem.css.scss | 6 ++++++ app/views/layouts/_admin_sidebar.html.haml | 2 +- app/views/layouts/_navigation.html.haml | 10 ++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/osem.css.scss b/app/assets/stylesheets/osem.css.scss index 5a331436..775418b3 100644 --- a/app/assets/stylesheets/osem.css.scss +++ b/app/assets/stylesheets/osem.css.scss @@ -94,3 +94,9 @@ p.comment-body { .box{ height: 230px; } + +/* sidebar hamburger btn */ +.side-nav-btn{ + margin-left: 10px; + float: left; +} diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index 1c7bac9a..28ef62e2 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -1,4 +1,4 @@ -%ul.nav.nav-stacked.nav-pills.mySidebar +%ul.nav.nav-stacked.nav-pills.mySidebar.collapse.navbar-collapse#side-nav .btn-group %button{type:'button', class: 'btn btn-default btn-link dropdown-toggle', 'data-toggle'=>'dropdown'} %span.fa.fa-cog diff --git a/app/views/layouts/_navigation.html.haml b/app/views/layouts/_navigation.html.haml index 9750be92..9995123b 100644 --- a/app/views/layouts/_navigation.html.haml +++ b/app/views/layouts/_navigation.html.haml @@ -1,7 +1,13 @@ .navbar.navbar-default.navbar-fixed-top.nav-osem{role: 'navigation'} .container .navbar-header - %button{"data-target"=>".navbar-collapse", "data-toggle"=>"collapse", class: 'navbar-toggle', type: 'button'} + - if @conference && @conference.short_title.present? + %button{ "data-target"=>"#side-nav", "data-toggle"=>"collapse", class: 'navbar-toggle side-nav-btn', type: 'button' } + %span.sr-only Toggle navigation + %span.icon-bar + %span.icon-bar + %span.icon-bar + %button{"data-target"=>"#main-nav", "data-toggle"=>"collapse", class: 'navbar-toggle', type: 'button'} %span.sr-only Toggle navigation %span.icon-bar @@ -11,7 +17,7 @@ = link_to (ENV['OSEM_NAME'] || 'OSEM'), root_path, class: 'navbar-brand', title: 'Open Source Event Manager' - else = link_to conference.organization.name, organizations_path, class: 'navbar-brand', title: 'Open Source Event Manager' - .collapse.navbar-collapse + .collapse.navbar-collapse#main-nav - if content_for :splash_nav %ul.nav.navbar-nav#splash-nav = content_for :splash_nav From 4b735cff69f9ac8f316d25d095c079d971024eb1 Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Thu, 27 Jul 2017 17:25:17 +0530 Subject: [PATCH 4/9] Added qr code Added qr code on ticket pdf and ticket show page. --- app/assets/stylesheets/osem.css.scss | 4 ++++ app/controllers/physical_ticket_controller.rb | 1 + app/pdfs/ticket_pdf.rb | 6 +++++- app/views/physical_ticket/show.html.haml | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/osem.css.scss b/app/assets/stylesheets/osem.css.scss index 775418b3..79768c5d 100644 --- a/app/assets/stylesheets/osem.css.scss +++ b/app/assets/stylesheets/osem.css.scss @@ -99,4 +99,8 @@ p.comment-body { .side-nav-btn{ margin-left: 10px; float: left; + } + +.qr-image{ + margin-left: 120px; } diff --git a/app/controllers/physical_ticket_controller.rb b/app/controllers/physical_ticket_controller.rb index fb25ae63..af02155c 100644 --- a/app/controllers/physical_ticket_controller.rb +++ b/app/controllers/physical_ticket_controller.rb @@ -13,6 +13,7 @@ class PhysicalTicketController < ApplicationController @file_name = "ticket_for_#{@conference.short_title}" @user = @physical_ticket.user @ticket_layout = @conference.ticket_layout.to_sym + @qrcode_image = RQRCode::QRCode.new(@physical_ticket.token).as_png(size: 180, border_modules: 0) respond_to do |format| format.html format.pdf do diff --git a/app/pdfs/ticket_pdf.rb b/app/pdfs/ticket_pdf.rb index 1c26ec77..ecb4cd2c 100644 --- a/app/pdfs/ticket_pdf.rb +++ b/app/pdfs/ticket_pdf.rb @@ -77,5 +77,9 @@ class TicketPdf < Prawn::Document move_up 180 end - def draw_fourth_square; end + def draw_fourth_square + x = @mid_horizontal + (@right - @mid_horizontal - 180) / 2 + y = cursor - (bounds.top - @mid_vertical - 180) / 2 + print_qr_code(@physical_ticket.token, pos: [x, y], extent: 180, stroke: false) + end end diff --git a/app/views/physical_ticket/show.html.haml b/app/views/physical_ticket/show.html.haml index 067f0a9b..40513ae8 100644 --- a/app/views/physical_ticket/show.html.haml +++ b/app/views/physical_ticket/show.html.haml @@ -67,6 +67,7 @@ = @physical_ticket.ticket_purchase.id %br .col-md-5.col-md-offset-2.box.well + = image_tag(@qrcode_image.to_data_url, class: 'img-responsive qr-image') .row .col-md-12 %p.text-left From 157c270497356ad17e8c18a0946025aba9d5c108 Mon Sep 17 00:00:00 2001 From: siddhantbajaj Date: Sat, 12 Aug 2017 01:27:16 +0530 Subject: [PATCH 5/9] Registration tickets to be set for registration period Admin must create at least one registration ticket before creating registration period. --- app/models/admin_ability.rb | 5 ++++- app/models/conference.rb | 6 +++++- app/views/admin/registration_periods/show.html.haml | 11 +++++++++-- .../admin/registration_periods_controller_spec.rb | 2 +- spec/factories/tickets.rb | 3 +++ spec/features/organization_admin_ability_spec.rb | 1 + spec/features/organizer_ability_spec.rb | 1 + spec/features/registration_periods_spec.rb | 1 + spec/models/admin_ability_spec.rb | 1 + spec/models/registration_period_spec.rb | 1 + 10 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/models/admin_ability.rb b/app/models/admin_ability.rb index f742b775..39183543 100644 --- a/app/models/admin_ability.rb +++ b/app/models/admin_ability.rb @@ -123,7 +123,10 @@ class AdminAbility can :manage, Commercial, commercialable_type: 'Conference', commercialable_id: conf_ids can :manage, Registration, conference_id: conf_ids - can :manage, RegistrationPeriod, conference_id: conf_ids + can :manage, RegistrationPeriod do |registration_period| + conference = registration_period.conference + conf_ids.include?(conference.id) && conference.tickets.for_registration.any? + end can :manage, Booth, conference_id: conf_ids can :manage, Question, conference_id: conf_ids can :manage, Question do |question| diff --git a/app/models/conference.rb b/app/models/conference.rb index 729db645..919bf7e5 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -26,7 +26,11 @@ class Conference < ActiveRecord::Base has_many :ticket_purchases, dependent: :destroy has_many :payments, dependent: :destroy has_many :supporters, through: :ticket_purchases, source: :user - has_many :tickets, dependent: :destroy + has_many :tickets, dependent: :destroy do + def for_registration + where(registration_ticket: true) + end + end has_many :resources, dependent: :destroy has_many :booths, dependent: :destroy diff --git a/app/views/admin/registration_periods/show.html.haml b/app/views/admin/registration_periods/show.html.haml index 057a7a37..e923d089 100644 --- a/app/views/admin/registration_periods/show.html.haml +++ b/app/views/admin/registration_periods/show.html.haml @@ -25,5 +25,12 @@ = link_to 'Delete', admin_conference_registration_period_path, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' - else - - if can? :create, @conference.build_registration_period - = link_to 'New Registration Period', new_admin_conference_registration_period_path, class: 'btn btn-primary' + - unless @conference.tickets.for_registration.empty? + - if can? :create, @conference.build_registration_period + = link_to 'New Registration Period', new_admin_conference_registration_period_path, class: 'btn btn-primary' + - else + .h3.text-left + No Registration Tickets! + %small + = link_to 'Create registration tickets', new_admin_conference_ticket_path + before creating the registration period. diff --git a/spec/controllers/admin/registration_periods_controller_spec.rb b/spec/controllers/admin/registration_periods_controller_spec.rb index 6177fde7..fd98ce77 100644 --- a/spec/controllers/admin/registration_periods_controller_spec.rb +++ b/spec/controllers/admin/registration_periods_controller_spec.rb @@ -5,7 +5,7 @@ describe Admin::RegistrationPeriodsController do # It is necessary to use bang version of let to build roles before user let(:conference) { create(:conference) } let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) } - + let!(:registration_ticket) { create(:registration_ticket, conference: conference) } let(:organizer) { create(:user, role_ids: organizer_role.id) } let(:organizer2) { create(:user, email: 'organizer2@email.osem', role_ids: organizer_role.id) } let(:participant) { create(:user) } diff --git a/spec/factories/tickets.rb b/spec/factories/tickets.rb index 88532b86..c4bb1539 100644 --- a/spec/factories/tickets.rb +++ b/spec/factories/tickets.rb @@ -3,5 +3,8 @@ FactoryGirl.define do title { "#{Faker::Hipster.word} Ticket" } price_cents 1000 price_currency 'USD' + factory :registration_ticket do + registration_ticket true + end end end diff --git a/spec/features/organization_admin_ability_spec.rb b/spec/features/organization_admin_ability_spec.rb index 8bccd2cf..d84a7c01 100644 --- a/spec/features/organization_admin_ability_spec.rb +++ b/spec/features/organization_admin_ability_spec.rb @@ -5,6 +5,7 @@ feature 'Has correct abilities' do let(:conference) { create(:full_conference, organization: organization) } let(:role_organization_admin) { Role.find_by(name: 'organization_admin', resource: organization) } let(:user_organization_admin) { create(:user, role_ids: [role_organization_admin.id]) } + let!(:registration_ticket) { create(:registration_ticket, conference: conference) } context 'when user is organization_admin' do before do diff --git a/spec/features/organizer_ability_spec.rb b/spec/features/organizer_ability_spec.rb index 5345b58c..0127ea2f 100644 --- a/spec/features/organizer_ability_spec.rb +++ b/spec/features/organizer_ability_spec.rb @@ -8,6 +8,7 @@ feature 'Has correct abilities' do let(:role_organizer_conf) { Role.find_by(name: 'organizer', resource: conference) } let(:role_organizer_other_conf) { Role.find_by(name: 'organizer', resource: other_conference) } let(:user_organizer) { create(:user, role_ids: [role_organizer_conf.id, role_organizer_other_conf.id]) } + let!(:registration_ticket) { create(:registration_ticket, conference: conference) } context 'when user is organizer' do before do diff --git a/spec/features/registration_periods_spec.rb b/spec/features/registration_periods_spec.rb index c6cc992e..5c1c90b5 100644 --- a/spec/features/registration_periods_spec.rb +++ b/spec/features/registration_periods_spec.rb @@ -6,6 +6,7 @@ feature RegistrationPeriod do let!(:conference) { create(:conference) } let!(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) } let!(:organizer) { create(:user, email: 'admin@example.com', role_ids: [organizer_role.id]) } + let!(:registration_ticket) { create(:registration_ticket, conference: conference) } shared_examples 'successfully' do scenario 'create and update registration period', js: true do diff --git a/spec/models/admin_ability_spec.rb b/spec/models/admin_ability_spec.rb index 126d32de..805dd621 100644 --- a/spec/models/admin_ability_spec.rb +++ b/spec/models/admin_ability_spec.rb @@ -11,6 +11,7 @@ describe 'User with admin role' do let!(:organization) { create(:organization) } let!(:my_conference) { create(:full_conference, organization: organization) } + let!(:registration_ticket) { create(:registration_ticket, conference: my_conference) } let(:my_venue) { my_conference.venue || create(:venue, conference: my_conference) } let(:my_registration) { create(:registration, conference: my_conference, user: admin) } diff --git a/spec/models/registration_period_spec.rb b/spec/models/registration_period_spec.rb index ef28bab1..52fb3755 100644 --- a/spec/models/registration_period_spec.rb +++ b/spec/models/registration_period_spec.rb @@ -2,6 +2,7 @@ require 'spec_helper' describe RegistrationPeriod do let!(:conference) { create(:conference, start_date: Date.today, end_date: Date.today + 6) } + let!(:registration_ticket) { create(:registration_ticket, conference: conference) } let!(:registration_period) { create(:registration_period, start_date: Date.today - 2, end_date: Date.today - 1, conference: conference) } describe 'validations' do From db8fdb3d387ad70671f6b262f5f1d301990dfce7 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 22 Aug 2017 17:24:50 +0530 Subject: [PATCH 6/9] add permissions and actions to assign and unassign organization admin role --- .../admin/organizations_controller.rb | 42 +++++++++++++++++++ app/models/admin_ability.rb | 8 ++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/organizations_controller.rb b/app/controllers/admin/organizations_controller.rb index 087bf7f8..d125c5cf 100644 --- a/app/controllers/admin/organizations_controller.rb +++ b/app/controllers/admin/organizations_controller.rb @@ -1,6 +1,7 @@ module Admin class OrganizationsController < Admin::BaseController load_and_authorize_resource :organization + before_action :verify_user, only: [:assign_org_admins, :unassign_org_admins] def index @organizations = Organization.all @@ -43,8 +44,49 @@ module Admin end end + def assign_org_admins + if @user.has_role? 'organization_admin', @organization + flash[:error] = "User #{@user.email} already has the role organization admin" + elsif @user.add_role 'organization_admin', @organization + flash[:notice] = "Successfully added role organization admin to user #{@user.email}" + else + flash[:error] = "Coud not add role organization admin to #{@user.email}" + end + + redirect_to admins_admin_organization_path(@organization) + end + + def unassign_org_admins + if @user.remove_role 'organization_admin', @organization + flash[:notice] = "Successfully removed role organization admin from user #{@user.email}" + else + flash[:error] = "Could not remove role organization admin from user #{@user.email}" + end + + redirect_to admins_admin_organization_path(@organization) + end + + def admins + @role = @organization.roles.first + @users = @role.users + render 'show_org_admins' + end + private + def user_params + params.require(:user).permit(:email) + end + + def verify_user + @user = User.find_by(email: user_params[:email]) + unless @user + redirect_to admins_admin_organization_path(@organization), + error: 'Could not find user. Please provide a valid email!' + return + end + end + def organization_params params.require(:organization).permit(:name, :description, :picture) end diff --git a/app/models/admin_ability.rb b/app/models/admin_ability.rb index 39183543..cfe17d1d 100644 --- a/app/models/admin_ability.rb +++ b/app/models/admin_ability.rb @@ -28,7 +28,7 @@ class AdminAbility conference.registration_open? && !conference.registration_limit_exceeded? || conference.program.speakers.confirmed.include?(user) end - can :index, Organization + can [:index, :admins], Organization can :index, Ticket can :manage, TicketPurchase, user_id: user.id can [:new, :create], Payment, user_id: user.id @@ -96,13 +96,11 @@ class AdminAbility org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id) conf_ids_for_organization_admin = Conference.where(organization_id: org_ids_for_organization_admin).pluck(:id) - can [:read, :update, :destroy], Organization, id: org_ids_for_organization_admin + can [:read, :update, :destroy, :assign_org_admins, :unassign_org_admins, :admins], Organization, id: org_ids_for_organization_admin can :new, Conference can :manage, Conference, organization_id: org_ids_for_organization_admin can [:index, :show], Role - can [:edit, :update], Role do |role| - role.resource_type == 'Organization' && (org_ids_for_organization_admin.include? role.resource_id) - end + signed_in_with_organizer_role(user, conf_ids_for_organization_admin) end From a91c67be0afa368e5ed0d5a262603ca84cbb7b30 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 22 Aug 2017 17:25:34 +0530 Subject: [PATCH 7/9] add views for organization admin role --- .haml-lint_todo.yml | 1 + .../_users_with_org_admin_role.haml | 25 +++++++++++++++++++ app/views/admin/organizations/index.html.haml | 2 ++ .../admin/organizations/show_org_admins.haml | 24 ++++++++++++++++++ config/routes.rb | 8 +++++- 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/organizations/_users_with_org_admin_role.haml create mode 100644 app/views/admin/organizations/show_org_admins.haml diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index 2e4c2995..25ccb622 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -78,6 +78,7 @@ linters: - "app/views/admin/resources/show.html.haml" - "app/views/admin/roles/_form.html.haml" - "app/views/admin/roles/_users.html.haml" + - "app/views/admin/roles/_users_with_org_admin_role.haml" - "app/views/admin/roles/index.html.haml" - "app/views/admin/roles/show.html.haml" - "app/views/admin/rooms/_form.html.haml" diff --git a/app/views/admin/organizations/_users_with_org_admin_role.haml b/app/views/admin/organizations/_users_with_org_admin_role.haml new file mode 100644 index 00000000..e107868c --- /dev/null +++ b/app/views/admin/organizations/_users_with_org_admin_role.haml @@ -0,0 +1,25 @@ +.page-header + %h3 Users (#{users.length}) +- if users.present? + %table.table.table-striped.table-bordered.table-hover.datatable#users + %thead + %th Name + %th Email + - if ( can? :unassign_org_admins, organization ) + %th + Actions + %tbody + - users.each do |user| + %tr + %td= user.name + %td= user.email + - if ( can? :unassign_org_admins, organization ) + %td + = link_to 'Remove from organization admin', + unassign_org_admins_admin_organization_path(organization.id, + role.name, + user: {email: user.email}), + method: :delete, + class: 'btn btn-danger' +- else + %h5 No users found! diff --git a/app/views/admin/organizations/index.html.haml b/app/views/admin/organizations/index.html.haml index aa682c57..baf9bc80 100644 --- a/app/views/admin/organizations/index.html.haml +++ b/app/views/admin/organizations/index.html.haml @@ -25,6 +25,8 @@ = organization.conferences.past.count %td .btn-group + = link_to 'Admins', admins_admin_organization_path(organization), + method: :get, class: 'btn btn-success' = link_to 'Edit', edit_admin_organization_path(organization), method: :get, class: 'btn btn-primary' = link_to 'Delete', admin_organization_path(organization), diff --git a/app/views/admin/organizations/show_org_admins.haml b/app/views/admin/organizations/show_org_admins.haml new file mode 100644 index 00000000..7fe1f943 --- /dev/null +++ b/app/views/admin/organizations/show_org_admins.haml @@ -0,0 +1,24 @@ +.row + .col-md-12 + .page-header + %h2 + Organization admins for #{@organization.name} + .text-muted + = @role.description + +.row.col-md-3 + - if ( can? :assign_org_admins, @organization ) + = semantic_form_for :user, + url: assign_org_admins_admin_organization_path(@organization, + @role.name), method: :post do |u| + + = u.label 'Add user by email: ' + .input-group + = u.input :email, label: false, placeholder: "User's email" + .input-group-btn + = u.submit 'Add', id: 'user-add', class: 'btn btn-primary' + +.row + .col-md-12 + = render partial: 'users_with_org_admin_role', + locals: { users: @users, organization: @organization, role: @role } diff --git a/config/routes.rb b/config/routes.rb index 523a076d..3b955953 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -20,7 +20,13 @@ Osem::Application.routes.draw do end namespace :admin do - resources :organizations + resources :organizations do + member do + get :admins + post :assign_org_admins + delete :unassign_org_admins + end + end resources :users do member do patch :toggle_confirmation From c596a9fda7a541f769d12d402eeb7f88201e8b38 Mon Sep 17 00:00:00 2001 From: shlok007 Date: Tue, 22 Aug 2017 17:26:11 +0530 Subject: [PATCH 8/9] add tests to assign and unassign organization admin role --- .../admin/organizations_controller_spec.rb | 27 +++++++++++ .../admin/roles_controller_spec.rb | 1 - spec/features/roles_spec.rb | 45 +++++++++++++++++++ spec/models/admin_ability_spec.rb | 18 +++++++- 4 files changed, 89 insertions(+), 2 deletions(-) diff --git a/spec/controllers/admin/organizations_controller_spec.rb b/spec/controllers/admin/organizations_controller_spec.rb index abe5005b..801cce83 100644 --- a/spec/controllers/admin/organizations_controller_spec.rb +++ b/spec/controllers/admin/organizations_controller_spec.rb @@ -167,5 +167,32 @@ describe Admin::OrganizationsController do end end end + + describe 'POST #assign_org_admins' do + let(:org_admin_role) { Role.find_by(name: 'organization_admin', resource: organization) } + + before do + post :assign_org_admins, id: organization.id, + user: { email: user.email } + end + + it 'assigns organization_admin role' do + expect(user.roles).to eq [org_admin_role] + end + end + + describe 'DELETE #unassign_org_admins' do + let(:org_admin_role) { Role.find_by(name: 'organization_admin', resource: organization) } + let!(:org_admin_user) { create(:user, role_ids: [org_admin_role.id]) } + + before do + delete :unassign_org_admins, id: organization.id, + user: { email: org_admin_user.email } + end + + it 'unassigns organization_admin role' do + expect(org_admin_user.reload.roles).to eq [] + end + end end end diff --git a/spec/controllers/admin/roles_controller_spec.rb b/spec/controllers/admin/roles_controller_spec.rb index d5cdc67e..dcc81313 100644 --- a/spec/controllers/admin/roles_controller_spec.rb +++ b/spec/controllers/admin/roles_controller_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe Admin::RolesController do - let(:conference) { create(:conference) } let(:organizer_role) { Role.find_by(name: 'organizer', resource: conference) } let(:cfp_role) { Role.find_by(name: 'cfp', resource: conference) } diff --git a/spec/features/roles_spec.rb b/spec/features/roles_spec.rb index ebdeacaf..ba9e5d4c 100644 --- a/spec/features/roles_spec.rb +++ b/spec/features/roles_spec.rb @@ -98,6 +98,51 @@ feature Role do end end + context 'organization_admin' do + let!(:organization) { create(:organization) } + let!(:org_admin_role) { Role.find_by(name: 'organization_admin', resource: organization) } + let!(:organization_admin) { create(:user, role_ids: [org_admin_role.id]) } + let(:user_with_no_role) { create :user } + let!(:other_organization) { create(:organization) } + + before do + sign_in organization_admin + visit admin_organizations_path + end + + context 'for the organization it belongs to' do + scenario 'successfully adds role organization_admin' do + click_link('Admins', href: admins_admin_organization_path(organization.id)) + + fill_in 'user_email', with: user_with_no_role.email + click_button 'Add' + user_with_no_role.reload + + expect(user_with_no_role.has_role?('organization_admin', organization)).to eq true + end + + scenario 'successfully removes role organization_admin' do + click_link('Admins', href: admins_admin_organization_path(organization.id)) + + first('tr').find('.btn-danger').click + expect(organization_admin.has_role?('organization_admin', organization)).to eq false + end + end + + context 'for the organizations it does not belong to' do + scenario 'does not successfully add role organization_admin' do + click_link('Admins', href: admins_admin_organization_path(other_organization.id)) + + expect(page.has_field?('user_email')).to eq false + end + + scenario 'does not successfully removes role organization_admin' do + click_link('Admins', href: admins_admin_organization_path(other_organization.id)) + expect(page.has_css?('.btn-danger')).to eq false + end + end + end + context 'organizer' do Role.all.each.map(&:name).each do |role| it_behaves_like 'successfully', role, 'organizer' diff --git a/spec/models/admin_ability_spec.rb b/spec/models/admin_ability_spec.rb index 805dd621..f148b2ae 100644 --- a/spec/models/admin_ability_spec.rb +++ b/spec/models/admin_ability_spec.rb @@ -63,7 +63,7 @@ describe 'User with admin role' do it{ should_not be_able_to(:update, Role.find_by(name: 'organization_admin', resource: other_organization)) } it{ should_not be_able_to(:edit, Role.find_by(name: 'organization_admin', resource: other_organization)) } - it{ should_not be_able_to(:show, Role.find_by(name: 'organization_admin', resource: other_organization)) } + it{ should be_able_to(:admins, organization) } it{ should_not be_able_to(:new, User.new) } it{ should_not be_able_to(:create, User.new) } @@ -127,6 +127,8 @@ describe 'User with admin role' do let(:other_organization) { create(:organization) } let(:other_conference) { create(:conference, organization: other_organization) } + it{ should be_able_to(:assign_org_admins, organization) } + it{ should be_able_to(:unassign_org_admins, organization) } it{ should be_able_to(:manage, my_conference) } it{ should be_able_to(:read, organization) } it{ should be_able_to(:update, organization) } @@ -137,6 +139,8 @@ describe 'User with admin role' do it{ should_not be_able_to(:create, Conference.new(organization_id: other_organization.id)) } it{ should_not be_able_to(:new, Organization.new) } it{ should_not be_able_to(:create, Organization.new) } + + it_behaves_like 'user with any role' end context 'when user has the role organizer' do @@ -214,6 +218,9 @@ describe 'User with admin role' do it{ should be_able_to(:manage, resource) } + it{ should_not be_able_to(:assign_org_admins, organization) } + it{ should_not be_able_to(:unassign_org_admins, organization) } + %w[organizer cfp info_desk volunteers_coordinator].each do |role| it{ should be_able_to(:toggle_user, Role.find_by(name: role, resource: my_conference)) } it{ should be_able_to(:edit, Role.find_by(name: role, resource: my_conference)) } @@ -299,6 +306,8 @@ describe 'User with admin role' do it{ should be_able_to(:index, resource) } it{ should be_able_to(:show, resource) } it{ should be_able_to(:update, resource) } + it{ should_not be_able_to(:assign_org_admins, organization) } + it{ should_not be_able_to(:unassign_org_admins, organization) } it_behaves_like 'user with any role' it_behaves_like 'user with non-organizer role', 'cfp' @@ -366,6 +375,8 @@ describe 'User with admin role' do it{ should be_able_to(:index, resource) } it{ should be_able_to(:show, resource) } it{ should be_able_to(:update, resource) } + it{ should_not be_able_to(:assign_org_admins, organization) } + it{ should_not be_able_to(:unassign_org_admins, organization) } it_behaves_like 'user with any role' it_behaves_like 'user with non-organizer role', 'info_desk' @@ -433,6 +444,8 @@ describe 'User with admin role' do it{ should be_able_to(:index, resource) } it{ should be_able_to(:show, resource) } it{ should be_able_to(:update, resource) } + it{ should_not be_able_to(:assign_org_admins, organization) } + it{ should_not be_able_to(:unassign_org_admins, organization) } it 'should be_able to :manage Vposition' it 'should be_able to :manage Vday' @@ -509,6 +522,9 @@ describe 'User with admin role' do it{ should_not be_able_to(:edit, my_self_organized_track) } it{ should_not be_able_to(:update, my_self_organized_track) } + it{ should_not be_able_to(:assign_org_admins, organization) } + it{ should_not be_able_to(:unassign_org_admins, organization) } + it_behaves_like 'user with any role' it_behaves_like 'user with non-organizer role', 'track_organizer' end From 1a5aa14e2cb825ed79af4567cce5a2bf2790211b Mon Sep 17 00:00:00 2001 From: shlok007 Date: Sun, 13 Aug 2017 02:31:46 +0530 Subject: [PATCH 9/9] Mention organization name while creating a conference --- app/controllers/admin/conferences_controller.rb | 3 ++- app/views/admin/conferences/new.html.haml | 1 + spec/features/conference_spec.rb | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index 3905012c..d8c101d1 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -72,11 +72,12 @@ module Admin def new @conference = Conference.new + @organizations = Organization.accessible_by(current_ability, :update).pluck(:name, :id) end def create @conference = Conference.new(conference_params) - @conference.organization = Organization.find_or_create_by(name: 'organization') + if @conference.save # user that creates the conference becomes organizer of that conference current_user.add_role :organizer, @conference diff --git a/app/views/admin/conferences/new.html.haml b/app/views/admin/conferences/new.html.haml index 014758de..9e115457 100644 --- a/app/views/admin/conferences/new.html.haml +++ b/app/views/admin/conferences/new.html.haml @@ -2,6 +2,7 @@ .col-md-8 = semantic_form_for(@conference, url: admin_conferences_path) do |f| = f.inputs 'Basic Information' do + = f.input :organization, as: :select, collection: @organizations = f.input :title, hint: "The name of your conference as it shall appear throughout the site. Example: 'OpenSUSE Conference 2013'", input_html: { required: 'required' } = f.input :short_title, hint: "A short and unique handle for your conference, using only letters, numbers, underscores, and dashes. This will be used to identify your conference in URLs etc. Example: 'froscon2011'", diff --git a/spec/features/conference_spec.rb b/spec/features/conference_spec.rb index f3205e07..0dc4e228 100644 --- a/spec/features/conference_spec.rb +++ b/spec/features/conference_spec.rb @@ -2,13 +2,15 @@ require 'spec_helper' feature Conference do let!(:user) { create(:admin) } - + let!(:organization) { create(:organization) } shared_examples 'add and update conference' do scenario 'adds a new conference', feature: true, js: true do expected_count = Conference.count + 1 sign_in user visit new_admin_conference_path + + select organization.name, from: 'conference_organization_id' fill_in 'conference_title', with: 'Example Con' fill_in 'conference_short_title', with: 'ExCon' @@ -27,7 +29,7 @@ feature Conference do expect(flash) .to eq('Conference was successfully created.') expect(Conference.count).to eq(expected_count) - + expect(Conference.last.organization).to eq(organization) expect(user.has_role? :organizer, Conference.last).to eq(true) end