Skip to content

Commit

Permalink
Merge pull request #458 from commercekitchen/develop
Browse files Browse the repository at this point in the history
Merge develop into master
  • Loading branch information
tmichaelreis authored Jun 12, 2020
2 parents 06f038a + ed4b340 commit 8c0b695
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ GEM
hashdiff (>= 0.4.0, < 2.0.0)
websocket-driver (0.7.1)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.4)
websocket-extensions (0.1.5)
where_exists (1.2.1)
rails (>= 4.2, < 6.1)
wicked_pdf (1.4.0)
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/components/_sortable_list.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
display: table-cell;
width: 15%;
vertical-align: middle;

@media (max-width: $breakpoint-mobile-large) {
display: block;
}
Expand Down
13 changes: 13 additions & 0 deletions app/assets/stylesheets/components/_users_table.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.users-table {
width: 100%;
table-layout: fixed;

th,
td {
padding: 10px 10px;
}

td {
word-wrap: break-word;
}
}
3 changes: 2 additions & 1 deletion app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions app/models/organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ def clean_up_paperclip_errors
errors.delete(:footer_logo_file_size)
end

def assignable_roles
default_roles = %w[Admin User Trainer]

if student_programs?
default_roles + %w[Student Parent]
else
default_roles
end
end

def self.pla
find_by(subdomain: 'www')
end
Expand Down
2 changes: 0 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions app/views/admin/program_locations/create.js.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
$("#program_location_rows").append("<%= escape_javascript(render(partial: 'location_row', locals: { program_location: @program_location })) %>");
$("#program_location_location_name").val('');
<% if @program_location.valid? %>
$("#program_location_rows").append("<%= escape_javascript(render(partial: 'location_row', locals: { program_location: @program_location })) %>");
$("#program_location_location_name").val('');
<% end %>
2 changes: 1 addition & 1 deletion app/views/admin/programs/_program_locations_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class='form-row'>
<fieldset>
<div class='inline-form'>
<%= f.text_field :location_name %>
<%= f.text_field :location_name, required: true %>
<%= f.submit "Add", id: "addLocation" %>
<%= f.hidden_field :program_id, :value => @program.id %>
</div>
Expand Down
12 changes: 7 additions & 5 deletions app/views/shared/_users_table.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<table class="users-table">
<colgroup>
<col span="1" style="width: 40%;">
<col span="1" style="width: 40%;">
<col span="1" style="width: 20%;">
</colgroup>

<tr>
<th>Name</th>
<th><%= t('login_signup.email') %></th>
<th>Language</th>
<th>User Role</th>
</tr>
<% users.each do |user| %>
Expand All @@ -13,12 +18,9 @@
<td>
<%= user.email %>
</td>
<td>
<%= user.preferred_language %>
</td>
<td>
<% 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 %>
Expand Down
2 changes: 2 additions & 0 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Rails.application.configure do
config.active_record.dump_schema_after_migration = false

config.force_ssl = true

# Disable serving static files from the `/public` folder by default since
Expand Down
11 changes: 11 additions & 0 deletions spec/models/organization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8c0b695

Please sign in to comment.