diff --git a/app/assets/stylesheets/components/_sortable_list.scss b/app/assets/stylesheets/components/_sortable_list.scss index 7174257d..b8668fe0 100644 --- a/app/assets/stylesheets/components/_sortable_list.scss +++ b/app/assets/stylesheets/components/_sortable_list.scss @@ -36,6 +36,7 @@ display: table-cell; width: 15%; vertical-align: middle; + @media (max-width: $breakpoint-mobile-large) { display: block; } diff --git a/app/assets/stylesheets/components/_users_table.scss b/app/assets/stylesheets/components/_users_table.scss new file mode 100644 index 00000000..5293efbe --- /dev/null +++ b/app/assets/stylesheets/components/_users_table.scss @@ -0,0 +1,13 @@ +.users-table { + width: 100%; + table-layout: fixed; + + th, + td { + padding: 10px 10px; + } + + td { + word-wrap: break-word; + } +} diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 99e5c186..cdc73237 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -50,7 +50,7 @@ def export_user_info def users_csv(users) CSV.generate do |csv| - csv << ['User Name', 'User Last Name', 'User Email', 'User Role', 'Registration Date', 'Branch', 'Zip Code', 'Courses User has Started', 'Courses User has Completed'] + csv << ['User Name', 'User Last Name', 'User Email', 'User Role', 'Preferred Language', 'Registration Date', 'Branch', 'Zip Code', 'Courses User has Started', 'Courses User has Completed'] users.each do |user| row = [] @@ -60,6 +60,7 @@ def users_csv(users) row << profile.try(:last_name) row << user.email row << user.roles.map(&:name).map(&:capitalize).join(', ') + row << user.preferred_language row << user.created_at.in_time_zone('Central Time (US & Canada)').strftime('%m-%d-%Y') row << profile.try(:library_location).try(:name) row << profile.try(:zip_code) diff --git a/app/models/organization.rb b/app/models/organization.rb index 18a65978..78716a8e 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -79,6 +79,16 @@ def clean_up_paperclip_errors errors.delete(:footer_logo_file_size) end + def assignable_roles + default_roles = ['Admin', 'User', 'Trainer'] + + if student_programs? + default_roles + ['Student', 'Parent'] + else + default_roles + end + end + def self.pla find_by(subdomain: 'www') end diff --git a/app/models/user.rb b/app/models/user.rb index 4ef49319..f6402d57 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -44,8 +44,6 @@ class User < ApplicationRecord # Expose some information from profile delegate :library_location_name, :library_location_zipcode, to: :profile, allow_nil: true - ROLES = %w[Admin Trainer User Parent Student].freeze - ### Devise overrides to allow library card number login # TODO: Pull this into a concern diff --git a/app/views/shared/_users_table.html.erb b/app/views/shared/_users_table.html.erb index ee1aa1b5..dd6770e6 100644 --- a/app/views/shared/_users_table.html.erb +++ b/app/views/shared/_users_table.html.erb @@ -1,8 +1,13 @@
Name | <%= t('login_signup.email') %> | -Language | User Role | <%= user.email %> | -- <%= user.preferred_language %> - | <% if current_user.has_role?(:admin, current_organization) %> - <%= select_tag "user_#{user.id}", options_for_select(User::ROLES, user.current_roles.capitalize), data: { user_id: user.id, role: user.current_roles }, class: "user_role small narrow", method: :patch %> + <%= select_tag "user_#{user.id}", options_for_select(current_organization.assignable_roles, user.current_roles.capitalize), data: { user_id: user.id, role: user.current_roles }, class: "user_role small narrow", method: :patch %> <% else %> <%= user.current_roles.empty? ? "user" : user.current_roles %> <% end %> diff --git a/spec/models/organization_spec.rb b/spec/models/organization_spec.rb index cd0aee69..3fd46be1 100644 --- a/spec/models/organization_spec.rb +++ b/spec/models/organization_spec.rb @@ -62,6 +62,17 @@ end end + describe '#assignable_roles' do + it 'returns correct options for typical organization' do + expect(org.assignable_roles).to contain_exactly('Admin', 'User', 'Trainer') + end + + it 'returns correct options for program organization with student programs' do + FactoryBot.create(:program, :student_program, organization: org) + expect(org.assignable_roles).to contain_exactly('Admin', 'User', 'Trainer', 'Parent', 'Student') + end + end + describe '#pla' do it 'returns PLA organization' do expect(Organization.pla).to eq(pla) |
---|