Skip to content

Commit

Permalink
refactor: Renames admin_limited_access to Organizer
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaudouinjr committed Sep 7, 2020
1 parent f592750 commit 873e43c
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 39 deletions.
10 changes: 5 additions & 5 deletions app/controllers/manage/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class Manage::ApplicationController < ApplicationController
before_action :logged_in
before_action :require_director_or_limited_admin
before_action :require_director_or_organizer_or_event_tracking
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?

Expand All @@ -12,12 +12,12 @@ def require_director
return redirect_to root_path unless current_user.try(:director?)
end

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

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?)
def require_director_or_organizer_or_event_tracking
redirect_to root_path unless current_user.try(:director?) || current_user.try(:organizer?) || current_user.try(:event_tracking?)
end

def limit_write_access_to_directors
Expand Down
1 change: 1 addition & 0 deletions app/controllers/manage/checkins_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class Manage::CheckinsController < Manage::ApplicationController
before_action :require_director_or_organizer
before_action :set_questionnaire, only: [:show]

respond_to :html, :json
Expand Down
1 change: 0 additions & 1 deletion app/controllers/manage/dashboard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Manage::DashboardController < Manage::ApplicationController
before_action :require_director_or_limited_admin

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

before_action :set_data_export, only: [:destroy]
Expand Down
7 changes: 2 additions & 5 deletions app/controllers/manage/trackable_events_controller.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
class Manage::TrackableEventsController < Manage::ApplicationController
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]
before_action :scope_organizer_access, only: [:edit, :update, :destroy]

respond_to :html, :json

Expand Down Expand Up @@ -86,7 +83,7 @@ def limit_write_access_to_directors
end

# If the user isn't a director, scope changes only to those they created
def scope_limited_admin_access
def scope_organizer_access
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
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/manage/trackable_tags_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
class Manage::TrackableTagsController < Manage::ApplicationController
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]

respond_to :html, :json
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/manage/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Manage::UsersController < Manage::ApplicationController
respond_to :html, :json

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

def user_datatable
Expand Down
2 changes: 1 addition & 1 deletion app/datatables/staff_datatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ def data
end

def get_raw_records
User.where(role: [:director, :admin_limited_access, :event_tracking])
User.where(role: [:director, :organizer, :event_tracking])
end
end
4 changes: 2 additions & 2 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, director: 3 }
enum role: { user: 0, event_tracking: 1, organizer: 2, director: 3 }

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

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

def self.without_questionnaire
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/doorkeeper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# every time somebody will try to access the admin web interface.
admin_authenticator do
if current_user
head :forbidden unless current_user.director? || current_user.admin_limited_access?
head :forbidden unless current_user.director? || current_user.organizer?
else
redirect_to new_user_session_url
end
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/manage/bus_lists_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ class Manage::BusListsControllerTest < ActionController::TestCase
end
end

context "while authenticated as a limited access admin" do
context "while authenticated as an organizer" do
setup do
@user = create(:limited_access_admin)
@user = create(:organizer)
@request.env["devise.mapping"] = Devise.mappings[:director]
sign_in @user
end
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/manage/checkins_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Manage::CheckinsControllerTest < ActionController::TestCase
end

success_conditions = {
'limited access admin' => :admin_limited_access,
'organizer' => :organizer,
'director' => :director
}

Expand Down
4 changes: 2 additions & 2 deletions test/controllers/manage/configs_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class Manage::ConfigsControllerTest < ActionController::TestCase
end
end

context "while authenticated as a limited access admin" do
context "while authenticated as an organizer" do
setup do
@user = create(:limited_access_admin)
@user = create(:organizer)
@request.env["devise.mapping"] = Devise.mappings[:director]
sign_in @user
end
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/manage/messages_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ class Manage::MessagesControllerTest < ActionController::TestCase
end
end

context "while authenticated as a limited access admin" do
context "while authenticated as an organizer" do
setup do
@user = create(:limited_access_admin)
@user = create(:organizer)
@request.env["devise.mapping"] = Devise.mappings[:director]
sign_in @user
end
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/manage/questionnaires_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase
end
end

context "while authenticated as a limited access admin" do
context "while authenticated as an organizer" do
setup do
@user = create(:limited_access_admin)
@user = create(:organizer)
@request.env["devise.mapping"] = Devise.mappings[:director]
sign_in @user
end
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/manage/schools_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ class Manage::SchoolsControllerTest < ActionController::TestCase
end
end

context "while authenticated as a limited access admin" do
context "while authenticated as an organizer" do
setup do
@user = create(:limited_access_admin)
@user = create(:organizer)
@request.env["devise.mapping"] = Devise.mappings[:director]
sign_in @user
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Manage::TrackableEventsControllerTest < ActionController::TestCase

limited_conditions = {
'event tracking user' => :event_tracking,
'limited access admin' => :admin_limited_access
'organizer' => :organizer
}

limited_conditions.each do |condition_name, user_role|
Expand Down
2 changes: 1 addition & 1 deletion test/controllers/manage/trackable_tags_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Manage::TrackableTagsControllerTest < ActionController::TestCase

limited_conditions = {
'event tracking user' => :event_tracking,
'limited access admin' => :admin_limited_access
'organizer' => :organizer
}

limited_conditions.each do |condition_name, user_role|
Expand Down
4 changes: 2 additions & 2 deletions test/controllers/manage/users_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ class Manage::UsersControllerTest < ActionController::TestCase
end
end

context "while authenticated as a limited access admin" do
context "while authenticated as an organizer" do
setup do
@user = create(:limited_access_admin)
@user = create(:organizer)
@request.env["devise.mapping"] = Devise.mappings[:staff]
sign_in @user
end
Expand Down
6 changes: 3 additions & 3 deletions test/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
role { :director }
end

factory :limited_access_admin do
factory :organizer do
sequence :email do |n|
"limited_admin#{n}@example.com"
"organizer#{n}@example.com"
end
role { :admin_limited_access }
role { :organizer }
end
end
end
2 changes: 1 addition & 1 deletion test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class UserTest < ActiveSupport::TestCase
should "not return staff" do
create(:questionnaire) # user, has questionnaire
create(:user, role: :event_tracking) # user, does not
create(:user, role: :admin_limited_access) # admin, does not
create(:user, role: :organizer) # organizer, does not
create(:user, role: :director) # director, does not
assert_equal 4, User.count
assert_equal 1, User.without_questionnaire.count
Expand Down

0 comments on commit 873e43c

Please sign in to comment.