Skip to content

Commit

Permalink
enhanced user model; added user UI support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ganley committed Mar 12, 2012
1 parent 600f708 commit c2e2277
Show file tree
Hide file tree
Showing 15 changed files with 474 additions and 29 deletions.
34 changes: 17 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
GIT
remote: http://github.com/projectcypress/health-data-standards.git
revision: 33eb427029d7eeaf144ec861d407ba6cc41eac74
revision: 4355b59545516c4cd529b3cd6748032e66456469
branch: develop
specs:
health-data-standards (0.7.2)
health-data-standards (0.8.0)
builder (~> 3.0.0)
erubis (~> 2.6)
mongoid (~> 2.4.2)
Expand Down Expand Up @@ -62,9 +62,9 @@ GEM
arel (3.0.2)
attr_required (0.0.5)
bcrypt-ruby (3.0.1)
bson (1.6.0)
bson_ext (1.6.0)
bson (= 1.6.0)
bson (1.6.1)
bson_ext (1.6.1)
bson (~> 1.6.1)
builder (3.0.0)
capistrano (2.11.2)
highline
Expand Down Expand Up @@ -96,7 +96,7 @@ GEM
eventmachine (0.12.10)
execjs (1.3.0)
multi_json (~> 1.0)
factory_girl (2.6.0)
factory_girl (2.6.1)
activesupport (>= 2.3.9)
factory_girl_rails (1.7.0)
factory_girl (~> 2.6.0)
Expand All @@ -112,7 +112,7 @@ GEM
rdoc (~> 3.8)
sax-machine (~> 0.0.20)
hashie (1.2.0)
heroku (2.20.1)
heroku (2.21.2)
launchy (>= 0.3.2)
rest-client (~> 1.6.1)
rubyzip
Expand All @@ -122,8 +122,8 @@ GEM
httpclient (2.2.4)
i18n (0.6.0)
journey (1.0.3)
jquery-rails (2.0.0)
railties (>= 3.2.0.beta, < 5.0)
jquery-rails (2.0.1)
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.6.5)
kaminari (0.13.0)
Expand All @@ -141,12 +141,12 @@ GEM
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
method_source (0.7.0)
method_source (0.7.1)
mime-types (1.17.2)
minitest (2.11.2)
mongo (1.6.0)
bson (= 1.6.0)
mongoid (2.4.5)
minitest (2.11.3)
mongo (1.6.1)
bson (~> 1.6.1)
mongoid (2.4.6)
activemodel (~> 3.1)
mongo (~> 1.3)
tzinfo (~> 0.3.22)
Expand All @@ -159,17 +159,17 @@ GEM
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
nokogiri (1.4.7)
omniauth (1.0.2)
omniauth (1.0.3)
hashie (~> 1.2)
rack
omniauth-openid (1.0.1)
omniauth (~> 1.0)
rack-openid (~> 1.3.1)
orm_adapter (0.0.6)
polyglot (0.3.3)
pry (0.9.8.2)
pry (0.9.8.4)
coderay (~> 1.0.5)
method_source (~> 0.7)
method_source (~> 0.7.1)
slop (>= 2.4.4, < 3)
pry-nav (0.1.0)
pry (~> 0.9.8.1)
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/static_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class StaticController < ApplicationController

end
112 changes: 112 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
class UsersController < ApplicationController
# GET /users
# GET /users.json
def index

@users = User.all

respond_to do |format|
format.html # index.html.erb
format.json { render json: @users }
end
end

# GET /users/1
# GET /users/1.json
def show
@user = User.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.json { render json: @user }
end
end

# GET /users/new
# GET /users/new.json
def new
@user = User.new

respond_to do |format|
format.html # new.html.erb
format.json { render json: @user }
end
end

# GET /users/1/edit
def edit
@user = User.find(params[:id])
end

# POST /users
# POST /users.json
def create
@user = User.new(params[:user])

respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render json: @user, status: :created, location: @user }
else
##puts @user.errors.inspect
format.html { render action: "new" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end

# PUT /users/1
# PUT /users/1.json
def update
@user = User.find(params[:id])

respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to @user, notice: 'User was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end

# DELETE /users/1
# DELETE /users/1.json
def destroy
@user = User.find(params[:id])
@user.destroy

respond_to do |format|
format.html { redirect_to users_url }
format.json { head :no_content }
end
end


def make_admin
@user = User.find( params[:id] ) || current_user
@user.admin = :true
@user.save

respond_to do |wants|
flash[:notice] = 'User was successfully updated.'
wants.html { redirect_to :action => "edit", :id => @user.id }
end
end

def remove_admin
@user = User.find( params[:id] ) || current_user
@user.admin = :false
@user.save
#rent_user, "ADMIN", "admin_privs_remove", ""

respond_to do |wants|
flash[:notice] = 'User was successfully updated.'
wants.html { redirect_to :action => "edit", :id => @user.id }
end
end



end
8 changes: 8 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module UsersHelper

def isAdmin?
return true if current_user.admin == :true
false
end

end
28 changes: 27 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
class User
include Mongoid::Document
include Mongoid::Symbolize

# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:oauth2_providable, :oauth2_password_grantable, :oauth2_refresh_token_grantable,
:oauth2_authorization_code_grantable

field :name
## contact information
field :street, type: String
field :city, type: String
field :state, type: String
field :zip, type: String
field :country, type: String

## role, a user can be one of these roles at at time
# PATIENT, CLINICIAN, INSURER, RECORD_ADMIN
symbolize :role, :in => {
patient: "Patient",
clinician: "Clinician",
insurer: "Insurer",
record_admin: "Record Admin"}, :default => :patient, :scopes => true

## APP admin role
symbolize :admin, :in => {
true: "True",
false: "False"}, :default => :false, :scopes => true

attr_accessible :admin, :role, :street, :city, :state, :zip, :country

## need to define name here, odd since defined below in attr_accessible
field :name

# validates_presence_of :name
validates_uniqueness_of :email, :case_sensitive => false
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
Expand Down
25 changes: 25 additions & 0 deletions app/views/static/settings.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="breadcrumb">
<%= link_to "Home", root_path( :action => "index" ) %> |
Settings
</div>

<h1>Settings</h1>

<table/>
<tr>
<td><%= link_to 'Notifications and Alerts', :controller => :notify_configs, :action => :index %></td>
</tr>

<tr>
<td> <%= link_to 'My User Info', current_user %> </td>
</tr>

<% if isAdmin? %>
<tr>
<td><%= link_to 'All Users', :controller => :users, :action => :index %></td>
</tr>
<% end %>

</table>

<br />
73 changes: 73 additions & 0 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@


<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>

<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>

<div class="field">
<%= f.label "Name" %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label "Username / email" %><br />
<%= f.text_field :email %>
</div>
<div class="field">
<%= f.label "Password" %><br />
<%= f.text_field :password %>
</div>
<div class="field">
<%= f.label :street %><br />
<%= f.text_field :street %>
</div>
<div class="field">
<%= f.label :city %><br />
<%= f.text_field :city %>
</div>
<div class="field">
<%= f.label :state %><br />
<%= f.text_field :state %>
</div>
<div class="field">
<%= f.label :zip %><br />
<%= f.text_field :zip %>
</div>
<div class="field">
<%= f.label :country %><br />
<%= f.text_field :country %>
</div>
<div class="field">
<%= f.label :role %><br />
<%= f.select :role, User.get_role_values, :prompt => 'Select...' %>
</div>
<% if isAdmin? && current_user != @user %>
<div class="field">
<%= f.label :admin %><br />
<%= f.select :admin, User.get_admin_values, :prompt => 'Select...' %>
</div>
<% else %>
<p>
<div class="field">
<b>Admin:</b>
<%= @user.admin %>
</div>
<% end %>

<p>
<div class="actions">
<%= f.submit %>
</div>
<% end %>


<p>

21 changes: 21 additions & 0 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<h1>Editing user</h1>

<%= render 'form' %>

<%= link_to 'Show', @user %>
<% if isAdmin? %>
| <%= link_to 'Back', users_path %>
<% end %>


<p>
<div class="field">
<br/>
<% if current_user == @user %>
<% if current_user.admin == :true %>
<a href="/users/<%= @user.id%>/remove_admin">Turn off Admin privs</a>
<% else %>
<a href="/users/<%= @user.id%>/make_admin">Add Admin privs</a>
<% end %>
<% end %>
</div>
Loading

0 comments on commit c2e2277

Please sign in to comment.