Merge branch 'master' into org-name-in-conf
This commit is contained in:
commit
7b923e4e01
11 changed files with 193 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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!
|
||||
|
|
@ -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),
|
||||
|
|
|
|||
24
app/views/admin/organizations/show_org_admins.haml
Normal file
24
app/views/admin/organizations/show_org_admins.haml
Normal file
|
|
@ -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 }
|
||||
Loading…
Add table
Add a link
Reference in a new issue