Modified: branches/apace/app/models/user.rb (2164 => 2165)
--- branches/apace/app/models/user.rb 2009-04-07 11:08:34 UTC (rev 2164)
+++ branches/apace/app/models/user.rb 2009-04-07 11:16:25 UTC (rev 2165)
@@ -528,17 +528,12 @@
# 1) the ID of a user (of 2 involved in the 'friendship') who is a 'friend', not an owner of the friendship;
# 2) the 'friendship' object itself
def friendship_from_self_id_and_friends_id(friend_id)
- friendship = Friendship.find(:first, :conditions => [ "user_id = ? AND friend_id = ?", id, friend_id ] )
+ friendship = Friendship.find(:first, :conditions => [ "( (user_id = ? AND friend_id = ?) OR ( user_id = ? AND friend_id = ? ) )", id, friend_id, friend_id, id ] )
if friendship
return [friend_id, friendship]
- elsif
- friendship = Friendship.find(:first, :conditions => [ "user_id = ? AND friend_id = ?", friend_id, id ] )
- if friendship
- return [id, friendship]
- else
- return [nil, nil] # an error state
- end
+ else
+ return [nil, nil] # an error state
end
end
Modified: branches/apace/app/views/home/_stats.rhtml (2164 => 2165)
--- branches/apace/app/views/home/_stats.rhtml 2009-04-07 11:08:34 UTC (rev 2164)
+++ branches/apace/app/views/home/_stats.rhtml 2009-04-07 11:16:25 UTC (rev 2165)
@@ -1,8 +1,9 @@
-<div class="stats">
- <%= Conf.sitename %> currently has
- <%= link_to pluralize(User.count(:conditions => "users.activated_at IS NOT NULL"), "user"), users_url -%>,
- <%= link_to pluralize(Network.count, "group"), groups_url -%>,
- <%= link_to pluralize(Workflow.count, "workflow"), workflows_url -%>,
- <%= link_to pluralize(Blob.count, "file"), files_url -%> and
- <%= link_to pluralize(Pack.count, "pack"), packs_url -%>
-</div>
+<% if !Conf.home_page_stats.empty? %>
+ <div class="stats">
+ <%= Conf.sitename %> currently has
+ <%= comma_list(Conf.home_page_stats.map do |stat|
+ link_to(pluralize(eval(stat["model"]).count(stat["conditions"] ?
+ { :conditions => stat["conditions"] } : { }), stat["label"]), stat["link"])
+ end) %>
+ </div>
+<% end %>
Modified: branches/apace/lib/rest.rb (2164 => 2165)
--- branches/apace/lib/rest.rb 2009-04-07 11:08:34 UTC (rev 2164)
+++ branches/apace/lib/rest.rb 2009-04-07 11:16:25 UTC (rev 2165)
@@ -18,7 +18,7 @@
'Foreign Accessor',
'List Element Name', 'List Element Accessor',
'Example', 'Versioned', 'Key type',
- 'Limited to user', 'Permission' ] },
+ 'Limited to user', 'Permission', 'Index filter' ] },
'REST' => { :indices => [ 'URI', 'Method' ] }
} )
@@ -134,7 +134,7 @@
case model_data['Encoding'][i]
- when 'list'
+ when 'list', 'item as list'
list_element = XML::Node.new(model_data['REST Attribute'][i])
@@ -144,6 +144,8 @@
collection = eval("ob.#{model_data['Accessor'][i]}")
+ collection = [collection] if model_data['Encoding'][i] == 'item as list'
+
# filter out things that the user cannot see
collection = collection.select do |c|
not c.respond_to?('contribution') or Authorization.is_authorized?("view", nil, c, user)
@@ -292,9 +294,9 @@
rest_get_request(ob, params[:uri], user, eval("rest_resource_uri(ob)"), rest_name, query)
end
-def find_all_paginated_auth(model, find_args, num, page, user)
+def find_all_paginated_auth(model, find_args, num, page, filters, user)
- def aux(model, find_args, num, page, user)
+ def aux(model, find_args, num, page, filters, user)
find_args = find_args.clone
find_args[:page] = { :size => num, :current => page }
@@ -304,7 +306,15 @@
return nil if results.page > results.page_count
results.select do |result|
- Authorization.is_authorized?('view', nil, result, user)
+ selected = Authorization.is_authorized?('view', nil, result, user)
+
+ if selected
+ filters.each do |attribute,value|
+ selected = false unless result.send(attribute).downcase == value.downcase
+ end
+ end
+
+ selected
end
end
@@ -319,13 +329,13 @@
# up to possibly fulfil the request
if (page > 1)
- results = aux(model, find_args, upto, 1, user)
+ results = aux(model, find_args, upto, 1, filters, user)
current_page = page + 1
end
while (results.length < upto)
- results_page = aux(model, find_args, num, current_page, user)
+ results_page = aux(model, find_args, num, current_page, filters, user)
if results_page.nil?
break
@@ -359,6 +369,20 @@
page = 1 if page < 1
+ model = TABLES["Model"][:data][TABLES["REST"][:data][req_uri]["GET"]["REST Entity"]]
+
+ # detect filters
+
+ filters = {}
+
+ (0..model["REST Attribute"].length - 1).each do |i|
+ filter_name = model["Index filter"][i]
+
+ if !filter_name.nil? && !query[filter_name].nil?
+ filters[filter_name] = query[filter_name]
+ end
+ end
+
if query['tag']
tag = Tag.find_by_name(query['tag'])
@@ -386,7 +410,7 @@
find_args[:conditions] = conditions if conditions
- obs = find_all_paginated_auth(model_name.camelize, find_args, limit, page, user)
+ obs = find_all_paginated_auth(model_name.camelize, find_args, limit, page, filters, user)
end
produce_rest_list(req_uri, rules, query, obs, rest_name.pluralize, user)
@@ -443,6 +467,7 @@
when 'User'; return user_url(ob)
when 'Review'; return workflow_review_url(ob.reviewable, ob)
when 'Comment'; return "#{rest_resource_uri(ob.commentable)}/comments/#{ob.id}"
+ when 'Bookmark'; return nil
when 'Blog'; return blog_url(ob)
when 'BlogPost'; return blog_post_url(ob.blog, ob)
when 'Rating'; return "#{rest_resource_uri(ob.rateable)}/ratings/#{ob.id}"
@@ -479,6 +504,7 @@
when 'User'; return "#{base}/user.xml?id=#{ob.id}"
when 'Review'; return "#{base}/review.xml?id=#{ob.id}"
when 'Comment'; return "#{base}/comment.xml?id=#{ob.id}"
+ when 'Bookmark'; return "#{base}/favourite.xml?id=#{ob.id}"
when 'Blog'; return "#{base}/blog.xml?id=#{ob.id}"
when 'BlogPost'; return "#{base}/blog-post.xml?id=#{ob.id}"
when 'Rating'; return "#{base}/rating.xml?id=#{ob.id}"
@@ -524,6 +550,8 @@
when 'PackContributableEntry'; return rest_object_tag_text(ob.contributable)
when 'PackRemoteEntry'; return 'external'
when 'Workflow::Version'; return 'workflow'
+ when 'Comment'; return 'comment'
+ when 'Bookmark'; return 'favourite'
end
return 'object'