Diff
Modified: trunk/app/controllers/blobs_controller.rb (2421 => 2422)
--- trunk/app/controllers/blobs_controller.rb 2010-06-02 14:11:51 UTC (rev 2421)
+++ trunk/app/controllers/blobs_controller.rb 2010-06-02 23:28:31 UTC (rev 2422)
@@ -4,10 +4,9 @@
# See license.txt for details.
class BlobsController < ApplicationController
- before_filter :login_required, :except => [:index, :show, :download, :named_download, :statistics, :search, :all]
+ before_filter :login_required, :except => [:index, :show, :download, :named_download, :statistics, :search]
- before_filter :find_blobs, : [:all]
- before_filter :find_blob_auth, :except => [:search, :index, :new, :create, :all]
+ before_filter :find_blob_auth, :except => [:search, :index, :new, :create]
before_filter :initiliase_empty_objects_for_new_pages, : [:new, :create]
before_filter :set_sharing_mode_variables, : [:show, :new, :create, :edit, :update]
@@ -52,18 +51,12 @@
# GET /files
def index
+ @contributions = Contribution.contributions_list(Blob, params)
respond_to do |format|
format.html # index.rhtml
end
end
- # GET /files/all
- def all
- respond_to do |format|
- format.html # all.rhtml
- end
- end
-
# GET /files/1
def show
if allow_statistics_logging(@blob)
@@ -295,19 +288,6 @@
protected
- def find_blobs
- found = Blob.find(:all,
- :order => "updated_at DESC, created_at DESC",
- :page => { :size => 20,
- :current => params[:page] })
-
- found.each do |blob|
- blob.content_blob.data = "" unless Authorization.is_authorized?("download", nil, blob, current_user)
- end
-
- @blobs = found
- end
-
def find_blob_auth
begin
blob = Blob.find(params[:id])
Modified: trunk/app/controllers/packs_controller.rb (2421 => 2422)
--- trunk/app/controllers/packs_controller.rb 2010-06-02 14:11:51 UTC (rev 2421)
+++ trunk/app/controllers/packs_controller.rb 2010-06-02 23:28:31 UTC (rev 2422)
@@ -6,10 +6,9 @@
class PacksController < ApplicationController
include ApplicationHelper
- before_filter :login_required, :except => [:index, :show, :all, :search, :items, :download, :statistics]
+ before_filter :login_required, :except => [:index, :show, :search, :items, :download, :statistics]
- before_filter :find_packs, : [:all]
- before_filter :find_pack_auth, :except => [:index, :new, :create, :all, :search]
+ before_filter :find_pack_auth, :except => [:index, :new, :create, :search]
before_filter :set_sharing_mode_variables, : [:show, :new, :create, :edit, :update]
@@ -28,18 +27,12 @@
# GET /packs
def index
+ @contributions = Contribution.contributions_list(Pack, params)
respond_to do |format|
format.html # index.rhtml
end
end
- # GET /packs/all
- def all
- respond_to do |format|
- format.html # all.rhtml
- end
- end
-
# GET /packs/1
def show
if allow_statistics_logging(@pack)
@@ -422,13 +415,6 @@
end
end
- def find_packs
- @packs = Pack.find(:all,
- :order => "title ASC",
- :page => { :size => 20,
- :current => params[:page] })
- end
-
def find_pack_auth
begin
pack = Pack.find(params[:id])
Modified: trunk/app/controllers/workflows_controller.rb (2421 => 2422)
--- trunk/app/controllers/workflows_controller.rb 2010-06-02 14:11:51 UTC (rev 2421)
+++ trunk/app/controllers/workflows_controller.rb 2010-06-02 23:28:31 UTC (rev 2422)
@@ -4,11 +4,10 @@
# See license.txt for details.
class WorkflowsController < ApplicationController
- before_filter :login_required, :except => [:index, :show, :download, :named_download, :statistics, :launch, :search, :all]
+ before_filter :login_required, :except => [:index, :show, :download, :named_download, :statistics, :launch, :search]
- before_filter :find_workflows, : [:all]
before_filter :find_workflows_rss, : [:index]
- before_filter :find_workflow_auth, :except => [:search, :index, :new, :create, :all]
+ before_filter :find_workflow_auth, :except => [:search, :index, :new, :create]
before_filter :initiliase_empty_objects_for_new_pages, : [:new, :create, :new_version, :create_version]
before_filter :set_sharing_mode_variables, : [:show, :new, :create, :edit, :update]
@@ -17,7 +16,7 @@
before_filter :check_custom_workflow_type, : [:create, :create_version]
before_filter :check_is_owner, : [:edit, :update]
-
+
# declare sweepers and which actions should invoke them
cache_sweeper :workflow_sweeper, : [ :create, :create_version, :launch, :update, :update_version, :destroy_version, :destroy ]
cache_sweeper :download_viewing_sweeper, : [ :show, :download, :named_download, :launch ]
@@ -213,7 +212,10 @@
# GET /workflows
def index
respond_to do |format|
- format.html # index.rhtml
+ format.html do
+ @contributions = Contribution.contributions_list(Workflow, params)
+ # index.rhtml
+ end
format.rss do
address@hidden = Workflow.find(:all, :order => "updated_at DESC") # list all (if required)
render :action ="" 'index.rxml', :layout => false
@@ -221,16 +223,8 @@
end
end
- # GET /workflows/all
- def all
- respond_to do |format|
- format.html # all.rhtml
- end
- end
-
# GET /workflows/1
def show
- logger.debug("DEBUG DEBUG DEBUG")
if allow_statistics_logging(@viewing_version)
@viewing = Viewing.create(:contribution => @workflow.contribution, :user => (logged_in? ? current_user : nil), :user_agent => request.env['HTTP_USER_AGENT'], :accessed_from_site => accessed_from_website?())
end
@@ -602,19 +596,6 @@
protected
- def find_workflows
- found = Workflow.find(:all,
- construct_options.merge({:page => { :size => 20, :current => params[:page] },
- :include => [ { :contribution => :policy }, :tags, :ratings ],
- :order => "workflows.updated_at DESC" }))
-
- found.each do |workflow|
- workflow.content_blob.data = "" unless Authorization.is_authorized?('download', nil, workflow, current_user)
- end
-
- @workflows = found
- end
-
def find_workflows_rss
# Only carry out if request is for RSS
if params[:format] and params[:format].downcase == 'rss'
Modified: trunk/app/models/contribution.rb (2421 => 2422)
--- trunk/app/models/contribution.rb 2010-06-02 14:11:51 UTC (rev 2421)
+++ trunk/app/models/contribution.rb 2010-06-02 23:28:31 UTC (rev 2422)
@@ -15,7 +15,40 @@
has_many :viewings,
:order => "created_at DESC",
:dependent => :destroy
-
+
+ def self.contributions_list(klass = nil, params = nil, user = nil)
+
+ sort_options = Conf.contribution_order_options
+
+ args = sort_options.first
+
+ sort_options.each do |sort_option|
+ args = sort_option if params["order"] == sort_option["option"]
+ end
+
+ num = 10
+ offset = 0
+
+ if params["page"]
+ offset = (params["page"].to_i - 1) * num
+ end
+
+ # This uses the proprietary MySQL feature "SQL_CALC_FOUND_ROWS" to
+ # determine the total number of rows if it weren't for the LIMIT clause
+
+ results = Authorization.authorised_index(:type => klass,
+ :select => 'SQL_CALC_FOUND_ROWS contributions.*',
+ :user => user,
+ :contribution_records => true,
+ :limit => "#{offset}, #{num}",
+ :joins => args["joins"],
+ :order => args["order"])
+
+ total = ActiveRecord::Base.connection.execute("SELECT FOUND_ROWS()").fetch_row.first.to_i
+
+ PaginatedArray.new(results, :total => total, :limit => num, :offset => offset)
+ end
+
# returns the 'most downloaded' Contributions
# (only takes into account downloads, that is internal usage)
# the maximum number of results is set by #limit#
Modified: trunk/app/views/blobs/index.rhtml (2421 => 2422)
--- trunk/app/views/blobs/index.rhtml 2010-06-02 14:11:51 UTC (rev 2421)
+++ trunk/app/views/blobs/index.rhtml 2010-06-02 23:28:31 UTC (rev 2422)
@@ -7,11 +7,26 @@
<ul class="sectionIcons">
<li><%= icon "blob", new_file_path, nil, nil, "Upload New File" %></li>
- <li><%= icon "view-all", all_files_path, nil, nil, "View All Files" %></li>
</ul>
<% cache(:controller => 'files', :action ="" 'all_tags') do -%>
<%= render :partial => "blobs/all_tags" %>
<% end -%>
-<%= render :partial => "contributions/most_tabs", :locals => { :type => "Blob" } %>
+<div style="float: right; margin: 0.5em;">
+ Sort by:
+ <select = this.options[this.selectedIndex].value;">
+ <% Conf.contribution_order_options.each do |args| %>
+ <option value="?order=<%= args["option"] -%>" <% if params[:order] == args["option"] -%> selected="selected"<% end -%>><%= args["label"] -%></option>
+ <% end %>
+ </select>
+</div>
+
+<%= render :partial => "layouts/paginate", :locals => { :collection => @contributions } %>
+
+<div style="clear: right"></div>
+
+<%= render :partial => "contributions/list", :locals => { :collection => @contributions, :table => true } %>
+
+<%= render :partial => "layouts/paginate", :locals => { :collection => @contributions } %>
+
Modified: trunk/app/views/packs/index.rhtml (2421 => 2422)
--- trunk/app/views/packs/index.rhtml 2010-06-02 14:11:51 UTC (rev 2421)
+++ trunk/app/views/packs/index.rhtml 2010-06-02 23:28:31 UTC (rev 2422)
@@ -34,13 +34,20 @@
<%= render :partial => "packs/all_tags" %>
<% end -%>
-<%= render :partial => "contributions/most_tabs", :locals => { :type => "Pack" } %>
+<div style="float: right; margin: 0.5em;">
+ Sort by:
+ <select = this.options[this.selectedIndex].value;">
+ <% Conf.contribution_order_options.each do |args| %>
+ <option value="?order=<%= args["option"] -%>" <% if params[:order] == args["option"] -%> selected="selected"<% end -%>><%= args["label"] -%></option>
+ <% end %>
+ </select>
+</div>
-<% unless (largest = Pack.most_items).empty? %>
- <div class="tabContainer">
- <div class="tabTitle">Most items</div>
- <div class="tabContent">
- <%= render :partial => "packs/table", :locals => { :collection => largest } %>
- </div>
- </div>
-<% end %>
+<%= render :partial => "layouts/paginate", :locals => { :collection => @contributions } %>
+
+<div style="clear: right"></div>
+
+<%= render :partial => "contributions/list", :locals => { :collection => @contributions, :table => true } %>
+
+<%= render :partial => "layouts/paginate", :locals => { :collection => @contributions } %>
+
Modified: trunk/app/views/workflows/index.rhtml (2421 => 2422)
--- trunk/app/views/workflows/index.rhtml 2010-06-02 14:11:51 UTC (rev 2421)
+++ trunk/app/views/workflows/index.rhtml 2010-06-02 23:28:31 UTC (rev 2422)
@@ -5,13 +5,30 @@
<% end %>
</div>
+<h1><%= feed_icon_tag "Latest Workflows", formatted_workflows_path(:rss), "margin-right: 0.3em;" -%> Workflows</h1>
+
<ul class="sectionIcons">
<li><%= icon "workflow", new_workflow_path, nil, nil, "Upload New Workflow" %></li>
- <li><%= icon "view-all", all_workflows_path, nil, nil, "View All Workflows" %></li>
</ul>
<% cache(:controller => 'workflows', :action ="" 'all_tags') do -%>
<%= render :partial => "workflows/all_tags" %>
<% end -%>
-<%= render :partial => "contributions/most_tabs", :locals => { :type => "Workflow" } %>
+<div style="float: right; margin: 0.5em;">
+ Sort by:
+ <select = this.options[this.selectedIndex].value;">
+ <% Conf.contribution_order_options.each do |args| %>
+ <option value="?order=<%= args["option"] -%>" <% if params[:order] == args["option"] -%> selected="selected"<% end -%>><%= args["label"] -%></option>
+ <% end %>
+ </select>
+</div>
+
+<%= render :partial => "layouts/paginate", :locals => { :collection => @contributions } %>
+
+<div style="clear: right"></div>
+
+<%= render :partial => "contributions/list", :locals => { :collection => @contributions, :table => true } %>
+
+<%= render :partial => "layouts/paginate", :locals => { :collection => @contributions } %>
+
Modified: trunk/config/default_settings.yml (2421 => 2422)
--- trunk/config/default_settings.yml 2010-06-02 14:11:51 UTC (rev 2421)
+++ trunk/config/default_settings.yml 2010-06-02 23:28:31 UTC (rev 2422)
@@ -421,3 +421,43 @@
label_icons:
+contribution_order_options:
+
+ - option: rank
+ label: Rank
+ order: rank DESC
+
+ - option: title
+ label: Title
+ order: label, rank DESC
+
+ - option: latest
+ label: Latest
+ order: created_at DESC, rank DESC
+
+ - option: last_updated
+ label: Last updated
+ order: updated_at DESC, rank DESC
+
+ - option: rating
+ label: Community rating
+ order: rating DESC, rank DESC
+
+ - option: viewings
+ label: Most viewed
+ order: viewings_count DESC, rank DESC
+
+ - option: downloads
+ label: Most downloaded
+ order: downloads_count DESC, rank DESC
+
+ - option: type
+ label: Type
+ joins: LEFT OUTER JOIN content_types ON contributions.content_type_id = content_types.id
+ order: content_types.title, rank DESC
+
+ - option: licence
+ label: Licence
+ joins: LEFT OUTER JOIN licenses ON contributions.license_id = licenses.id
+ order: licenses.title, rank DESC
+
Modified: trunk/config/routes.rb (2421 => 2422)
--- trunk/config/routes.rb 2010-06-02 14:11:51 UTC (rev 2421)
+++ trunk/config/routes.rb 2010-06-02 23:28:31 UTC (rev 2422)
@@ -40,7 +40,7 @@
# packs
map.resources :packs,
- :collection => { :all => :get, :search => :get },
+ :collection => { :search => :get },
:member => { :comment => :post,
:comment_delete => :delete,
:statistics => :get,
@@ -62,7 +62,7 @@
# workflows (downloadable)
map.resources :workflows,
- :collection => { :all => :get, :search => :get },
+ :collection => { :search => :get },
:member => { :new_version => :get,
:download => :get,
:launch => :get,
@@ -102,7 +102,7 @@
# files (downloadable)
map.resources :files,
:controller => :blobs,
- :collection => { :all => :get, :search => :get },
+ :collection => { :search => :get },
:member => { :download => :get,
:statistics => :get,
:favourite => :post,
Modified: trunk/lib/authorization.rb (2421 => 2422)
--- trunk/lib/authorization.rb 2010-06-02 14:11:51 UTC (rev 2421)
+++ trunk/lib/authorization.rb 2010-06-02 23:28:31 UTC (rev 2422)
@@ -458,9 +458,9 @@
def Authorization.categorize_action(action_name)
case action_name
- when 'show', 'index', 'view', 'search', 'favourite', 'favourite_delete', 'comment', 'comment_delete', 'comments', 'comments_timeline', 'rate', 'tag', 'items', 'statistics', 'curation', 'tag_suggestions', 'read', 'verify'
+ when 'show', 'index', 'view', 'search', 'favourite', 'favourite_delete', 'comment', 'comment_delete', 'comments', 'comments_timeline', 'rate', 'tag', 'items', 'statistics', 'curation', 'tag_suggestions', 'extra_metadata', 'read', 'verify'
action = ''
- when 'edit', 'new', 'create', 'update', 'new_version', 'create_version', 'destroy_version', 'edit_version', 'update_version', 'new_item', 'create_item', 'edit_item', 'update_item', 'quick_add', 'resolve_link', 'process_tag_suggestions'
+ when 'edit', 'new', 'create', 'update', 'new_version', 'create_version', 'destroy_version', 'edit_version', 'update_version', 'new_item', 'create_item', 'edit_item', 'update_item', 'quick_add', 'resolve_link', 'process_tag_suggestions', 'process_extra_metadata'
action = ''
when 'download', 'named_download', 'launch', 'submit_job', 'save_inputs', 'refresh_status', 'rerun', 'refresh_outputs', 'render_output', 'outputs_xml', 'outputs_package'
action = ''
@@ -749,7 +749,7 @@
"((contributions.contributor_type = 'User' AND contributions.contributor_id = #{user_id}) OR
(share_mode = 0 OR share_mode = 1 OR share_mode = 2) OR
- ((share_mode = 3 OR share_mode = 4 OR update_mode = 1) AND
+ ((share_mode = 1 OR share_mode = 3 OR share_mode = 4 OR update_mode = 1 OR (update_mode = 0 AND (share_mode = 1 OR share_mode = 3))) AND
(contributions.contributor_type = 'User' AND contributions.contributor_id IN #{friends})))"
end
@@ -759,7 +759,7 @@
"((contributions.contributor_type = 'User' AND contributions.contributor_id = #{user_id}) OR
(share_mode = 0) OR
- ((share_mode = 1 OR share_mode = 3 OR update_mode = 1) AND
+ ((share_mode = 1 OR share_mode = 3 OR update_mode = 1 OR (update_mode = 0 AND (share_mode = 1 OR share_mode = 3))) AND
(contributions.contributor_type = 'User' AND contributions.contributor_id IN #{friends})))"
end
@@ -773,14 +773,28 @@
(contributions.contributor_type = 'User' AND contributions.contributor_id IN #{friends})))"
end
- def self.permission_part(permission, user_id, networks)
- "(permissions.id IS NOT NULL AND permissions.#{permission} = true AND
+ def self.permission_part(permissions, user_id, networks)
+
+ permission_test = permissions.map do |p| "permissions.#{p} = true" end.join(" OR ")
+
+ "(permissions.id IS NOT NULL AND (#{permission_test}) AND
((permissions.contributor_type = 'User' AND permissions.contributor_id = #{user_id}) OR
(permissions.contributor_type = 'Network' AND permissions.contributor_id IN #{networks})))"
end
user = args[:user]
+ if (user != 0) && (user != nil)
+
+ user_id = user.id
+
+ friend_ids = get_friend_ids(user)
+ network_ids = get_network_ids(user)
+
+ friends = friend_ids.empty? ? "(-1)" : "(#{friend_ids.join(",")})"
+ networks = network_ids.empty? ? "(-1)" : "(#{network_ids.join(",")})"
+ end
+
# pagination
if args[:limit]
@@ -803,22 +817,26 @@
# filtering
- if args[:type]
- where_part = "WHERE contributions.contributable_type = '#{args[:type].name}'"
+ if user_id
+ where_bits = ["#{view_part(user_id, friends)} OR #{permission_part(['view', 'download', 'edit'], user_id, networks)}"]
else
- where_part = ""
+ where_bits = [view_part]
end
+ if args[:type]
+ where_bits.push("contributions.contributable_type = '#{args[:type].name}'")
+ end
+
+ where_part = where_bits.map do |b| "(#{b})" end.join(" AND ")
+
# result type
if !args[:type] || args[:contribution_records]
contributable_type = nil
- inner_select_part = "contributions.*"
result_model = Contribution
from_part = "FROM contributions"
else
contributable_type = args[:type].name.underscore.pluralize
- inner_select_part = "#{contributable_type}.*"
result_model = args[:type]
from_part = "FROM #{contributable_type} INNER JOIN contributions ON contributions.contributable_id = #{contributable_type}.id"
end
@@ -827,45 +845,34 @@
if args[:select]
select_part = args[:select]
- else
- select_part = "*"
+ elsif contributable_type
+ select_part = "#{args[:type].name.underscore.pluralize}.*"
+ else
+ select_part = "contributions.*"
end
- if (user != 0) && (user != nil)
+ # do the query
+ if user_id
+
# This is the version used for a member
- user_id = user.id
-
- friend_ids = get_friend_ids(user)
- network_ids = get_network_ids(user)
-
- friends = friend_ids.empty? ? "(-1)" : "(#{friend_ids.join(",")})"
- networks = network_ids.empty? ? "(-1)" : "(#{network_ids.join(",")})"
-
query = "
SELECT #{select_part},
- (view OR download OR edit) AS cascaded_view,
- (download OR edit) AS cascaded_download,
- edit AS cascaded_edit FROM
-
- (SELECT #{inner_select_part},
- BIT_OR(#{view_part(user_id, friends)} OR #{permission_part('view', user_id, networks)}) AS view,
- BIT_OR(#{download_part(user_id, friends)} OR #{permission_part('download', user_id, networks)}) AS download,
- BIT_OR(#{edit_part(user_id, friends)} OR #{permission_part('edit', user_id, networks)}) AS edit
+ BIT_OR(#{view_part(user_id, friends)} OR #{permission_part(['view', 'download', 'edit'], user_id, networks)}) AS view,
+ BIT_OR(#{download_part(user_id, friends)} OR #{permission_part(['view', 'download'], user_id, networks)}) AS download,
+ BIT_OR(#{edit_part(user_id, friends)} OR #{permission_part(['view'], user_id, networks)}) AS edit
- #{from_part}
- #{args[:joins]}
- INNER JOIN policies ON contributions.policy_id = policies.id
- LEFT OUTER JOIN permissions ON policies.id = permissions.policy_id
- #{where_part}
- GROUP BY contributable_type, contributable_id) AS foo
-
- WHERE (view OR download OR edit) = true
- #{order_part}
- #{limit_part}"
+ #{from_part}
+ #{args[:joins]}
+ INNER JOIN policies ON contributions.policy_id = policies.id
+ LEFT OUTER JOIN permissions ON policies.id = permissions.policy_id
+ WHERE #{where_part}
+ GROUP BY contributable_type, contributable_id
+ #{order_part}
+ #{limit_part}"
result_model.find_by_sql(query)
@@ -876,23 +883,16 @@
query = "
SELECT #{select_part},
- (view OR download OR edit) AS cascaded_view,
- (download OR edit) AS cascaded_download,
- edit AS cascaded_edit FROM
-
- (SELECT #{inner_select_part},
BIT_OR(#{view_part}) AS view,
BIT_OR(#{download_part}) AS download,
BIT_OR(#{edit_part}) AS edit
- #{from_part}
- #{args[:joins]}
- INNER JOIN policies ON contributions.policy_id = policies.id
- #{where_part}
- GROUP BY contributable_type, contributable_id) AS foo
-
- WHERE (view OR download OR edit) = true
+ #{from_part}
+ #{args[:joins]}
+ INNER JOIN policies ON contributions.policy_id = policies.id
+ WHERE #{where_part}
+ GROUP BY contributable_type, contributable_id
#{order_part}
#{limit_part}"
Modified: trunk/lib/conf.rb (2421 => 2422)
--- trunk/lib/conf.rb 2010-06-02 14:11:51 UTC (rev 2421)
+++ trunk/lib/conf.rb 2010-06-02 23:28:31 UTC (rev 2422)
@@ -134,6 +134,10 @@
self.fetch_entry('validate_email_veracity')
end
+ def self.contribution_order_options
+ self.fetch_entry('contribution_order_options')
+ end
+
# This method is required to create an administrator in the test fixtures
def self.admins=(value)