Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 28 additions & 42 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
class UsersController < ApplicationController

def new
if current_user.liaison?
@user = User.new
@user.project_users.build
@projects = current_user.projects
def index
if current_user.super_user?
@users = User.paginate(page: params[:page], per_page: 6)
else
flash[:alert] = 'You must be a liaison to add a new user.'
redirect_to root_path
end
end

def new
@user = User.new
@user.project_users.build
@projects = current_user.projects
end

def create
@user = User.new(user_params)
set_password
if @user.save
@user.notifications.create(notification_type: 0)
flash[:alert] = 'User has been created.'
redirect_to user_path(@user)
redirect_to users_path
else
render :new
end
Expand All @@ -29,13 +32,6 @@ def show

def edit
@user = User.find(params[:id])
if can_access_page?
@project_users = @user.project_users
render :edit
else
flash[:alert] = 'You must be a liaison to edit user information.'
redirect_to root_path
end
end

def change_password
Expand All @@ -57,21 +53,15 @@ def update_password

def update
@user = User.find(params[:id])
if can_access_page?
set_password unless password_param.empty?
set_password unless password_param.nil?

if @user.update(user_params)
@user.notifications.create(notification_type: 1)
flash[:alert] = 'User updated.'
sign_in(@user, :bypass => true)
redirect_to user_path(@user)
else
flash[:alert] = 'Unable to update user.'
render :edit
end
if @user.update(user_params)
# @user.notifications.create(notification_type: 1)
flash[:alert] = 'User updated.'
redirect_to users_path
else
flash[:alert] = 'You are not authorized to update this user.'
redirect_to root_path
flash[:alert] = 'Unable to update user.'
render :edit
end
end

Expand All @@ -81,23 +71,19 @@ def set_password
@user.password = password_param unless password_param.empty?
end

def can_access_page?
@user == current_user || current_user.liaison_in_projects?(@user.projects)
def user_params
params.require(:user).permit(
:email, :first_name, :last_name,
:phone, :phone2, :phone3, :best_time_to_call,
:birthday, :address, :city, :state, :zip, :address2,
:city2, :state2, :zip2, :primary_address, :notes, :avatar, :super_user,
project_users_attributes: [:project_id, :position, :_destroy, :id]
)
end

# def user_params
# params.require(:user).permit(
# :email, :first_name, :last_name,
# :phone, :phone2, :phone3, :best_time_to_call,
# :birthday, :address, :city, :state, :zip, :address2,
# :city2, :state2, :zip2, :primary_address, :notes, :avatar,
# project_users_attributes: [:project_id, :position, :_destroy, :id]
# )
# end

# def password_param
# params[:user][:password]
# end
def password_param
params[:user][:password]
end

def pass_params
# NOTE: Using `strong_parameters` gem
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/workshop_logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def show
@answers = @workshop_log.report_form_field_answers

if @workshop_log
if current_user.liaison? && @workshop_log.project && current_user.project_ids.include?(@workshop_log.project.id)
if @workshop_log.project && current_user.project_ids.include?(@workshop_log.project.id)
render :show
else
redirect_to root_path, error: 'You do not have permission to view this page.'
Expand Down
4 changes: 0 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ def liaison_in_projects?(projects)
(liaison_project_ids & projects.map(&:id)).any?
end

def liaison?
liaison_project_ids.count > 0
end

def project_monthly_workshop_logs(date, *windows_type)
where = windows_type.map do |wt| 'windows_type_id = ?' end

Expand Down
142 changes: 93 additions & 49 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,54 +1,98 @@
<%= form_for @user, html: { multipart: true } do |f| %>
<%= simple_form_for @user, html: { multipart: true } do |f| %>
<%= render 'shared/errors', resource: user if user.errors.any? %>
<div class="form-group">
<%= f.label :avatar, class: 'bold' %>
<%= image_tag user.avatar.url(:thumb), class: "img-rounded avatar" %>
<%= f.file_field :avatar %>
<%= f.label :email, class: 'bold' %>
<%= f.text_field :email %>
<%= f.label :password, class: 'bold' %>
<%= f.password_field :password %>
<%= f.label :first_name %>
<%= f.text_field :first_name %>
<%= f.label :last_name %>
<%= f.text_field :last_name %>
<div class="form-group">
<%= f.fields_for :project_users do |project_user_form| %>
<%= render 'project_user_fields', f: project_user_form, projects: projects, user: user %>
<% end %>
<%= link_to_add_association 'add role', f, :project_users, html_options: { locals: {projects: projects} }, class: 'smaller' %>
</div>
<%= f.label :phone, value: 'work phone' %>
<%= f.text_field :phone %>
<%= f.label :phone2, value: 'home phone' %>
<%= f.text_field :phone2 %>
<%= f.label :phone3, value: 'cell phone' %>
<%= f.text_field :phone3 %>
<%= f.label :best_time_to_call %>
<%= f.text_field :best_time_to_call %>
<div class="row">
<div class="col-md-6">
<%= f.label :avatar, class: 'bold' %>
<%= image_tag user.avatar.url(:thumb), class: "img-rounded avatar" %>
<%= f.file_field :avatar %>
</div>
<div class="col-md-6">
<%= f.input :super_user, as: :boolean %>
</div>
</div>


<div class="row">
<div class="col-md-6">
<%= f.input :email %>
</div>
<div class="col-md-6">
</div>
</div>
<div class="row">
<div class="col-md-6">
<%= f.input :first_name %>
</div>
<div class="col-md-6">
<%= f.input :last_name %>
</div>
</div>



<div class="row">
<div class="col-md-3">
<%= f.input :phone, label: 'Work phone' %>
</div>
<div class="col-md-3">
<%= f.input :phone2, label: 'Home phone' %>
</div>
<div class="col-md-3">
<%= f.input :phone3, value: 'Cell phone' %>
</div>
<div class="col-md-3">
<%= f.input :best_time_to_call %>
</div>
</div>

<div class="row">
<div class="col-md-6">
<%= f.input :primary_address, collection: [['work', 1], ['home', 2]] %>
</div>
<div class="col-md-6">

</div>
</div>

<div class="row">
<label class="bold">Work Address</label>
<%= f.label :address, value: 'street' %>
<%= f.text_field :address %>
<%= f.label :city %>
<%= f.text_field :city %>
<%= f.label :state %>
<%= f.text_field :state %>
<%= f.label :zip %>
<%= f.text_field :zip %>
<div class="col-md-3">
<%= f.input :address, value: 'Street' %>
</div>
<div class="col-md-3">
<%= f.input :city %>
</div>
<div class="col-md-3">
<%= f.input :state %>
</div>
<div class="col-md-3">
<%= f.input :zip %>
</div>
</div>


<div class="row">
<label class="bold">Home Address</label>
<%= f.label :address2, value: 'street' %>
<%= f.text_field :address2 %>
<%= f.label :city2, value: 'city' %>
<%= f.text_field :city2 %>
<%= f.label :state2, value: 'state' %>
<%= f.text_field :state2 %>
<%= f.label :zip2, value: 'zip' %>
<%= f.text_field :zip2 %>
<%= f.label :primary_address %>
<%= f.select :primary_address, [['work', 1], ['home', 2]] %>
<%= f.label :notes %>
<%= f.text_area :notes %>
<%= link_to 'Cancel', user.id ? user_path(user) : root_path, class: 'btn secondary cancel-btn' %>
<%= f.submit 'Submit' %>
<div class="col-md-3">
<%= f.input :address2, value: 'street' %>
</div>
<div class="col-md-3">
<%= f.input :city2 %>
</div>
<div class="col-md-3">
<%= f.input :state2 %>
</div>
<div class="col-md-3">
<%= f.input :zip2 %>
</div>
</div>

<div class="row">
<div class="col-md-12">
<%= f.input :notes, as: :text, input_html: { rows: 2 } %>
</div>
</div>

<%= link_to 'Cancel', users_path, class: 'btn secondary cancel-btn' %>
<%= f.submit 'Submit', class: "btn btn-success" %>
<% end %>
3 changes: 0 additions & 3 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
<div class="bc">
<%= "My Group -> Edit #{@user.name}" %>
</div>
<h2 class="normal">Edit User</h2>
<%= render 'form', user: @user, projects: @projects %>
38 changes: 38 additions & 0 deletions app/views/users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div class="col-md-12">
<h2 class="normal">Users</h2>
</div>
<div class="col-md-12">
<table class="table table-responsive table-bordered table-curved">
<thead>
<tr id="festi-table-thead-tr" class="<%= @color_class %>">
<th class="text-start text-nowrap">Participant</th>
<th class="text-center">Email</th>
<th class="text-left">Super user?</th>
<th class="text-center">Sign in<br>count</th>
<th class="text-center">Current<br>sign-in</th>
<th class="text-center">Last updated</th>
<th class="text-center">Edit</th>
</tr>
</thead>

<tbody>
<% @users.each do |user| %>
<tr>
<td class="text-start text-nowrap"><%= user.first_name %> <%= user.last_name %></td>
<td class="text-start"><%= user.email %></td>
<td class="text-center">
<span class="<%= user.super_user? ? 'glyphicon glyphicon glyphicon-record success text-success' : 'glyphicon glyphicon-circle' %>"></span>
</td>
<td class="sign-in-count text-center">
<span class="<%= "text-utility" unless user.sign_in_count > 0 %>">
<%= user.sign_in_count %>
</span>
</td>
<td class="current-sign-in" style="max-width: 3em;"><%= user.current_sign_in_at && user.current_sign_in_at.strftime('%m/%d/%y %I:%M %P') %></td>
<td class="user-updated-at text-center"><%= user.updated_at&.strftime('%m/%d/%y %I:%M %P') %></td>
<td class="text-center"><%= link_to "<span class='glyphicon glyphicon-pencil'></span>".html_safe, edit_user_path(user) %></td>
</tr>
<% end %>
</tbody>
</table>
</div>