|
From: | noreply |
Subject: | [myexperiment-hackers] [3021] trunk: initial user management page |
Date: | Mon, 11 Jun 2012 10:57:39 +0000 (UTC) |
initial user management page
--- trunk/app/controllers/application_controller.rb 2012-06-11 10:21:54 UTC (rev 3020)
+++ trunk/app/controllers/application_controller.rb 2012-06-11 10:57:39 UTC (rev 3021)
@@ -20,9 +20,16 @@
include AuthenticatedSystem
before_filter :login_from_cookie
before_filter :oauth_required
+ before_filter :check_for_sleeper
include ActionView::Helpers::NumberHelper
+ def check_for_sleeper
+ if current_user.account_status == "sleep"
+ current_user.update_attribute(:account_status, "recheck")
+ end
+ end
+
def base_host
request.host_with_port
end
--- trunk/app/controllers/users_controller.rb 2012-06-11 10:21:54 UTC (rev 3020)
+++ trunk/app/controllers/users_controller.rb 2012-06-11 10:57:39 UTC (rev 3021)
@@ -549,7 +549,143 @@
end
end
end
-
+
+ def check
+
+ def add(strings, opts = {})
+ if opts[:string] && opts[:string] != ""
+
+ label = opts[:label]
+ label = self.class.helpers.link_to(label, opts[:link]) if opts[:link]
+
+ strings << { :label => label, :string => opts[:string], :escape => opts[:escape] }
+ end
+ end
+
+ unless logged_in? && Conf.admins.include?(current_user.username)
+ render :text => "Not authorised"
+ return
+ end
+
+ @from = params[:from].to_i
+ @to = params[:to].to_i
+
+ if @to > 0
+
+ users = User.find(:all, :conditions => ["activated_at IS NOT NULL AND id >= ? AND id <= ? AND (account_status IS NULL OR (account_status != 'sleep' AND account_status != 'whitelist'))", @from, @to])
+
+ @userlist = users.map do |user|
+
+ strings = []
+
+ add(strings, :label => "email", :string => user.email)
+ add(strings, :label => "openid", :string => user.openid_url)
+ add(strings, :label => "created at", :string => user.created_at)
+ add(strings, :label => "last login", :string => user.last_seen_at ? user.last_seen_at : "never logged back in")
+ add(strings, :label => "name", :string => user.name)
+ add(strings, :label => "public email", :string => user.profile.email)
+ add(strings, :label => "website", :string => user.profile.website)
+ add(strings, :label => "description", :string => user.profile.body_html, :escape => :false)
+ add(strings, :label => "field / ind", :string => user.profile.field_or_industry)
+ add(strings, :label => "occ / roles", :string => user.profile.occupation_or_roles)
+ add(strings, :label => "city", :string => user.profile.location_city)
+ add(strings, :label => "country", :string => user.profile.location_country)
+ add(strings, :label => "interests", :string => user.profile.interests)
+ add(strings, :label => "contact", :string => user.profile.contact_details)
+ add(strings, :label => "tags", :string => user.tags.map do |tag| tag.name end.join(", "))
+
+ user.networks_owned.each do |network|
+
+ add(strings, :label => "group title",
+ :link => polymorphic_path(network),
+ :string => network.title)
+
+ add(strings, :label => "group description",
+ :link => polymorphic_path(network),
+ :string => network.description_html,
+ :escape => :false)
+ end
+
+ user.packs.each do |pack|
+
+ add(strings, :label => "pack title",
+ :link => polymorphic_path(pack),
+ :string => pack.title)
+
+ add(strings, :label => "pack description",
+ :link => polymorphic_path(pack),
+ :string => pack.description_html,
+ :escape => :false)
+ end
+
+ user.workflows.each do |workflow|
+
+ add(strings, :label => "workflow title",
+ :link => polymorphic_path(workflow),
+ :string => workflow.title)
+
+ add(strings, :label => "workflow description",
+ :link => polymorphic_path(workflow),
+ :string => workflow.body_html,
+ :escape => :false)
+ end
+
+ user.blobs.each do |blob|
+
+ add(strings, :label => "file title",
+ :link => polymorphic_path(blob),
+ :string => blob.title)
+
+ add(strings, :label => "file description",
+ :link => polymorphic_path(blob),
+ :string => blob.body_html,
+ :escape => :false)
+ end
+
+ user.comments.each do |comment|
+
+ add(strings, :label => "comment",
+ :link => polymorphic_path(comment.commentable),
+ :string => comment.comment,
+ :escape => :white_list)
+ end
+
+ { :ob => user, :strings => strings }
+
+ end
+ end
+ end
+
+ def change_status
+
+ unless logged_in? && Conf.admins.include?(current_user.username)
+ render :text => "Not authorised"
+ return
+ end
+
+ from = params[:from].to_i
+ to = params[:to].to_i
+
+ (from..to).each do |user_id|
+ if user = User.find_by_id(user_id)
+ case params["user-#{user_id}"]
+ when "whitelist"
+ user.update_attributes(:account_status => "whitelist")
+ when "sleep"
+ user.update_attributes(:account_status => "sleep")
+ when "delete"
+ user.destroy
+ end
+ end
+ end
+
+ respond_to do |format|
+ format.html {
+ redirect_to(url_for(:controller => "users", :action ="" "check", :from => params[:from], :to => params[:to]))
+ }
+ end
+ end
+
protected
def find_users
--- trunk/app/helpers/application_helper.rb 2012-06-11 10:21:54 UTC (rev 3020)
+++ trunk/app/helpers/application_helper.rb 2012-06-11 10:57:39 UTC (rev 3021)
@@ -775,6 +775,8 @@
return "famfamfam_silk/award_star_delete.png"
when "service"
return "biocat_icon.png"
+ when "usercheck"
+ return "famfamfam_silk/flag_red.png"
else
return Conf.label_icons[method.to_s] if Conf.label_icons[method.to_s]
end
--- trunk/app/views/gadgets/_user_monitor.rhtml 2012-06-11 10:21:54 UTC (rev 3020)
+++ trunk/app/views/gadgets/_user_monitor.rhtml 2012-06-11 10:57:39 UTC (rev 3021)
@@ -26,6 +26,7 @@
<hr/>
<ul class="gadget_list">
<li><%= icon "announcement", announcements_url, nil, nil, "Manage Announcements" %></li>
+ <li><%= icon "usercheck", "/users/check", nil, nil, "Manage Users" %></li>
</ul>
<% end %>
--- trunk/app/views/users/check.rhtml (rev 0)
+++ trunk/app/views/users/check.rhtml 2012-06-11 10:57:39 UTC (rev 3021)
@@ -0,0 +1,65 @@
+<% if (current_user && Conf.admins.include?(current_user.username)) %>
+<% end %>
+<h1>Manage Users</h1>
+
+ <div id="user-check-range">
+<form method="GET">
+ Show users from <input type="text" name="from" value="<%= @from -%>"></input>
+ to <input type="text" name="to" value="<%= @to -%>"></input>
+ <input type="submit" value="Refresh">
+</form>
+ </div>
+
+<% if @userlist %>
+ <div id="user-check-list">
+ <form method="post" action=""
+ <% @userlist.each do |user| %>
+ <div>
+ <h2><%= link_to("User: #{user[:ob].id}", user[:ob]) -%></h2>
+ <div class="user-check-buttons">
+ <% input_name = "user-#{user[:ob].id}" %>
+ <div>
+ <input name="<%= input_name -%>" id="<%= input_name -%>-1" value="nothing" type="radio" checked="checked"/>
+ <label for="" input_name -%>-1">Do nothing</label>
+ </div>
+ <div>
+ <input name="<%= input_name -%>" id="<%= input_name -%>-2" value="whitelist" type="radio"/>
+ <label for="" input_name -%>-2">White list</label>
+ </div>
+ <div>
+ <input name="<%= input_name -%>" id="<%= input_name -%>-3" value="sleep" type="radio"/>
+ <label for="" input_name -%>-3">Sleep</label>
+ </div>
+ <div>
+ <input name="<%= input_name -%>" id="<%= input_name -%>-4" value="delete" type="radio"/>
+ <label for="" input_name -%>-4">Delete</label>
+ </div>
+ </div>
+ <table class="simple">
+ <% user[:strings].each do |string| %>
+ <tr>
+ <td><%= string[:label] -%></td>
+ <td <%= 'class="ident"' if ["email", "openid"].include?(string[:label]) -%>>
+ <% if string[:escape] == :false %>
+ <%= string[:string] -%>
+ <% elsif string[:escape] == :white_list %>
+ <%= white_list(string[:string]) -%>
+ <% else %>
+ <%= h(string[:string]) -%>
+ <% end %>
+ </td>
+ </tr>
+ <% end %>
+ </table>
+ </div>
+ <% end %>
+ <input type="hidden" name="authenticity_token" value="<%= form_authenticity_token -%>"/>
+ <input type="hidden" name="from" value="<%= @from -%>"/>
+ <input type="hidden" name="to" value="<%= @to -%>"/>
+ <div id="user-check-submit">
+ <input type="submit" value="Process"/>
+ </div>
+ </form>
+ </div>
+<% end %>
+
--- trunk/config/routes.rb 2012-06-11 10:21:54 UTC (rev 3020)
+++ trunk/config/routes.rb 2012-06-11 10:57:39 UTC (rev 3021)
@@ -214,6 +214,8 @@
# all users
map.resources :users,
:collection => { :all => :get,
+ :check => :get,
+ :change_status => :post,
:search => :get,
:invite => :get } do |user|
--- trunk/db/migrate/094_add_account_status_to_users.rb (rev 0)
+++ trunk/db/migrate/094_add_account_status_to_users.rb 2012-06-11 10:57:39 UTC (rev 3021)
@@ -0,0 +1,15 @@
+# myExperiment: db/migrate/094_add_account_status_to_users.rb
+#
+# Copyright (c) 2012 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class AddAccountStatusToUsers < ActiveRecord::Migration
+ def self.up
+ add_column :users, :account_status, :string
+ end
+
+ def self.down
+ remove_column :users, :account_status
+ end
+end
+
--- trunk/public/stylesheets/styles.css 2012-06-11 10:21:54 UTC (rev 3020)
+++ trunk/public/stylesheets/styles.css 2012-06-11 10:57:39 UTC (rev 3021)
@@ -2290,3 +2290,25 @@
margin-bottom: 1.5em;
line-height: 1.4;
}
+
+.user-check-buttons {
+ border: 1px solid #CCCCCC;
+ padding: 4px;
+ margin-left: 8px;
+ float: right;
+}
+
+#user-check-list TD {
+ background: #f0f0f0;
+}
+
+#user-check-list TD.ident {
+ font-weight: bold;
+}
+
+#user-check-submit,
+#user-check-range {
+ margin: 24px;
+ text-align: center;
+}
+
[Prev in Thread] | Current Thread | [Next in Thread] |