Skip to content

Commit

Permalink
refactor: Changes admin to director
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaudouinjr committed Sep 6, 2020
1 parent ac720d9 commit f592750
Show file tree
Hide file tree
Showing 60 changed files with 170 additions and 174 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/manage/lib/setupDataTables.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var setupDataTables = function () {
],
});

$('.datatable.admins').DataTable({
$('.datatable.staff').DataTable({
order: [2, 'asc'],
columns: [
{ orderable: true, data: 'id', visible: false },
Expand Down
20 changes: 10 additions & 10 deletions app/controllers/manage/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
class Manage::ApplicationController < ApplicationController
before_action :logged_in
before_action :require_admin_or_limited_admin
before_action :limit_write_access_to_admins, only: ["edit", "update", "new", "create", "destroy", "convert_to_admin", "deliver", "merge", "perform_merge", "toggle_bus_captain", "duplicate", "update_acc_status", "send_update_email", "live_preview"]
before_action :require_director_or_limited_admin
before_action :limit_write_access_to_directors, only: ["edit", "update", "new", "create", "destroy", "convert_to_admin", "deliver", "merge", "perform_merge", "toggle_bus_captain", "duplicate", "update_acc_status", "send_update_email", "live_preview"]
skip_before_action :verify_authenticity_token, if: :json_request?

def logged_in
authenticate_user!
end

def require_full_admin
return redirect_to root_path unless current_user.try(:admin?)
def require_director
return redirect_to root_path unless current_user.try(:director?)
end

def require_admin_or_limited_admin
return redirect_to root_path unless current_user.try(:admin?) || current_user.try(:admin_limited_access?)
def require_director_or_limited_admin
return redirect_to root_path unless current_user.try(:director?) || current_user.try(:admin_limited_access?)
end

def require_admin_or_limited_admin_or_event_tracking
redirect_to root_path unless current_user.try(:admin?) || current_user.try(:admin_limited_access?) || current_user.try(:event_tracking?)
def require_director_or_limited_admin_or_event_tracking
redirect_to root_path unless current_user.try(:director?) || current_user.try(:admin_limited_access?) || current_user.try(:event_tracking?)
end

def limit_write_access_to_admins
redirect_to url_for(controller: controller_name, action: :index) unless current_user.try(:admin?)
def limit_write_access_to_directors
redirect_to url_for(controller: controller_name, action: :index) unless current_user.try(:director?)
end

def json_request?
Expand Down
5 changes: 1 addition & 4 deletions app/controllers/manage/configs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Manage::ConfigsController < Manage::ApplicationController
before_action :limit_access_admin
before_action :require_director
before_action :get_config, only: [:edit, :update, :update_only_css_variables]

respond_to :html, :json
Expand Down Expand Up @@ -69,7 +69,4 @@ def get_config
end
end

def limit_access_admin
redirect_to root_path unless current_user.admin?
end
end
3 changes: 1 addition & 2 deletions app/controllers/manage/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Manage::DashboardController < Manage::ApplicationController
skip_before_action :require_admin_or_limited_admin
before_action :require_admin_or_limited_admin
before_action :require_director_or_limited_admin

def index
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/manage/data_exports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Manage::DataExportsController < Manage::ApplicationController
skip_before_action :require_admin_or_limited_admin
before_action :require_full_admin
skip_before_action :require_director_or_limited_admin
before_action :require_director

before_action :set_data_export, only: [:destroy]

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/manage/messages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Manage::MessagesController < Manage::ApplicationController
before_action :set_message, only: [:show, :edit, :update, :destroy, :deliver, :preview, :duplicate]
before_action :check_message_access, only: [:edit, :update, :destroy]
before_action :limit_template_access_to_admins, only: [:template, :template_preview, :template_update, :template_replace_with_default]
before_action :limit_template_access_to_directors, only: [:template, :template_preview, :template_update, :template_replace_with_default]

respond_to :html, :json

Expand Down Expand Up @@ -106,9 +106,9 @@ def template_replace_with_default

private

def limit_template_access_to_admins
def limit_template_access_to_directors
# From Manage::ApplicationController
limit_write_access_to_admins
limit_write_access_to_directors
end

def message_params
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/manage/questionnaires_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Manage::QuestionnairesController < Manage::ApplicationController
include QuestionnairesControllable

before_action :set_questionnaire, only: [:show, :edit, :update, :destroy, :check_in, :convert_to_admin, :update_acc_status]
before_action :set_questionnaire, only: [:show, :edit, :update, :destroy, :check_in, :convert_to_director, :update_acc_status]

respond_to :html, :json

Expand Down Expand Up @@ -95,10 +95,10 @@ def check_in
redirect_to index_redirect_path
end

def convert_to_admin
def convert_to_director
user = @questionnaire.user
@questionnaire.destroy
user.update_attributes(role: :admin)
user.update_attributes(role: :director)
redirect_to edit_manage_user_path(user)
end

Expand Down
12 changes: 6 additions & 6 deletions app/controllers/manage/trackable_events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Manage::TrackableEventsController < Manage::ApplicationController
skip_before_action :require_admin_or_limited_admin
before_action :require_admin_or_limited_admin_or_event_tracking
skip_before_action :require_director_or_limited_admin
before_action :require_director_or_limited_admin_or_event_tracking

before_action :set_trackable_event, only: [:show, :edit, :update, :destroy]
before_action :scope_limited_admin_access, only: [:edit, :update, :destroy]
Expand Down Expand Up @@ -81,13 +81,13 @@ def trackable_event_params
params.require(:trackable_event).permit(:band_id, :trackable_tag_id)
end

# Permit limited-access admins (overrides Manage::ApplicationController#limit_write_access_to_admins)
def limit_write_access_to_admins
# Permit limited-access directors (overrides Manage::ApplicationController#limit_write_access_to_directors)
def limit_write_access_to_directors
end

# If the user isn't a full admin, scope changes only to those they created
# If the user isn't a director, scope changes only to those they created
def scope_limited_admin_access
return if current_user.admin? || @trackable_event.blank? || @trackable_event.user.blank?
return if current_user.director? || @trackable_event.blank? || @trackable_event.user.blank?
redirect_to manage_trackable_events_path, notice: 'You may not view events you did not create.' if @trackable_event.user != current_user
end
end
4 changes: 2 additions & 2 deletions app/controllers/manage/trackable_tags_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Manage::TrackableTagsController < Manage::ApplicationController
skip_before_action :require_admin_or_limited_admin
before_action :require_admin_or_limited_admin_or_event_tracking
skip_before_action :require_director_or_limited_admin
before_action :require_director_or_limited_admin_or_event_tracking

before_action :set_trackable_tag, only: [:show, :edit, :update, :destroy]

Expand Down
8 changes: 4 additions & 4 deletions app/controllers/manage/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
class Manage::UsersController < Manage::ApplicationController
before_action :require_full_admin
before_action :require_director
before_action :find_user, only: [:show, :edit, :update, :destroy]

respond_to :html, :json

def index
respond_with(:manage, User.where(role: [:admin, :admin_limited_access, :event_tracking]))
respond_with(:manage, User.where(role: [:director, :admin_limited_access, :event_tracking]))
end

def user_datatable
render json: UserDatatable.new(params, view_context: view_context)
end

def admin_datatable
render json: AdminDatatable.new(params, view_context: view_context)
def staff_datatable
render json: StaffDatatable.new(params, view_context: view_context)
end

def show
Expand Down
4 changes: 2 additions & 2 deletions app/datatables/questionnaire_datatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def note(record)

def bus_captain(record)
return "No" unless record.bus_list_id?
return record.is_bus_captain? ? '<span class="badge badge-success">Yes</span>' : "No" unless current_user.admin?
return record.is_bus_captain? ? '<span class="badge badge-success">Yes</span>' : "No" unless current_user.director?

if record.is_bus_captain?
link_to("Remove", toggle_bus_captain_manage_bus_list_path(record.bus_list_id, questionnaire_id: record.id, bus_captain: "0"), method: "post", class: "text-danger")
Expand All @@ -47,7 +47,7 @@ def bus_captain(record)
def data
records.map do |record|
{
bulk: current_user.admin? ? "<input type=\"checkbox\" data-bulk-row-edit=\"#{record.id}\">".html_safe : "",
bulk: current_user.director? ? "<input type=\"checkbox\" data-bulk-row-edit=\"#{record.id}\">".html_safe : "",
link: link_to('<i class="fa fa-search"></i>'.html_safe, manage_questionnaire_path(record)),
note: note(record),
id: record.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class AdminDatatable < ApplicationDatatable
class StaffDatatable < ApplicationDatatable
def_delegators :@view, :link_to, :manage_user_path, :bold, :display_datetime

def view_columns
Expand Down Expand Up @@ -43,6 +43,6 @@ def data
end

def get_raw_records
User.where(role: [:admin, :admin_limited_access, :event_tracking])
User.where(role: [:director, :admin_limited_access, :event_tracking])
end
end
8 changes: 4 additions & 4 deletions app/jobs/bulk_message_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def self.build_recipients(recipient_types)
def self.user_ids(type)
case type
when "all"
# Everyone, including admins that completed a questionnaire
User.non_admins.pluck(:id) + Questionnaire.pluck(:user_id)
# Everyone, including organizers that completed a questionnaire
User.non_organizer.pluck(:id) + Questionnaire.pluck(:user_id)
when "incomplete"
# Incomplete applications, excluding admins that don't have a questionnaire
User.non_admins.pluck(:id) - Questionnaire.pluck(:user_id)
# Incomplete applications, excluding organizers that don't have a questionnaire
User.non_organizer.pluck(:id) - Questionnaire.pluck(:user_id)
when "complete"
Questionnaire.pluck(:user_id)
when "accepted"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class AdminWeeklyReportJob < ApplicationJob
class StaffWeeklyReportJob < ApplicationJob
queue_as :default

def perform
# Queue all eligible users and let the is_active (or other) logic determine if they should really receive it
users = User.where(receive_weekly_report: true)
users.each do |user|
AdminMailer.weekly_report(user.id).deliver_later
StaffMailer.weekly_report(user.id).deliver_later
end
end
end
4 changes: 2 additions & 2 deletions app/mailers/mail_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ def bulk_message_email
UserMailer.bulk_message_email(message, User.first.id)
end

def admin_weekly_report
AdminMailer.weekly_report(User.first.id)
def staff_weekly_report
StaffMailer.weekly_report(User.first.id)
end
end
end
4 changes: 2 additions & 2 deletions app/mailers/admin_mailer.rb → app/mailers/staff_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class AdminMailer < ApplicationMailer
class StaffMailer < ApplicationMailer
include Roadie::Rails::Automatic
add_template_helper(HackathonManagerHelper)

layout "admin_mailer"
layout "staff_mailer"

def weekly_report(user_id)
# Don't send emails more than 7 days after event starts
Expand Down
2 changes: 1 addition & 1 deletion app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def bulk_message_email(message_id, user_id, message = nil, use_examples = false)

def incomplete_reminder_email(user_id)
@user = User.find_by_id(user_id)
return if @user.blank? || @user.admin? || @user.questionnaire || Time.now.to_date > Date.parse(HackathonConfig["last_day_to_apply"])
return if @user.blank? || @user.director? || @user.questionnaire || Time.now.to_date > Date.parse(HackathonConfig["last_day_to_apply"])

Message.queue_for_trigger("user.24hr_incomplete_application", @user.id)
end
Expand Down
8 changes: 4 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class User < ApplicationRecord
after_create :queue_reminder_email
after_initialize :set_default_role, if: :new_record?

enum role: { user: 0, event_tracking: 1, admin_limited_access: 2, admin: 3 }
enum role: { user: 0, event_tracking: 1, admin_limited_access: 2, director: 3 }

def set_default_role
self.role ||= :user
Expand Down Expand Up @@ -75,11 +75,11 @@ def self.from_omniauth(auth)
current_user
end

def self.non_admins
User.where.not(role: :admin).where.not(role: :admin_limited_access)
def self.non_organizer
User.where.not(role: :director).where.not(role: :admin_limited_access)
end

def self.without_questionnaire
non_admins.left_outer_joins(:questionnaire).where(questionnaires: { id: nil })
non_organizer.left_outer_joins(:questionnaire).where(questionnaires: { id: nil })
end
end
2 changes: 1 addition & 1 deletion app/views/layouts/_header.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
= btn_link_to "Home", homepage_url
.header-nav
- if user_signed_in?
- if current_user.admin?
- if current_user.director?
= btn_link_to "Manage", manage_root_path
= btn_link_to "Sign Out", destroy_user_session_path, method: :delete
2 changes: 1 addition & 1 deletion app/views/layouts/manage/_page_title.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
- if defined?(subtitle) && subtitle.present?
%small.text-muted= subtitle

- if current_user.try(:admin?)
- if current_user.try(:director?)
= yield
2 changes: 1 addition & 1 deletion app/views/layouts/manage/application.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
.fa.fa-home.fa-fw.icon-space-r-half
= t(:title, scope: 'pages.manage.schools')
- if current_user.admin?
- if current_user.director?
%h6.sidebar-heading.d-flex.justify-content-between.align-items-center.px-3.mt-4.mb-1.text-muted
%span
= t(:administration, scope: 'layouts.manage.navigation')
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%thead
%tr
%th{'data-table': { orderable: 'false', data: 'bulk', visible: bulk_actions ? 'true' : 'false' }}
- if current_user.admin?
- if current_user.director?
%input{ type: "checkbox", name: "select_allc", value: "1", data: { bulk_row_select: "" } }
%th{'data-table': { orderable: 'false', data: 'link', visible: visible.call('link', columns) }}
%th{'data-table': { orderable: 'false', data: 'note', visible: visible.call('note', columns) }}
Expand Down
4 changes: 2 additions & 2 deletions app/views/manage/bus_lists/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
%th Email
%th Phone Number
%th School
- if current_user.admin?
- if current_user.director?
%th Actions
%tbody
- @bus_list.passengers.select { |q| q.bus_captain_interest }.each do |p|
Expand All @@ -70,7 +70,7 @@
%td= p.email
%td= phone_link_to p.phone
%td= link_to p.school.name, manage_school_path(p.school)
- if current_user.admin?
- if current_user.director?
%td
- if p.is_bus_captain?
= link_to "Remove Bus Captain", toggle_bus_captain_manage_bus_list_path(@bus_list, questionnaire_id: p.id, bus_captain: '0'), method: 'post', class: 'text-danger'
Expand Down
2 changes: 1 addition & 1 deletion app/views/manage/messages/_message_template_status.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
%span.badge.badge-danger.mb-1 Using customized template
%br
Not in sync with HackathonManager
- if current_user.try(:admin?)
- if current_user.try(:director?)
%br
%small
= link_to template_replace_with_default_manage_messages_path, method: :post, data: { confirm: 'Are you sure? This will permanently erase the existing template and replace it with the HackathonManager default. This action is irreversible.'} do
Expand Down
2 changes: 1 addition & 1 deletion app/views/manage/messages/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
= render 'triggered_email_summary'
- if current_user.try(:admin?)
- if current_user.try(:director?)
.mb-4
%h3.pb-2.mb-3.border-bottom#triggered-email-overview Message Template
%p The message template is used for all outgoing emails. If desired, it may be customized to your needs.
Expand Down
8 changes: 4 additions & 4 deletions app/views/manage/questionnaires/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
= render 'check_in_badge'

.btn-group{role: "group"}
- if current_user.admin?
- if current_user.director?
= link_to 'Edit', edit_manage_questionnaire_path(@questionnaire), class: 'btn btn-sm btn-outline-secondary'
- if current_user.admin?
- if current_user.director?
.btn-group{role: "group"}
%button.btn.btn-sm.btn-outline-secondary.dropdown-toggle#title-actions{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", type: "button"}
.fa.fa-cog
.dropdown-menu.dropdown-menu-right{"aria-labelledby" => "title-actions"}
= link_to 'Convert to Admin', convert_to_admin_manage_questionnaire_path(@questionnaire), method: :patch, data: { confirm: "Are you sure? The questionnaire for \"#{@questionnaire.user.full_name}\" will be permanently erased, and \"#{@questionnaire.email}\" will become an admin. This action is irreversible." }, class: 'dropdown-item'
= link_to 'Convert to Director', convert_to_director_manage_questionnaire_path(@questionnaire), method: :patch, data: { confirm: "Are you sure? The questionnaire for \"#{@questionnaire.user.full_name}\" will be permanently erased, and \"#{@questionnaire.email}\" will become a director. This action is irreversible." }, class: 'dropdown-item'

= render 'overview'

Expand All @@ -40,7 +40,7 @@
- else
= "(no author)"
= @questionnaire.acc_status_date ? display_datetime(@questionnaire.acc_status_date, in_sentence: true) : "(no date)"
- if current_user.admin?
- if current_user.director?
= bs_vertical_simple_form @questionnaire, url: url_for(action: "update_acc_status", controller: "questionnaires") do |f|
= f.input :acc_status, as: :select, collection: Questionnaire::POSSIBLE_ACC_STATUS.invert, include_blank: false, label: "Acceptance Status:", hint: "Updating this status may trigger an automatic email to the applicant - see #{link_to('messages', manage_messages_path(anchor: 'triggered-email-overview'))} for details.".html_safe
= f.button :submit, value: "Update Status", class: 'btn-primary'
Expand Down
Loading

0 comments on commit f592750

Please sign in to comment.