diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-11-07 15:37:14 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-12-18 14:03:49 +0000 |
commit | 17f7352a42554fb13baf43e63f116ca828553047 (patch) | |
tree | ed3c60df03cc37e9e95541cccababd0ce1fd2590 | |
parent | 7aae38fb8c0469d9db030689d2eb5e31cfaac6af (diff) |
Use RESTful routes for CRUD admin user actions
-rw-r--r-- | app/controllers/admin_censor_rule_controller.rb | 6 | ||||
-rw-r--r-- | app/controllers/admin_user_controller.rb | 32 | ||||
-rw-r--r-- | app/helpers/admin_helper.rb | 2 | ||||
-rwxr-xr-x | app/helpers/link_to_helper.rb | 4 | ||||
-rw-r--r-- | app/views/admin_general/_admin_navbar.html.erb | 2 | ||||
-rw-r--r-- | app/views/admin_user/_user_table.html.erb | 2 | ||||
-rw-r--r-- | app/views/admin_user/edit.html.erb | 6 | ||||
-rw-r--r-- | app/views/admin_user/index.html.erb (renamed from app/views/admin_user/list.html.erb) | 0 | ||||
-rw-r--r-- | app/views/admin_user/list_banned.html.erb | 2 | ||||
-rw-r--r-- | app/views/admin_user/show.html.erb | 2 | ||||
-rw-r--r-- | app/views/user/show.html.erb | 2 | ||||
-rw-r--r-- | config/routes.rb | 10 | ||||
-rw-r--r-- | spec/controllers/admin_user_controller_spec.rb | 10 |
13 files changed, 38 insertions, 42 deletions
diff --git a/app/controllers/admin_censor_rule_controller.rb b/app/controllers/admin_censor_rule_controller.rb index dd0af002d..01c0bf4b2 100644 --- a/app/controllers/admin_censor_rule_controller.rb +++ b/app/controllers/admin_censor_rule_controller.rb @@ -54,7 +54,7 @@ class AdminCensorRuleController < AdminController if !@censor_rule.info_request.nil? redirect_to admin_request_url(@censor_rule.info_request) elsif !@censor_rule.user.nil? - redirect_to admin_user_show_url(@censor_rule.user) + redirect_to admin_user_url(@censor_rule.user) else raise "internal error" end @@ -85,7 +85,7 @@ class AdminCensorRuleController < AdminController if !@censor_rule.info_request.nil? redirect_to admin_request_url(@censor_rule.info_request) elsif !@censor_rule.user.nil? - redirect_to admin_user_show_url(@censor_rule.user) + redirect_to admin_user_url(@censor_rule.user) else raise "internal error" end @@ -114,7 +114,7 @@ class AdminCensorRuleController < AdminController if !info_request.nil? redirect_to admin_request_url(info_request) elsif !user.nil? - redirect_to admin_user_show_url(user) + redirect_to admin_user_url(user) else raise "internal error" end diff --git a/app/controllers/admin_user_controller.rb b/app/controllers/admin_user_controller.rb index a6438e151..3379b9629 100644 --- a/app/controllers/admin_user_controller.rb +++ b/app/controllers/admin_user_controller.rb @@ -5,12 +5,8 @@ # Email: hello@mysociety.org; WWW: http://www.mysociety.org/ class AdminUserController < AdminController - def index - list - render :action => 'list' - end - def list + def index @query = params[:query] if @query users = User.where(["lower(name) like lower('%'||?||'%') or @@ -21,20 +17,11 @@ class AdminUserController < AdminController @admin_users = users.paginate :order => "name", :page => params[:page], :per_page => 100 end - def list_banned - @banned_users = User.paginate :order => "name", :page => params[:page], :per_page => 100, - :conditions => ["ban_text <> ''"] - end - def show # Don't use @user as that is any logged in user @admin_user = User.find(params[:id]) end - def show_bounce_message - @admin_user = User.find(params[:id]) - end - def edit @admin_user = User.find(params[:id]) end @@ -53,17 +40,26 @@ class AdminUserController < AdminController if @admin_user.valid? @admin_user.save! flash[:notice] = 'User successfully updated.' - redirect_to admin_user_show_url(@admin_user) + redirect_to admin_user_url(@admin_user) else render :action => 'edit' end end + def list_banned + @banned_users = User.paginate :order => "name", :page => params[:page], :per_page => 100, + :conditions => ["ban_text <> ''"] + end + + def show_bounce_message + @admin_user = User.find(params[:id]) + end + def destroy_track track_thing = TrackThing.find(params[:track_id].to_i) track_thing.destroy flash[:notice] = 'Track destroyed' - redirect_to admin_user_show_url(track_thing.tracking_user) + redirect_to admin_user_url(track_thing.tracking_user) end def clear_bounce @@ -71,7 +67,7 @@ class AdminUserController < AdminController user.email_bounced_at = nil user.email_bounce_message = "" user.save! - redirect_to admin_user_show_url(user) + redirect_to admin_user_url(user) end def login_as @@ -96,7 +92,7 @@ class AdminUserController < AdminController end flash[:notice] = "Profile photo cleared" - redirect_to admin_user_show_url(@admin_user) + redirect_to admin_user_url(@admin_user) end def modify_comment_visibility diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 38743b1fa..d13fea79b 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -31,7 +31,7 @@ module AdminHelper def user_both_links(user) link_to(eye, user_path(user), :title => "view user's page on public website") + " " + - link_to(h(user.name), admin_user_show_path(user), :title => "view full details") + link_to(h(user.name), admin_user_path(user), :title => "view full details") end def comment_visibility(comment) diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index 3709469cf..44d6c6f5f 100755 --- a/app/helpers/link_to_helper.rb +++ b/app/helpers/link_to_helper.rb @@ -116,7 +116,7 @@ module LinkToHelper if request.is_external? external_text || (request.external_user_name || _("Anonymous user")) + " (external)" else - link_to(internal_text || request.user.name, admin_user_show_url(request.user)) + link_to(internal_text || request.user.name, admin_user_url(request.user)) end end @@ -178,7 +178,7 @@ module LinkToHelper end def user_admin_link(user, name="admin", cls=nil) - link_to name, admin_user_show_url(user), :class => cls + link_to name, admin_user_url(user), :class => cls end # Tracks. feed can be 'track' or 'feed' diff --git a/app/views/admin_general/_admin_navbar.html.erb b/app/views/admin_general/_admin_navbar.html.erb index b6196815a..5dab81e7d 100644 --- a/app/views/admin_general/_admin_navbar.html.erb +++ b/app/views/admin_general/_admin_navbar.html.erb @@ -12,7 +12,7 @@ <li><%= link_to 'Authorities', admin_bodies_path %></li> <li><%= link_to 'Categories', admin_categories_path %></li> <li><%= link_to 'Requests', admin_requests_path %></li> - <li><%= link_to 'Users', admin_user_list_path %></li> + <li><%= link_to 'Users', admin_users_path %></li> <li><%= link_to 'Tracks', admin_track_list_path %></li> <li><%= link_to 'Log out', signout_path %></li> </ul> diff --git a/app/views/admin_user/_user_table.html.erb b/app/views/admin_user/_user_table.html.erb index 57066bf3f..4fd90d5c6 100644 --- a/app/views/admin_user/_user_table.html.erb +++ b/app/views/admin_user/_user_table.html.erb @@ -7,7 +7,7 @@ <% if user.admin_level == "super" %> <span class="label">superuser</span> <% end %> - <%= link_to("#{h(user.name)}", admin_user_show_path(user))%> + <%= link_to("#{h(user.name)}", admin_user_path(user))%> <%= link_to("(#{h(user.email)})", "mailto:#{h(user.email)}")%> </span> <span class="item-metadata"> diff --git a/app/views/admin_user/edit.html.erb b/app/views/admin_user/edit.html.erb index e641a13d6..ed1fb6e08 100644 --- a/app/views/admin_user/edit.html.erb +++ b/app/views/admin_user/edit.html.erb @@ -1,11 +1,11 @@ <h1><%=@title%></h1> -<%= form_tag admin_user_update_path(@admin_user), :class => "form form-horizontal" do %> +<%= form_tag admin_user_path(@admin_user), :method => 'put', :class => "form form-horizontal" do %> <%= render :partial => 'form' %> <div class="form-actions"> <%= submit_tag 'Save', :accesskey => 's', :class => "btn btn-primary" %> </div> <% end %> -<%= link_to 'Show', admin_user_show_path(@admin_user), :class => "btn" %> -<%= link_to 'List all', admin_user_list_path, :class => "btn" %> +<%= link_to 'Show', admin_user_path(@admin_user), :class => "btn" %> +<%= link_to 'List all', admin_users_path, :class => "btn" %> diff --git a/app/views/admin_user/list.html.erb b/app/views/admin_user/index.html.erb index b1238f87a..b1238f87a 100644 --- a/app/views/admin_user/list.html.erb +++ b/app/views/admin_user/index.html.erb diff --git a/app/views/admin_user/list_banned.html.erb b/app/views/admin_user/list_banned.html.erb index e535415e6..ee17d9899 100644 --- a/app/views/admin_user/list_banned.html.erb +++ b/app/views/admin_user/list_banned.html.erb @@ -2,7 +2,7 @@ <h1><%=@title%></h1> -<p><%= link_to 'List all', admin_user_list_path %></p> +<p><%= link_to 'List all', admin_users_path %></p> <%= render :partial => 'user_table', :locals => { :users => @banned_users, :banned_column => true } %> diff --git a/app/views/admin_user/show.html.erb b/app/views/admin_user/show.html.erb index 6d12aeff5..2963a4100 100644 --- a/app/views/admin_user/show.html.erb +++ b/app/views/admin_user/show.html.erb @@ -49,7 +49,7 @@ </table> -<%= link_to 'Edit', admin_user_edit_path(@admin_user), :class => "btn btn-primary" %> +<%= link_to 'Edit', edit_admin_user_path(@admin_user), :class => "btn btn-primary" %> <%= link_to 'Public page', user_path(@admin_user), :class => "btn" %> <%= link_to "Log in as #{@admin_user.name} (also confirms their email)", admin_user_login_as_path(@admin_user), :class => "btn btn-info" %> diff --git a/app/views/user/show.html.erb b/app/views/user/show.html.erb index b23f74326..51882b8ef 100644 --- a/app/views/user/show.html.erb +++ b/app/views/user/show.html.erb @@ -66,7 +66,7 @@ <p class="subtitle"> <%= _('Joined {{site_name}} in', :site_name=>site_name) %> <%= @display_user.created_at.year %> <% if !@user.nil? && @user.admin_page_links? %> - (<%= link_to "admin", admin_user_show_path(@display_user) %>) + (<%= link_to "admin", admin_user_path(@display_user) %>) <% end %> </p> diff --git a/config/routes.rb b/config/routes.rb index 8f3087d17..7fc996e99 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -270,13 +270,13 @@ Alaveteli::Application.routes.draw do #### #### AdminUser controller - match '/admin/user' => 'admin_user#index', :as => :admin_user_index - match '/admin/user/list' => 'admin_user#list', :as => :admin_user_list + scope '/admin', :as => 'admin' do + resources :users, + :controller => 'admin_user', + :except => [:new, :create, :destroy] + end match '/admin/user/banned' => 'admin_user#list_banned', :as => :admin_user_list_banned - match '/admin/user/show/:id' => 'admin_user#show', :as => :admin_user_show - match '/admin/user/edit/:id' => 'admin_user#edit', :as => :admin_user_edit match '/admin/user/show_bounce_message/:id' => 'admin_user#show_bounce_message', :as => :admin_user_show_bounce - match '/admin/user/update/:id' => 'admin_user#update', :as => :admin_user_update match '/admin/user/clear_bounce/:id' => 'admin_user#clear_bounce', :as => :admin_user_clear_bounce match '/admin/user/destroy_track' => 'admin_user#destroy_track', :as => :admin_user_destroy_track match '/admin/user/login_as/:id' => 'admin_user#login_as', :as => :admin_user_login_as diff --git a/spec/controllers/admin_user_controller_spec.rb b/spec/controllers/admin_user_controller_spec.rb index 8b89506f9..e979355cf 100644 --- a/spec/controllers/admin_user_controller_spec.rb +++ b/spec/controllers/admin_user_controller_spec.rb @@ -2,13 +2,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') describe AdminUserController, "when administering users" do render_views - - it "shows the index/list page" do + + it "shows the index page" do get :index end it "searches for 'bob'" do - get :list, :query => "bob" + get :index, :query => "bob" assigns[:admin_users].should == [ users(:bob_smith_user) ] end @@ -51,7 +51,7 @@ describe AdminUserController do before(:each) do @user = FactoryGirl.create(:user) - request.env["HTTP_REFERER"] = admin_user_show_path(@user) + request.env["HTTP_REFERER"] = admin_user_path(@user) end it 'redirects to the page the admin was previously on' do @@ -61,7 +61,7 @@ describe AdminUserController do :comment_ids => comment.id, :hide_selected => 'hidden' } - response.should redirect_to(admin_user_show_path(@user)) + response.should redirect_to(admin_user_path(@user)) end it 'sets the given comments visibility to hidden' do |