From 2599c7bac06ee55d58e492a47e09ee163e9582ba Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 8 Jan 2013 13:20:34 -0800 Subject: Adding show view for users. --- users/app/controllers/users_controller.rb | 2 +- users/app/helpers/users_helper.rb | 6 ++++++ users/app/models/user.rb | 4 ++++ users/app/views/users/_user.html.haml | 2 +- users/app/views/users/show.html.haml | 32 +++++++++++++++++++++++++++++++ 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 users/app/views/users/show.html.haml (limited to 'users/app') diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index 79de630..eb93fcb 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -2,7 +2,7 @@ class UsersController < ApplicationController skip_before_filter :verify_authenticity_token, :only => [:create] - 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 1798ea4..4b6b06c 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -100,6 +100,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) #defaults to having most recent updated first + end + protected ## 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..9df029e --- /dev/null +++ b/users/app/views/users/show.html.haml @@ -0,0 +1,32 @@ +.span8.offset1 + %h2= @user.login + %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.empty? + none set + - else + %ul.unstyled + - aliases.each do |al| + %li + = al.email + %dt + =t :most_recently_updated_tickets + %dd + %ul + - @user.most_recent_tickets.each do |ticket| + %li + = link_to ticket.title, ticket + %small + updated: + = ticket.updated_at.to_s(:long) + + -- cgit v1.2.3 From 8141876126aa25d713cf4b2c76c3ecff837c4ba7 Mon Sep 17 00:00:00 2001 From: jessib Date: Mon, 14 Jan 2013 12:39:59 -0800 Subject: Use partials for displaying details shown when viewing a user. Some of these partials have specific CSS for another use, so we will likely want to tweak this. --- users/app/models/user.rb | 2 +- users/app/views/emails/_email.html.haml | 5 +++-- users/app/views/users/show.html.haml | 21 ++++++++------------- 3 files changed, 12 insertions(+), 16 deletions(-) (limited to 'users/app') diff --git a/users/app/models/user.rb b/users/app/models/user.rb index 42900ea..1e8ee0e 100644 --- a/users/app/models/user.rb +++ b/users/app/models/user.rb @@ -95,7 +95,7 @@ class User < CouchRest::Model::Base end def most_recent_tickets(count=3) - Ticket.for_user(self).limit(count) #defaults to having most recent updated first + 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/show.html.haml b/users/app/views/users/show.html.haml index 9df029e..2b59c66 100644 --- a/users/app/views/users/show.html.haml +++ b/users/app/views/users/show.html.haml @@ -1,5 +1,7 @@ .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| @@ -14,19 +16,12 @@ - if aliases.empty? none set - else - %ul.unstyled - - aliases.each do |al| - %li - = al.email + .pull-left + = render aliases + .clearfix %dt =t :most_recently_updated_tickets %dd - %ul - - @user.most_recent_tickets.each do |ticket| - %li - = link_to ticket.title, ticket - %small - updated: - = ticket.updated_at.to_s(:long) - - + %table + %tbody + = render @user.most_recent_tickets \ No newline at end of file -- cgit v1.2.3 From e7d36df945792b292732e25e879a90577050a6c1 Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 15 Jan 2013 11:06:46 +0100 Subject: minor: put emails in unstyled ul and simplify Just found out that render(@collection) returns nil for emtpy collections. So that is usefull for putting messages about the emtpy collection in an or clause. --- users/app/views/users/show.html.haml | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'users/app') diff --git a/users/app/views/users/show.html.haml b/users/app/views/users/show.html.haml index 2b59c66..d8b51e9 100644 --- a/users/app/views/users/show.html.haml +++ b/users/app/views/users/show.html.haml @@ -12,16 +12,12 @@ %dt =t :email_aliases %dd - - aliases = @user.email_aliases - - if aliases.empty? - none set - - else - .pull-left - = render aliases + %ul.pull-left.unstyled + = render(@user.email_aliases) || t(:none_set) .clearfix %dt =t :most_recently_updated_tickets %dd %table %tbody - = render @user.most_recent_tickets \ No newline at end of file + = render @user.most_recent_tickets -- cgit v1.2.3 From be8ee9fa669bc5554796be1fc99867fc99ba21bc Mon Sep 17 00:00:00 2001 From: Azul Date: Tue, 15 Jan 2013 11:28:37 +0100 Subject: reverted simplification - not good to have 'none set' in a %ul --- users/app/views/users/show.html.haml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'users/app') diff --git a/users/app/views/users/show.html.haml b/users/app/views/users/show.html.haml index d8b51e9..ec5cea6 100644 --- a/users/app/views/users/show.html.haml +++ b/users/app/views/users/show.html.haml @@ -12,8 +12,12 @@ %dt =t :email_aliases %dd - %ul.pull-left.unstyled - = render(@user.email_aliases) || t(:none_set) + - aliases = @user.email_aliases + - if aliases.present? + %ul.pull-left.unstyled + = render aliases + - else + =t :none_set .clearfix %dt =t :most_recently_updated_tickets -- cgit v1.2.3 From 9d53f7b2d1b34da6b6103e97bd6c931cedb23e9b Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 15 Jan 2013 11:03:02 -0800 Subject: Show different ticket characteristics when viewing the users versus when listing the tickets. Give a message if a user has no tickets. --- users/app/views/users/show.html.haml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'users/app') diff --git a/users/app/views/users/show.html.haml b/users/app/views/users/show.html.haml index ec5cea6..a1eeccb 100644 --- a/users/app/views/users/show.html.haml +++ b/users/app/views/users/show.html.haml @@ -17,11 +17,15 @@ %ul.pull-left.unstyled = render aliases - else - =t :none_set + =t :none .clearfix %dt =t :most_recently_updated_tickets %dd - %table - %tbody - = render @user.most_recent_tickets + - tix = @user.most_recent_tickets + - if tix.present? + %table + %tbody + = render @user.most_recent_tickets + - else + =t :none \ No newline at end of file -- cgit v1.2.3 From e2021bdcc40b51ab5e571c97e882bba10dc80ad6 Mon Sep 17 00:00:00 2001 From: jessib Date: Tue, 15 Jan 2013 12:52:09 -0800 Subject: For both users and tickets, if the object is not found and the current user is an admin, they should see an alert that the object wasn't found, and be redirected to the current controller. If the object isn't found and the current user is not an admin, then we will continue to give an error about no access, so as not to leak information about what IDs do and don't exist. --- users/app/controllers/users_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'users/app') diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index 79de630..3d5a6a7 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -49,6 +49,10 @@ class UsersController < ApplicationController def fetch_user @user = User.find_by_param(params[:id]) + if !@user and admin? + redirect_to users_path, :alert => t(:no_such_thing, :thing => 'user') + return + end access_denied unless admin? or (@user == current_user) end -- cgit v1.2.3 From dc16c6f8e5382f9e5470eb2a40081d41f4112437 Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 17 Jan 2013 11:25:39 -0800 Subject: Deal with corner case where we don't have authenticated user. Will write a test after merging in show view for users. --- users/app/controllers/users_controller.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'users/app') diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index 3d5a6a7..b705f47 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -2,6 +2,7 @@ class UsersController < ApplicationController skip_before_filter :verify_authenticity_token, :only => [:create] + before_filter :authorize before_filter :fetch_user, :only => [:edit, :update, :destroy] before_filter :set_anchor, :only => [:edit, :update] before_filter :authorize_admin, :only => [:index] @@ -48,6 +49,7 @@ class UsersController < ApplicationController protected def fetch_user + # authorize filter has been checked first, so won't get here unless authenticated @user = User.find_by_param(params[:id]) if !@user and admin? redirect_to users_path, :alert => t(:no_such_thing, :thing => 'user') -- cgit v1.2.3 From cce882a42cc0c139b75d932ea8ee42525e4fdb32 Mon Sep 17 00:00:00 2001 From: jessib Date: Thu, 17 Jan 2013 12:35:48 -0800 Subject: Should be able to create a user when not logged in. This isn't ready to merge, as there is an issue with logging in as an admin in the test. --- users/app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'users/app') diff --git a/users/app/controllers/users_controller.rb b/users/app/controllers/users_controller.rb index a8ba1ab..c0fe243 100644 --- a/users/app/controllers/users_controller.rb +++ b/users/app/controllers/users_controller.rb @@ -3,7 +3,7 @@ class UsersController < ApplicationController skip_before_filter :verify_authenticity_token, :only => [:create] - before_filter :authorize + before_filter :authorize, :only => [:show, :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] -- cgit v1.2.3