summaryrefslogtreecommitdiff
path: root/users
diff options
context:
space:
mode:
authorjessib <jessib@leap.se>2013-01-17 11:28:27 -0800
committerjessib <jessib@leap.se>2013-01-17 11:28:27 -0800
commita4105f068e6f8ce89fbba475048f2a1e02e0fcbc (patch)
tree91353015c71c5e2b73c416f1b6974423c1298632 /users
parentdc16c6f8e5382f9e5470eb2a40081d41f4112437 (diff)
parent6347fdbe0d932e78dfa8259bf81355edb19508e9 (diff)
Merge branch 'master' into feature/tickets_controllers_simplification
Conflicts: users/app/controllers/users_controller.rb
Diffstat (limited to 'users')
-rw-r--r--users/app/controllers/users_controller.rb3
-rw-r--r--users/app/helpers/users_helper.rb6
-rw-r--r--users/app/models/user.rb4
-rw-r--r--users/app/views/emails/_email.html.haml5
-rw-r--r--users/app/views/users/_user.html.haml2
-rw-r--r--users/app/views/users/show.html.haml31
-rw-r--r--users/config/locales/en.yml1
-rw-r--r--users/test/functional/users_controller_test.rb51
8 files changed, 99 insertions, 4 deletions
diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb
index b705f47..a8ba1ab 100644
--- a/users/app/controllers/users_controller.rb
+++ b/users/app/controllers/users_controller.rb
@@ -2,8 +2,9 @@ class UsersController < ApplicationController
skip_before_filter :verify_authenticity_token, :only => [:create]
+
before_filter :authorize
- before_filter :fetch_user, :only => [:edit, :update, :destroy]
+ before_filter :fetch_user, :only => [:show, :edit, :update, :destroy]
before_filter :set_anchor, :only => [:edit, :update]
before_filter :authorize_admin, :only => [:index]
diff --git a/users/app/helpers/users_helper.rb b/users/app/helpers/users_helper.rb
index 45ca0e9..5f68085 100644
--- a/users/app/helpers/users_helper.rb
+++ b/users/app/helpers/users_helper.rb
@@ -30,4 +30,10 @@ module UsersHelper
classes.compact
end
+ def user_field(field)
+ value = @user.send(field)
+ value = value.to_s(:long) if field.end_with? '_at'
+ value || 'not set'
+ end
+
end
diff --git a/users/app/models/user.rb b/users/app/models/user.rb
index f20c6ac..1e8ee0e 100644
--- a/users/app/models/user.rb
+++ b/users/app/models/user.rb
@@ -94,6 +94,10 @@ class User < CouchRest::Model::Base
email_aliases.build(attrs.values.first) if attrs
end
+ def most_recent_tickets(count=3)
+ Ticket.for_user(self).limit(count).all #defaults to having most recent updated first
+ end
+
protected
##
diff --git a/users/app/views/emails/_email.html.haml b/users/app/views/emails/_email.html.haml
index 3feb6f0..948d847 100644
--- a/users/app/views/emails/_email.html.haml
+++ b/users/app/views/emails/_email.html.haml
@@ -1,6 +1,7 @@
- if email.valid?
%li.pull-right
%code= email
- = link_to(user_email_alias_path(@user, email), :method => :delete) do
- %i.icon-remove
+ - if params[:action] == 'edit'
+ = link_to(user_email_alias_path(@user, email), :method => :delete) do
+ %i.icon-remove
.clearfix
diff --git a/users/app/views/users/_user.html.haml b/users/app/views/users/_user.html.haml
index 7db0041..ca03d34 100644
--- a/users/app/views/users/_user.html.haml
+++ b/users/app/views/users/_user.html.haml
@@ -1,5 +1,5 @@
%tr
- %td= user.login
+ %td= link_to user.login, user
%td= time_ago_in_words(user.created_at) + " ago"
%td
= link_to edit_user_path(user), :class => "btn btn-mini btn-primary" do
diff --git a/users/app/views/users/show.html.haml b/users/app/views/users/show.html.haml
new file mode 100644
index 0000000..a1eeccb
--- /dev/null
+++ b/users/app/views/users/show.html.haml
@@ -0,0 +1,31 @@
+.span8.offset1
+ %h2= @user.login
+ .small
+ = link_to 'edit', edit_user_path(@user)
+ %dl.offset1
+ - fields = ['login', 'email', 'created_at', 'updated_at', 'email_forward']
+ - fields.each do |field|
+ %dt
+ = field.titleize
+ %dd
+ = user_field(field)
+ %dt
+ =t :email_aliases
+ %dd
+ - aliases = @user.email_aliases
+ - if aliases.present?
+ %ul.pull-left.unstyled
+ = render aliases
+ - else
+ =t :none
+ .clearfix
+ %dt
+ =t :most_recently_updated_tickets
+ %dd
+ - tix = @user.most_recent_tickets
+ - if tix.present?
+ %table
+ %tbody
+ = render @user.most_recent_tickets
+ - else
+ =t :none \ No newline at end of file
diff --git a/users/config/locales/en.yml b/users/config/locales/en.yml
index 3c71e7e..7a6ab90 100644
--- a/users/config/locales/en.yml
+++ b/users/config/locales/en.yml
@@ -1,4 +1,5 @@
en:
+ none: "None."
signup: "Sign up"
signup_message: "Please create an account."
cancel: "Cancel"
diff --git a/users/test/functional/users_controller_test.rb b/users/test/functional/users_controller_test.rb
index 8f1ee15..46db4d1 100644
--- a/users/test/functional/users_controller_test.rb
+++ b/users/test/functional/users_controller_test.rb
@@ -9,13 +9,64 @@ class UsersControllerTest < ActionController::TestCase
assert_response :success
end
+ test "failed show without login" do
+ user = find_record :user
+ get :show, :id => user.id
+ assert_response :redirect
+ assert_redirected_to login_path
+ end
+
+ test "user can see user" do
+ user = find_record :user,
+ :email => nil,
+ :email_forward => nil,
+ :email_aliases => [],
+ :created_at => Time.now,
+ :updated_at => Time.now,
+ :most_recent_tickets => []
+ login user
+ get :show, :id => user.id
+ assert_response :success
+ end
+
+ test "admin can see other user" do
+ user = find_record :user,
+ :email => nil,
+ :email_forward => nil,
+ :email_aliases => [],
+ :created_at => Time.now,
+ :updated_at => Time.now,
+ :most_recent_tickets => []
+ login :is_admin? => true
+ get :show, :id => user.id
+ assert_response :success
+
+ end
+
+ test "user cannot see other user" do
+ user = find_record :user,
+ :email => nil,
+ :email_forward => nil,
+ :email_aliases => [],
+ :created_at => Time.now,
+ :updated_at => Time.now,
+ :most_recent_tickets => []
+ login
+ get :show, :id => user.id
+ assert_response :redirect
+ assert_access_denied
+ end
+
+
test "should create new user" do
user_attribs = record_attributes_for :user
user = User.new(user_attribs)
User.expects(:create).with(user_attribs).returns(user)
+
post :create, :user => user_attribs, :format => :json
+
assert_nil session[:user_id]
assert_json_response user
assert_response :success