Skip to content

Commit

Permalink
Merge 5153572 into 75d5e0d
Browse files Browse the repository at this point in the history
  • Loading branch information
jaithrik committed Nov 14, 2015
2 parents 75d5e0d + 5153572 commit 044800b
Show file tree
Hide file tree
Showing 21 changed files with 136 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ gem 'nokogiri'
gem 'omniauth-google-oauth2', '~> 0.2.6'
gem 'open-uri-cached'
gem 'paper_trail'
gem 'pg', group: :production
gem 'pg', '~> 0.11.0', group: :production
gem 'protected_attributes'
gem 'rails_12factor', group: :production
gem 'rails4-autocomplete'
Expand Down
7 changes: 5 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ GEM
activerecord (>= 3.0, < 6.0)
activesupport (>= 3.0, < 6.0)
request_store (~> 1.1)
pg (0.18.2)
pg (0.11.0)
power_assert (0.2.4)
protected_attributes (1.1.3)
activemodel (>= 4.0.1, < 5.0)
Expand Down Expand Up @@ -444,7 +444,7 @@ DEPENDENCIES
omniauth-google-oauth2 (~> 0.2.6)
open-uri-cached
paper_trail
pg
pg (~> 0.11.0)
protected_attributes
pry
pry-nav
Expand Down Expand Up @@ -476,3 +476,6 @@ DEPENDENCIES
uglifier
will_paginate
zip-zip

BUNDLED WITH
1.10.6
28 changes: 27 additions & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def new_instructor
end
end


# def create_instructor
# if params['save']
# @user = User.find_or_create_by_name params[:user][:name]
Expand All @@ -40,6 +39,9 @@ def new_instructor
# end
# end
# end
# def show
# redirect_to url_for(:controller => :users, :action => :new)
# end

def list_instructors
@users = User.
Expand All @@ -51,6 +53,7 @@ def list_instructors

def add_administrator
@user = User.new
redirect_to 'users#new'
end

def new_administrator
Expand All @@ -63,6 +66,7 @@ def save_administrator # saves newly created administrator to database

def create_administrator
save_administrator
redirect_to "users#new"
end

def list_administrators
Expand Down Expand Up @@ -93,12 +97,34 @@ def show_instructor
@role = Role.new(:id => nil, :name => '(none)')
end
end

def show_super_admin
@user = User.find(params[:id])
if @user.role_id
@role = Role.find(@user.role_id)
else
@role = Role.new(:id => nil, :name => '(none)')
end
end
def show_admin
@user = User.find(params[:id])
if @user.role_id
@role = Role.find(@user.role_id)
else
@role = Role.new(:id => nil, :name => '(none)')
end
end

def remove_instructor
User.find(params[:id]).destroy
redirect_to :action => 'list_instructors'
end

def remove_administrator
User.find(params[:id]).destroy
redirect_to :action => 'list_administrators'
end

def save_super_administrator
PgUsersController.create(Role.superadministrator.id, :admin_controller, :list_super_administrators, :new_super_administrator)
end
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/institution_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def index
:redirect_to => { :action => :list }

def list
@institutions = Institution.all
@institutions = Institution.all

end

def show
Expand All @@ -27,7 +28,7 @@ def new
end

def create
@institution = Institution.new(params[:institution])
@institution = Institution.new(:name => params[:institution][:name])
if @institution.save
flash[:success] = 'Institution was successfully created.'
redirect_to :action => 'list'
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def show

def new
@user = User.new
@rolename= Role.find_by_name(params[:role])
foreign
end

Expand All @@ -120,6 +121,7 @@ def create
end

@user = User.new(user_params)
@user.institutions_id=params[:users][:institutions_id]
# record the person who created this new user
@user.parent_id = (session[:user]).id
# set the user's timezone to its parent's
Expand Down Expand Up @@ -154,7 +156,6 @@ def edit

def update
@user = User.find params[:id]

#update username, when the user cannot be deleted
#rename occurs in 'show' page, not in 'edit' page
#eg. /users/5408?name=5408
Expand Down Expand Up @@ -205,7 +206,7 @@ def foreign
private

def user_params
params.require(:user).permit(:name, :crypted_password, :role_id, :password_salt, :fullname, :email, :parent_id, :private_by_default, :mru_directory_path, :email_on_review, :email_on_submission, :email_on_review_of_review, :is_new_user, :master_permission_granted, :handle, :leaderboard_privacy, :digital_certificate, :persistence_token, :timezonepref, :public_key, :copy_of_emails)
params.require(:user).permit(:name, :crypted_password, :role_id, :password_salt, :fullname, :email, :parent_id, :private_by_default, :mru_directory_path, :email_on_review, :email_on_submission, :email_on_review_of_review, :is_new_user, :master_permission_granted, :handle, :leaderboard_privacy, :digital_certificate, :persistence_token, :timezonepref, :public_key, :copy_of_emails,:institutions_id)
end

def get_role
Expand Down
25 changes: 10 additions & 15 deletions app/views/admin/list_administrators.html.erb
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
<h1>Administrators</h1>

<table>
<tr><th>Name</th><th>Full name</th><th>E-mail address</th><th>Parent</th></tr>
<tr><th>Name</th><th></th><th>Full name</th><th></th><th>E-mail address</th><th></th><th>Parent</th><th></th></tr>
<% for user in @users %>
<tr>
<td><%= link_to user.name, :action => 'show',
:id => user.id %></td>
<td><%= user.fullname %></td>
<td><%= user.email %></td>
<td><%= (User.find(user.parent_id)).name %></td>
<td><%= link_to user.name, :action => 'show_admin',
:id => user.id %></td><td> </td>
<td><%= user.fullname %></td><td> </td>
<td><%= user.email %></td><td> </td>
<td><%= (User.find(user.parent_id)).name %></td><td> </td>
</tr>
<% end -%>
</table>


<hr/>
<%= form_tag({:action => 'new_administrator'}, {:method => 'post'}) do %>

<br>
<%= text_field_tag('name', '', {'size' => 30}) %>
&nbsp;
<input type='submit' value='New Administrator'/>
<% end %>
<%= form_tag(new_user_path, method: :get) do %>
<%= hidden_field_tag :role, "Administrator" %>
<%= submit_tag("New Administrator")%>
<% end %>
11 changes: 4 additions & 7 deletions app/views/admin/list_instructors.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<table>
<tr><th>Name</th><th>Full Name</th><th>Email Address</th><th>Parent</th></tr>
<% for user in @users %>
<% for user in @users%>
<tr>
<td><%= link_to user.name, :action => 'show_instructor',
:id => user.id %></td>
Expand All @@ -16,10 +16,7 @@
</table>

<hr/>
<%= form_tag('new_instructor', method: :get) do %>

<br>
<%= text_field_tag('name', '', {'size' => 30}) %>
&nbsp;
<input type='submit' value='New Instructor'/>
<%= form_tag(new_user_path, method: :get) do %>
<%= hidden_field_tag :role, "Instructor" %>
<%= submit_tag("New Instructor")%>
<% end %>
7 changes: 3 additions & 4 deletions app/views/admin/list_super_administrators.html.erb
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
<h1>Super-Administrators</h1>

<table>
<tr><th>Name</th><th>Full name</th><th>E-mail address</th><th>Parent</th></tr>
<tr><th>Name</th><th>Full name</th><th>E-mail address</th></tr>
<% for user in @users %>
<tr>
<td><%= link_to user.name, :action => 'show',
<td><%= link_to user.name, :action => 'show_super_admin',
:id => user.id %></td>
<td><%= user.fullname %></td>
<td><%= user.email %></td>
<td><%= (User.find(user.parent_id)).name %></td>
</tr>
<% end -%>
</table>

<hr/>
<p><%= link_to 'New Super administrator', :action => 'new' %></p>
There can be only One Super Administrator
7 changes: 7 additions & 0 deletions app/views/admin/show_admin.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= render :partial => 'show' %>
<hr/>
<p><%= link_to 'Edit', edit_user_path(@user) %> |
<%= link_to 'Delete', {:action => 'remove_administrator', :id => @user},
:confirm => 'Delete this user?', :method => :post %> </p>

<p><%= link_to 'Back', :action => 'list_administrators' %> to Administrators list</p>
2 changes: 1 addition & 1 deletion app/views/admin/show_instructor.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
<%= link_to 'Delete', {:action => 'remove_instructor', :id => @user},
:confirm => 'Delete this user?', :method => :post %> </p>

<p><%= link_to 'Back', :action => 'list_instructors' %> to Users list</p>
<p><%= link_to 'Back', :action => 'list_instructors' %> to Instructors list</p>
5 changes: 5 additions & 0 deletions app/views/admin/show_super_admin.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= render :partial => 'show' %>
<hr/>
<p><%= link_to 'Edit', edit_user_path(@user) %>

<p><%= link_to 'Back', :action => 'list_super_administrators' %> to Super Administrators list</p>
2 changes: 2 additions & 0 deletions app/views/users/_institutions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p><label for="user_institutions">Institution</label><br/>
<%= collection_select('users',:institutions_id, Institution.all, :id, :name) %></p>
1 change: 1 addition & 0 deletions app/views/users/_user.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<%= render :partial => 'users/email' %>
<%= render :partial => 'users/password', :locals => { :new_user => new_user } %>
<%= render :partial => 'users/prefs' %>
<%= render :partial => 'users/institutions' %>
<!--[eoform:user]-->
<br/>
2 changes: 1 addition & 1 deletion app/views/users/list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
session[:return_to] = "#{request.protocol}#{request.host_with_port}#{request.fullpath}"
%>
<%= link_to 'New User', :action => 'new' %> |
<%= link_to 'New User',:role => "Student", :action => 'new' %> |
<%= link_to 'Import Users', :controller=>'import_file', :action=>'start', :model => 'User', :expected_fields => 'username, full name (first[ middle] last), e-mail address' %>|
<%= link_to 'Export Users', :controller=>'export_file',:action=>'start',:model=> 'User',:id=> 1 %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/users/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<%= form_tag :action => 'create' do %>
<p><label for="role_id">Role</label><br/>
<%= collection_select 'user', 'role_id', @all_roles, :id, :name %></p>
<%= collection_select 'user', 'role_id', @all_roles, :id, :name, {:selected => @rolename.id} %></p>

<%= render :partial => 'user', :locals => { :new_user => true } %>
<%= submit_tag "Create" %>
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions db/migrate/20151018114752_add_institution_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddInstitutionToUsers < ActiveRecord::Migration
def change
add_column :users, :institutions_id, :integer
end
end
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,7 @@
t.string "timezonepref", limit: 255
t.text "public_key", limit: 65535
t.boolean "copy_of_emails", limit: 1, default: false
t.integer "institutions_id", limit: 4
end

add_index "users", ["role_id"], name: "fk_user_role_id", using: :btree
Expand Down
19 changes: 19 additions & 0 deletions spec/admin_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'spec_helper'
require 'rails_helper'

describe 'admin_controller' do
let (:user){User.new(:id => 2, :name => 'admin1')}

it 'has id 2' do
user.id.should eql (2)
end
it 'is named admin1' do
user.name.should eql ('admin1')
end

it 'should be a new record' do
user.should be_new_record
end

end

20 changes: 20 additions & 0 deletions test/functional/admin_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'rails/all'
require 'app/controllers/admin_controller'

class AdminControllerTest < ActiveSupport::TestCase


test 'should redirect to new administrator page' do
get :new_administrator
assert_redirected_to :controller => :users, :action => :new
end

test 'should create new admin' do
get :new_administrator
@admin = PgUsersController.new(:id => 2, :name => "admin1", :role_id => 5)
@admin.save
assert_response
end

end

17 changes: 17 additions & 0 deletions test/functional/users_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require File.dirname(__FILE__) + '/../test_helper'

require 'user_controller'
class UserControllerTest < ActionController::TestCase


test "should save institution id" do
institutionID = institution_id.new
assert institution_id.save, 'Institution ID saved'
end

test "should create instituition id" do
assert_difference('User.count') do
post :create, admin: {institution: 'North Carolina State Univeristy'}
end

end

0 comments on commit 044800b

Please sign in to comment.