Skip to content

Commit

Permalink
fixity status report.
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Mar 18, 2013
1 parent 73db50d commit 6da3182
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 2 deletions.
2 changes: 0 additions & 2 deletions app/assets/stylesheets/styles.css.scss
Expand Up @@ -5,8 +5,6 @@
// TYPOGRAPHY
// -----------------------------------------------------

@import url("https://fonts.googleapis.com/css?family=Ubuntu");

// NAVBAR
// -----------------------------------------------------

Expand Down
8 changes: 8 additions & 0 deletions app/controllers/generic_files_controller.rb
Expand Up @@ -3,6 +3,10 @@ class GenericFilesController < ApplicationController

after_filter :log_visit, :only=>:show


load_resource :only=>[:fixity, :audit]
load_and_authorize_resource :except=>[:index, :fixity, :audit]

def log_visit
@generic_file.views.create!(user: current_or_guest_user)
end
Expand All @@ -17,6 +21,10 @@ def show
end
end

def fixity

end

# routed to /files (POST)
def create
if params[:local_file].present?
Expand Down
12 changes: 12 additions & 0 deletions app/models/ability.rb
Expand Up @@ -10,5 +10,17 @@ def custom_permissions
can :dashboard # grant access to the dashboard
end

can [:fixity], String do |pid|
test_edit(pid)
end

can [:fixity], ActiveFedora::Base do |obj|
test_edit(obj.pid)
end

can :fixity, SolrDocument do |obj|
test_edit(obj.id)
end

end
end
60 changes: 60 additions & 0 deletions app/views/generic_files/fixity.html.erb
@@ -0,0 +1,60 @@
<%
fixity_xml = ActiveFedora::Base.connection_for_pid(@generic_file).client["../../fcrepo-fixity/rest/results/#{@generic_file.pid}"].get
%>

<style>

.fixity-result {
padding: 2em 0;
}
.fixity-failure, .ds-fixity-failure {
color: red;
}

.fixity-result td, .fixity-result th {
text-align: left;
padding-right: 2em;
}

.dsid {
color: #000;
}

.details {
color: #666;
}
</style>

<h1>Fixity status for <%= @generic_file.pid %></h1>

<% Nokogiri::XML(fixity_xml).xpath('//fixity-result').sort_by { |x| x.attr('timestamp') }.reverse.each do |result| %>
<div class="fixity-result fixity-<%= result.attr("success") == "true" ? "success" : "failure" %> ">
<h3>From <%= time_ago_in_words DateTime.parse(result.attr("timestamp")) %> ago:</h3>
<dl>
<dt>Timestamp</dt>
<dd><%= result.attr("timestamp") %></dd>

<dt>Result</dt>
<dd><%= result.attr("success") == "true" ? "success" : "failure" %></dd>
</dl>
<table>
<thead>
<tr>
<th>Datastream</th>
<th>Details</th>
</tr>
</thead>

<tbody>
<% result.xpath('successes/successes', 'errors/errors').sort_by { |x| x.attr('datastream-id') }.each do |ds| %>
<tr class="ds-fixity-<%= ds.attr("type") == "SUCCESS" ? "success" : "failure" %> ">
<td class="dsid"><%= ds.attr('datastream-id') %></td>
<td class="details"><%= ds.xpath('details').text %></td>
</tr>
<% end %>
</tbody>
</table>


</div>
<% end %>
1 change: 1 addition & 0 deletions app/views/generic_files/show.html.erb
Expand Up @@ -49,5 +49,6 @@ limitations under the License.
</tr>
</tbody>
</table>
<%= link_to 'Fixity report', file_fixity_url(@generic_file) %>
</div><!-- /columns second -->
</div> <!-- /columns two-b -->
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -10,6 +10,7 @@

match 'about/repository', :to => 'about#repository'

match 'files/:id/fixity', :to => 'generic_files#fixity', :as => 'file_fixity'
match 'about', :to => 'about#repository'

# Resque monitoring routes
Expand Down

0 comments on commit 6da3182

Please sign in to comment.