Diff
Modified: branches/snapshots/app/controllers/packs_controller.rb (3196 => 3197)
--- branches/snapshots/app/controllers/packs_controller.rb 2012-11-23 11:29:17 UTC (rev 3196)
+++ branches/snapshots/app/controllers/packs_controller.rb 2012-11-26 10:45:27 UTC (rev 3197)
@@ -447,6 +447,8 @@
if Authorization.check(action_permissions[action_name], pack, current_user)
@pack = pack
+ @version = @pack.find_version(params[:version]) if params[:version]
+
@authorised_to_edit = logged_in? && Authorization.check("edit", @pack, current_user)
@authorised_to_download = Authorization.check("download", @pack, current_user)
Modified: branches/snapshots/app/models/pack.rb (3196 => 3197)
--- branches/snapshots/app/models/pack.rb 2012-11-23 11:29:17 UTC (rev 3196)
+++ branches/snapshots/app/models/pack.rb 2012-11-26 10:45:27 UTC (rev 3197)
@@ -30,7 +30,7 @@
match = versions.find(:first, :conditions => ["version = ?", version])
return match if match
- raise ActiveRecord::RecordNotFound.new("Couldn't find Pack with pack_id=#{id} and version=#{v}")
+ raise ActiveRecord::RecordNotFound.new("Couldn't find Pack with pack_id=#{id} and version=#{version}")
end
validates_presence_of :title
@@ -56,7 +56,7 @@
:dependent => :destroy
def items_count
- return contributable_entries.count + remote_entries.count
+ contributable_entries.count + remote_entries.count
end
# returns packs that have largest total number of items
Modified: branches/snapshots/app/views/packs/_items.rhtml (3196 => 3197)
--- branches/snapshots/app/views/packs/_items.rhtml 2012-11-23 11:29:17 UTC (rev 3196)
+++ branches/snapshots/app/views/packs/_items.rhtml 2012-11-26 10:45:27 UTC (rev 3197)
@@ -10,7 +10,7 @@
<ul id="packItemsList">
<!-- Contributable Item Entries -->
- <% pack.contributable_entries.each do |e| %>
+ <% contributable_entries.each do |e| %>
<% show = e.available? ? Authorization.check("view", e.contributable, current_user) : false -%>
<li>
<table>
@@ -98,7 +98,7 @@
<% end -%>
<!-- Remote Item Entries -->
- <% pack.remote_entries.each do |e| %>
+ <% remote_entries.each do |e| %>
<li>
<table>
<tr>
Modified: branches/snapshots/app/views/packs/show.rhtml (3196 => 3197)
--- branches/snapshots/app/views/packs/show.rhtml 2012-11-23 11:29:17 UTC (rev 3196)
+++ branches/snapshots/app/views/packs/show.rhtml 2012-11-26 10:45:27 UTC (rev 3197)
@@ -1,5 +1,9 @@
<% t "#{contributable_name(@pack.id, 'Pack')} (#{h @pack.contributor_name})" -%>
+<% items_count = @version ? @version.items_count : @pack.items_count %>
+<% contributable_entries = @version ? @version.contributable_entries : @pack.contributable_entries %>
+<% remote_entries = @version ? @version.remote_entries : @pack.remote_entries %>
+
<% if @authorised_to_edit %>
<ul class="sectionIcons">
<% if mine?(@pack) -%>
@@ -76,10 +80,10 @@
<% end %>
<%= info_icon_with_tooltip("This section shows all the items that are pointed to in this pack. This can be a combination of internal and external items.") -%>
- Items <span class="count_text">(<%= @pack.items_count -%>)</span>
+ Items <span class="count_text">(<%= items_count -%>)</span>
</h4>
- <%= render :partial => "items", :locals => { :pack => @pack, :authorised_to_edit => @authorised_to_edit } -%>
+ <%= render :partial => "items", :locals => { :pack => @pack, :contributable_entries => contributable_entries, :remote_entries => remote_entries, :authorised_to_edit => @authorised_to_edit } -%>
<br/><br/>
<h4>
@@ -133,7 +137,7 @@
<div class="contribution_section_box">
<p style="font-size: 108%;">
- <b><%= pluralize @pack.items_count, "item" %> in this pack</b>
+ <b><%= pluralize items_count, "item" %> in this pack</b>
</p>
</div>
Modified: branches/snapshots/config/routes.rb (3196 => 3197)
--- branches/snapshots/config/routes.rb 2012-11-23 11:29:17 UTC (rev 3196)
+++ branches/snapshots/config/routes.rb 2012-11-26 10:45:27 UTC (rev 3197)
@@ -137,8 +137,8 @@
map.formatted_blob_version '/files/:id/versions/:version.:format', :conditions => { :method => :get }, :controller => 'blobs', :action ="" 'show'
# pack redirect for linked data model
- map.blob_version '/packs/:id/versions/:version', :conditions => { :method => :get }, :controller => 'packs', :action ="" 'show'
- map.formatted_blob_version '/packs/:id/versions/:version.:format', :conditions => { :method => :get }, :controller => 'packs', :action ="" 'show'
+ map.pack_version '/packs/:id/versions/:version', :conditions => { :method => :get }, :controller => 'packs', :action ="" 'show'
+ map.formatted_pack_version '/packs/:id/versions/:version.:format', :conditions => { :method => :get }, :controller => 'packs', :action ="" 'show'
map.blob_version_suggestions '/files/:id/versions/:version/suggestions', :conditions => { :method => :get }, :controller => 'blobs', :action ="" 'suggestions'
map.blob_version_process_suggestions '/files/:id/versions/:version/process_suggestions', :conditions => { :method => :post }, :controller => 'blobs', :action ="" 'process_suggestions'
Modified: branches/snapshots/lib/authorization.rb (3196 => 3197)
--- branches/snapshots/lib/authorization.rb 2012-11-23 11:29:17 UTC (rev 3196)
+++ branches/snapshots/lib/authorization.rb 2012-11-26 10:45:27 UTC (rev 3197)
@@ -87,6 +87,24 @@
is_authorized = true
end
+ when "PackVersion"
+ case action
+ when "create"
+
+ # If a user can edit a pack, they can create a version of it.
+ is_authorized = Authorization.check('edit', context, user)
+
+ when "view"
+
+ # If a user can view a pack, they can view versions of it.
+ is_authorized = Authorization.check('view', context, user)
+
+ else
+
+ # Editing or deleting versions of a pack is not allowed.
+ is_authorized = false
+ end
+
when "Comment"
case action
when "create"