Drop Organization Feature

This commit is contained in:
Henne Vogelsang 2024-06-07 16:19:29 +02:00
parent dc1a6a4363
commit 275be8c80a
No known key found for this signature in database
GPG key ID: 97DDB66BDAF8D4D6
28 changed files with 22 additions and 402 deletions

View file

@ -21,8 +21,7 @@ module Admin
return false
end
unless (current_user.has_cached_role? :organizer, :any) || (current_user.has_cached_role? :cfp, :any) ||
(current_user.has_cached_role? :info_desk, :any) || (current_user.has_cached_role? :organization_admin, :any) ||
(current_user.has_cached_role? :volunteers_coordinator, :any) ||
(current_user.has_cached_role? :info_desk, :any) || (current_user.has_cached_role? :volunteers_coordinator, :any) ||
(current_user.has_cached_role? :track_organizer, :any) || current_user.is_admin
raise CanCan::AccessDenied.new('You are not authorized to access this page.')
end

View file

@ -180,7 +180,7 @@ module Admin
:use_vpositions, :use_vdays, :vdays_attributes,
:vpositions_attributes, :use_volunteers, :color,
:sponsorship_levels_attributes, :sponsors_attributes,
:registration_limit, :organization_id, :ticket_layout,
:registration_limit, :ticket_layout,
:booth_limit)
end
end

View file

@ -1,98 +0,0 @@
# frozen_string_literal: true
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
end
def create
@organization = Organization.new(organization_params)
if @organization.save
redirect_to admin_organizations_path,
notice: 'Organization successfully created'
else
redirect_to new_admin_organization_path,
error: @organization.errors.full_messages.join(', ')
end
end
def new
@organization = Organization.new
end
def edit; end
def update
if @organization.update(organization_params)
redirect_to admin_organizations_path,
notice: 'Organization successfully updated'
else
redirect_to edit_admin_organization_path(@organization),
error: @organization.errors.full_messages.join(', ')
end
end
def destroy
if @organization.destroy
redirect_to admin_organizations_path,
notice: 'Organization successfully destroyed'
else
redirect_to admin_organizations_path,
error: 'Organization cannot be destroyed'
end
end
def assign_org_admins
if @user.has_cached_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, :code_of_conduct
)
end
end
end

View file

@ -8,9 +8,6 @@ module Admin
def index
@conferences_with_role = current_user.is_admin? ? Conference.pluck(:short_title) : Conference.with_role([:organizer, :cfp, :info_desk], current_user).pluck(:short_title)
if current_user.has_cached_role? :organization_admin, :any
@conferences_with_role = Organization.with_role('organization_admin', current_user).map { |org| org.conferences.pluck :short_title }.flatten
end
@conferences_with_role.uniq!
return if @conference.blank?

View file

@ -1,21 +0,0 @@
# frozen_string_literal: true
class OrganizationsController < ApplicationController
load_and_authorize_resource :organization
def index
@organizations = Organization.all
end
def code_of_conduct
@title = "#{@organization.name}: Code of Conduct"
@content = @organization.code_of_conduct
render 'document'
end
def conferences
@current = @organization.conferences.upcoming.reorder(start_date: :asc)
@antiquated = @organization.conferences.past
render '/conferences/index'
end
end

View file

@ -140,7 +140,7 @@ module ApplicationHelper
def nav_root_link_for(conference)
link_text = (
conference.try(:organization).try(:name) || ENV.fetch('OSEM_NAME', 'OSEM')
ENV.fetch('OSEM_NAME', 'OSEM')
)
link_to(
link_text,

View file

@ -8,15 +8,6 @@ module VersionsHelper
version.item && conference ? link_to(link_text, link_url) : "#{link_text} with ID #{version.item_id}"
end
def link_to_organization(organization_id)
return 'deleted organization' unless organization_id
org = Organization.find_by(id: organization_id)
return current_or_last_object_state('Organization', organization_id).try(:name) unless org
org.name.to_s
end
def link_to_conference(conference_id)
return 'deleted conference' if conference_id.nil?

View file

@ -12,9 +12,6 @@ class Conference < ApplicationRecord
scope :upcoming, (-> { where('end_date >= ?', Date.current) })
scope :past, (-> { where('end_date < ?', Date.current) })
belongs_to :organization
delegate :code_of_conduct, to: :organization
has_paper_trail ignore: %i(updated_at guid revision events_per_week), meta: { conference_id: :id }
has_and_belongs_to_many :questions
@ -83,7 +80,6 @@ class Conference < ApplicationRecord
:start_hour,
:end_hour,
:ticket_layout,
:organization,
:timezone, presence: true
validates :short_title, uniqueness: true
@ -579,11 +575,11 @@ class Conference < ApplicationRecord
# * +ActiveRecord+
def self.get_active_conferences_for_dashboard
result = Conference.where('start_date > ?', Time.now)
.select('id, short_title, color, start_date, organization_id')
.select('id, short_title, color, start_date')
if result.empty?
result = Conference
.select('id, short_title, color, start_date, organization_id').limit(2)
.select('id, short_title, color, start_date').limit(2)
.order(start_date: :desc)
end
result
@ -595,7 +591,7 @@ class Conference < ApplicationRecord
# ====Returns
# * +ActiveRecord+
def self.get_conferences_without_active_for_dashboard(active_conferences)
result = Conference.select('id, short_title, color, start_date, organization_id').order(start_date: :desc)
result = Conference.select('id, short_title, color, start_date').order(start_date: :desc)
result - active_conferences
end

View file

@ -1,25 +0,0 @@
# frozen_string_literal: true
class Organization < ApplicationRecord
resourcify :roles, dependent: :delete_all
has_paper_trail
has_many :conferences, dependent: :destroy
after_create :create_roles
validates :name,
uniqueness: {
case_sensitive: false
},
presence: true
mount_uploader :picture, PictureUploader, mount_on: :picture
private
def create_roles
roles.where(name: 'organization_admin').first_or_create(description: 'For the administrators of an organization and its conferences')
end
end

View file

@ -67,7 +67,6 @@ class TicketPdf < Prawn::Document
move_down 70
draw_text @conference.title.to_s, at: [@mid_horizontal + 30, cursor - 30], size: 12
draw_text @conference.organization.name.to_s, at: [@mid_horizontal + 30, cursor - 50], size: 12
if @conference.venue
draw_text @conference.venue_name, at: [@mid_horizontal + 30, cursor - 70]
draw_text @conference.venue_street, at: [@mid_horizontal + 30, cursor - 90]

View file

@ -1,10 +1,6 @@
%h4
Basic Information
%hr
- if f.object.new_record?
.form-group
= f.label :organization, "Organization"
= f.select :organization_id, Organization.accessible_by(current_ability, :update).pluck(:name, :id)
.form-group
= f.label :title, "Title"
%abbr{title: 'This field is required'} *

View file

@ -1,22 +0,0 @@
= form_for(@organization, url: (@organization.new_record? ? admin_organizations_path : admin_organization_path(@organization))) do |f|
.form-group
= f.label :name, "Name"
%abbr{title: 'This field is required'} *
= f.text_field :name, required: true, class: 'form-control', placeholder: 'Name'
.form-group
= f.text_area :description, rows: 10, data: { provide: 'markdown' }, class: 'form-control', placeholder: 'Decribe about your organization...'
%span.help-block
= markdown_hint
.form-group
= f.text_area :code_of_conduct, rows: 10, data: { provide: 'markdown' }, class: 'form-control', placeholder: 'Rules governing behavior and dispute resolution...'
%span.help-block
= markdown_hint
.form-group
= image_tag f.object.picture.thumb.url if f.object.picture?
= f.file_field :picture
%p.text-right
%button{type: 'submit', class: 'btn btn-success'}
- if @organization.new_record?
Create Organization
- else
Update Organization

View file

@ -1,26 +0,0 @@
.page-header
%h3 Users (#{users.length})
- if users.present?
%table.datatable#users
%thead
%tr
%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!

View file

@ -1,9 +0,0 @@
.row
.col-md-12
.page-header
%h1
Edit Organization
= @organization.name
.row
.col-md-8
= render partial: 'form'

View file

@ -1,40 +0,0 @@
.row
.col-md-12
.page-header
%h1 Organizations
- if can? :manage, :all
.btn-group.pull-right
= link_to 'Create Organization', new_admin_organization_path, class: 'btn btn-success pull-right'
%p.text-muted
Manage organizations in OSEM
.row
.col-md-12
%table.datatable
%thead
%tr
%th Name
%th Upcoming Conferences
%th Past Conferences
%th Code of Conduct?
%th Actions
%tbody
- @organizations.each do |organization|
%tr{ id: "organization-#{organization.id}" }
%td
= organization.name
%td
= organization.conferences.upcoming.count
%td
= organization.conferences.past.count
%td.text-center
- unless organization.code_of_conduct.blank?
= icon 'fa-solid', 'check', title: 'yes'
%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),
method: :delete, class: 'btn btn-danger', data: { confirm: "Warning: This will delete #{organization.name} and all its data which includes data for all conferences within #{organization.name}. Do you really want to continue?" }
= link_to 'Add Conference', new_admin_conference_path, method: :get, class: 'btn btn-info'

View file

@ -1,8 +0,0 @@
.row
.col-md-12
.page-header
%h1
Create Organization
.row
.col-md-8
= render partial: 'form'

View file

@ -1,20 +0,0 @@
.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 )
= form_for :user, url: assign_org_admins_admin_organization_path(@organization, @role.name), method: :post do |f|
.form-group
= f.label :email, 'Add user by email: '
= f.text_field :email, placeholder: "User's email", class: 'form-control', required: true
= f.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 }

View file

@ -7,23 +7,10 @@
end
- case version.item_type
- when 'Organization'
organization
= link_to_organization(version.item_id)
- when 'UsersRole'
- role = current_or_last_object_state('Role', object.role_id)
- role_name = role.try(:name) || PaperTrail::Version.where(item_type: 'Role', item_id: object.role_id).last.changeset[:name].second
role
- if role_name == 'organization_admin'
- if Organization.find_by(id: version.conference_id)
-# organization_admin belongs to organization and not conferences
- organization = Organization.find_by(id: version.conference_id)
= link_if_alive version, role_name,
admins_admin_organization_path(organization), organization
- else
(Deleted Organization)
- else
- conference = Conference.find_by(id: version.conference_id)
- conference_short_title = conference.try(:short_title) || current_or_last_object_state('Conference', version.conference_id).try(:short_title) || ' '
= link_if_alive version, role.try(:name), admin_conference_role_path(conference_short_title,role.try(:name) || ' '), conference
@ -133,15 +120,6 @@
- when 'Role'
role
- role_name = object.try(:name) || PaperTrail::Version.where(item_type: 'Role', item_id: version.item_id).last.changeset[:name].second
- if role_name == 'organization_admin'
- if Organization.find_by(id: version.conference_id)
-# organization_admin belongs to organization and not conferences
- organization = Organization.find_by(id: version.conference_id)
= link_if_alive version, role_name,
admins_admin_organization_path(organization), organization
- else
(Role Deleted)
- else
- conference = Conference.find_by(id: version.conference_id)
- conference_short_title = conference.try(:short_title) || current_or_last_object_state('Conference', version.conference_id).try(:short_title) || ' '
= link_if_alive version, role_name,
@ -202,16 +180,8 @@
user
= link_to_user(version.item_id)
- unless %w(Conference Subscription Registration User Organization).include?(version.item_type)
- if (version.item_type == 'Role' && role_name == 'organization_admin') || (version.item_type == 'UsersRole' && role_name == 'organization_admin')
in organization
- if Organization.find_by(id: version.conference_id)
-# organization_admin belongs to organization and not conferences
- organization = Organization.find_by(id: version.conference_id)
= link_to_organization(version.conference_id)
- else
(Organization Deleted)
- elsif version.item_type == 'Commercial'
- unless %w(Conference Subscription Registration User).include?(version.item_type)
- if version.item_type == 'Commercial'
- commercial = current_or_last_object_state(version.item_type, version.item_id)
- commercialable = current_or_last_object_state(commercial.commercialable_type, commercial.commercialable_id)
- unless commercial.commercialable_type == 'Conference'

View file

@ -27,4 +27,4 @@
(Scheduled on: #{event.time.to_date})
%br
= render 'conferences/code_of_conduct', organization: @conference.organization
= render 'conferences/code_of_conduct'

View file

@ -37,8 +37,7 @@
You need to accept the
= link_to 'Code of Conduct', '#',
data: { toggle: 'modal', target: '#modal-code-of-conduct'}
= render 'conferences/code_of_conduct',
organization: @conference.organization
= render 'conferences/code_of_conduct'
- if @conference.surveys.for_registration.any?
.row
.col-md-12

View file

@ -4,7 +4,7 @@
data: { toggle: 'modal', target: '#modal-code-of-conduct'}
- content_for :modals do
- cache [organization, '#CoC-modal'] do
- cache '#CoC-modal' do
.modal.fade{ id: "modal-code-of-conduct" }
.modal-dialog
.modal-content
@ -13,8 +13,6 @@
%i.fa-solid.fa-xmark
%h3.modal-title Code of Conduct
.modal-body
= markdown organization.code_of_conduct
= markdown conference.code_of_conduct
.modal-footer
= link_to 'permalink',
[:code_of_conduct, organization],
target: '_blank'
= link_to 'permalink', :code_of_conduct

View file

@ -27,9 +27,7 @@
- if conference.program and conference.program.schedule_public
= link_to "Schedule", conference_schedule_path(conference.short_title), class: 'btn btn-default'
- unless conference.code_of_conduct.blank?
= link_to "Code of Conduct",
[:code_of_conduct, conference.organization],
class: 'btn btn-default'
= link_to "Code of Conduct", :code_of_conduct, class: 'btn btn-default'
- if conference.registration_open?
- if conference.user_registered?(current_user)
= link_to "My Registration", conference_conference_registration_path(conference.short_title), class: 'btn btn-default'

View file

@ -19,7 +19,7 @@
#splash
- if @conference.code_of_conduct.present?
= render 'code_of_conduct', organization: @conference.organization
= render 'code_of_conduct'
-# header/description
= render 'header', conference: @conference, venue: @conference.venue

View file

@ -27,18 +27,8 @@
= link_to(admin_users_path) do
%span.fa-solid.fa-user
Users
- if can? :index, Organization
%li
= link_to(admin_organizations_path) do
%span.fa-solid.fa-users
Organizations
- if can? :index, PaperTrail::Version
%li
= link_to(admin_revision_history_path) do
%span.fa-solid.fa-clock-rotate-left
Revision History
- if ENV.fetch('ORGANIZATIONS_ENABLED', nil) == 'true'
%li
= link_to(admin_organizations_path) do
%span.fa-solid.fa-user-group
Organizations

View file

@ -76,8 +76,3 @@
= link_to(admin_revision_history_path) do
%span.fa-solid.fa-clock-rotate-left
Revision History
- if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true'
%li
= link_to(admin_organizations_path) do
%span.fa-solid.fa-user-group
Organizations

View file

@ -1,21 +0,0 @@
.container
.row
.col-md-12.page-header
%h1
Organizations
.btn-group.pull-right
/ = link_to 'Add new', new_organization_path, class: 'btn btn-mini btn-success'
- @organizations.each do |organization|
.col-md-4{ id: "organization-#{organization.id}" }
.thumbnail
= image_tag(organization.picture.thumb.url, width: '20%') if organization.picture?
.caption
%h4
= organization.name
.btn-group
= link_to 'Conferences',
conferences_organization_path(organization),
class: 'btn btn-success'
- unless organization.code_of_conduct.blank?
= link_to 'Code of Conduct', [:code_of_conduct, organization], class: 'btn btn-info'
/ = link_to 'Edit', edit_organization_path(organization), class: 'btn btn-mini btn-default'

View file

@ -34,12 +34,6 @@
= image_tag(@conference.picture.ticket.url, class: 'img-responsive')
- else
= image_tag('/img/osem-logo.png', class: 'img-responsive')
%p.text-left
%br
%strong
Organization
%br
= @conference.organization.name
.col-md-5.box.well
%p.text-left
%strong

View file

@ -23,13 +23,6 @@ Osem::Application.routes.draw do
end
namespace :admin do
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
@ -150,11 +143,6 @@ Osem::Application.routes.draw do
get '/revision_history/:id/revert_object' => 'versions#revert_object', as: 'revision_history_revert_object'
get '/revision_history/:id/revert_attribute' => 'versions#revert_attribute', as: 'revision_history_revert_attribute'
end
resources :organizations, only: [:index] do
member do
get :conferences, 'code-of-conduct'
end
end
resources :conferences, only: [:index, :show] do
resources :booths do
member do