Skip to content

Commit

Permalink
Refs #22049 - improve metadata usability
Browse files Browse the repository at this point in the history
  • Loading branch information
ares committed Apr 3, 2018
1 parent 682269f commit 30d9135
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
34 changes: 34 additions & 0 deletions app/helpers/audits_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,40 @@ def audit_time(audit)
date_time_absolute(audit.created_at)
end

def audit_affected_locations(audit)
begin
return _('all') unless audit.auditable_type.constantize.included_modules.include?(Taxonomix)
rescue => e
Foreman::Logging.exception("Audit taxability could not be determined", e)
return _('none')
end

base = audit.locations.authorized(:view_locations)
return _('none') if base.empty?

authorizer = Authorizer.new(User.current, base)
base.map do |location|
link_to_if_authorized location.name, hash_for_edit_location_path(location).merge(:auth_object => location, :permission => 'edit_locations', :authorizer => authorizer)
end.to_sentence.html_safe
end

def audit_affected_organizations(audit)
begin
return _('all') unless audit.auditable_type.constantize.included_modules.include?(Taxonomix)
rescue => e
Foreman::Logging.exception("Audit taxability could not be determined", e)
return _('none')
end

base = audit.organizations.authorized(:view_organizations)
return _('none') if base.empty?

authorizer = Authorizer.new(User.current, base)
base.map do |organization|
link_to_if_authorized organization.name, hash_for_edit_organization_path(organization).merge(:auth_object => organization, :permission => 'edit_organizations', :authorizer => authorizer)
end.to_sentence.html_safe
end

def audited_icon(audit)
style = 'label-info'
style = case audit.action
Expand Down
4 changes: 4 additions & 0 deletions app/views/api/v2/audits/show.json.rabl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
object @audit

extends "api/v2/audits/main"

node do |audit|
partial("api/v2/taxonomies/children_nodes", :object => audit)
end
8 changes: 4 additions & 4 deletions app/views/audits/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@
</div>
<div class="row">
<strong class="col-md-2"><%= _("Audit Time:")%></strong>
<div class="col-md-10"><%= date_time_absolute(@audit.created_at) %></div>
<div class="col-md-10"><%= audit_time(@audit) %></div>
</div>
<div class="row">
<strong class="col-md-2"><%= _("User Name:")%></strong>
<div class="col-md-10"><%= @audit.username %></div>
<div class="col-md-10"><%= audit_user(@audit) %></div>
</div>
<% if Taxonomy.organizations_enabled %>
<div class="row">
<strong class="col-md-2"><%= _("Affected Organizations:")%></strong>
<div class="col-md-10"><%= @audit.organizations.authorized(:view_organizations).to_sentence %></div>
<div class="col-md-10"><%= audit_affected_organizations(@audit) %></div>
</div>
<% end %>
<% if Taxonomy.locations_enabled %>
<div class="row">
<strong class="col-md-2"><%= _("Affected Locations:")%></strong>
<div class="col-md-10"><%= @audit.locations.authorized(:view_locations).to_sentence %></div>
<div class="col-md-10"><%= audit_affected_locations(@audit) %></div>
</div>
<% end %>
<hr/>
Expand Down

0 comments on commit 30d9135

Please sign in to comment.