Skip to content

Commit

Permalink
Add audit functionality to the application
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jan 18, 2024
1 parent fe6313a commit 3a564ad
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 50 deletions.
19 changes: 15 additions & 4 deletions app/controllers/audit_controller.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
class AuditController < ApplicationController
def index
@collectives = Collective.where(projects_count: 0).where('balance > 0').order(balance: :desc).select{|c| c.project_url.present?}
redirect_to action: :user_owners
end

def user_owners
@collectives = Collective.with_user_owner.with_transactions.order(transactions_count: :desc)
end

@archived = Collective.where(projects_count: 1).select{|c| c.projects.first && c.projects.first.repository && c.projects.first.repository['archived']}
def no_projects
@collectives = Collective.where(projects_count: 0).with_transactions.order(transactions_count: :desc).select{|c| c.project_url.present?}
end

def no_license
@collectives = Collective.where(projects_count: 1).select{|c| c.projects.first && c.projects.first.repository && !c.projects.first.repository['archived'] && c.projects.first.repository['license'].blank?}
end

@no_license = Collective.where(projects_count: 1).select{|c| c.projects.first && c.projects.first.repository && !c.projects.first.repository['archived'] && c.projects.first.repository['license'].blank?}
def archived
@collectives = Collective.where(projects_count: 1).select{|c| c.projects.first && c.projects.first.repository && c.projects.first.repository['archived']}
end

# collectives where owner is a user instead of an org
# collectives with invalid urls
# collectives with no projects
# collectives with inactive projects
end
2 changes: 2 additions & 0 deletions app/models/collective.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Collective < ApplicationRecord

has_many :transactions, dependent: :destroy

scope :with_transactions, -> { where.not(transactions_count: 0) }

scope :with_repository, -> { where.not(repository: nil) }

scope :with_owner, -> { where.not(owner: nil) }
Expand Down
14 changes: 14 additions & 0 deletions app/views/audit/_nav.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ul class="nav nav-tabs my-3">
<li class="nav-item">
<a class="nav-link <%= 'active' if params[:action] == 'user_owners' %>" href='/audit/user_owners'>User owners</a>
</li>
<li class="nav-item">
<a class="nav-link <%= 'active' if params[:action] == 'no_projects' %>" href='/audit/no_projects'>No projects</a>
</li>
<li class="nav-item">
<a class="nav-link <%= 'active' if params[:action] == 'no_license' %>" href='/audit/no_license'>No license</a>
</li>
<li class="nav-item">
<a class="nav-link <%= 'active' if params[:action] == 'archived' %>" href='/audit/archived'>Archived</a>
</li>
</ul>
32 changes: 32 additions & 0 deletions app/views/audit/archived.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="container-md">
<h2>Audit</h2>

<%= render 'nav' %>

<% @collectives.each do |collective| %>
<div class="collective card my-2">
<div class='card-body'>
<div class="d-flex">

<div class="flex-grow-1 ms-3 text-break">
<h4><%= link_to collective.name, collective %></h4>
<p><%= collective.description %></p>
<p><%= number_with_delimiter collective.projects_count %> repository - <%= number_with_delimiter collective.transactions_count %> transactions - Balance: <%= collective.balance.round(2)%> <%= collective.currency %></p>
<p>Project url: <%= link_to collective.project_url, collective.project_url, target: :_blank %></p>
</div>
<div class="flex-shrink-0">
<img src="<%= collective.icon_url %>" class="rounded" height='40' width='40' onerror="this.style.display='none'">
</div>
</div>
</div>
</div>
<% end %>

<p>
<i>
<small>
Displaying <%= pluralize @collectives.length, 'collective' %> with exactly 1 repository, that has been archived.
</small>
</i>
</p>
</div>
46 changes: 0 additions & 46 deletions app/views/audit/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,46 +0,0 @@
<div class="container-md">
<h2>Audit</h2>
<ul>
<li><a href='#no-projects'>No projects</a></li>
<li><a href='#no-license'>No license</a></li>
<li><a href='#archived'>Archived repo</a></li>
</ul>

<h3 id='no-projects'>Collectives with no projects</h3>

<% @collectives.each do |collective| %>
<div class="collective card my-2">
<div class='card-body'>
<h4><%= link_to collective.name, collective %></h4>
<p><%= collective.description %></p>
<p><%= link_to collective.project_url, collective.project_url, target: :_blank %></p>
</div>
</div>
<% end %>

<hr>

<h3 id='no-license'>Collectives with no license</h3>

<% @no_license.each do |collective| %>
<div class="collective card my-2">
<div class='card-body'>
<h4><%= link_to collective.name, collective %></h4>
<p><%= link_to collective.projects.first.repository_url, collective.projects.first.repository_url, target: :_blank %></p>
</div>
</div>
<% end %>

<hr>

<h3 id='archived'>Collectives with archived repo</h3>

<% @archived.each do |collective| %>
<div class="collective card my-2">
<div class='card-body'>
<h4><%= link_to collective.name, collective %></h4>
<p><%= link_to collective.projects.first.repository_url, collective.projects.first.repository_url, target: :_blank %></p>
</div>
</div>
<% end %>
</div>
32 changes: 32 additions & 0 deletions app/views/audit/no_license.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="container-md">
<h2>Audit</h2>

<%= render 'nav' %>

<% @collectives.each do |collective| %>
<div class="collective card my-2">
<div class='card-body'>
<div class="d-flex">

<div class="flex-grow-1 ms-3 text-break">
<h4><%= link_to collective.name, collective %></h4>
<p><%= collective.description %></p>
<p><%= number_with_delimiter collective.projects_count %> repository - <%= number_with_delimiter collective.transactions_count %> transactions - Balance: <%= collective.balance.round(2)%> <%= collective.currency %></p>
<p>Project url: <%= link_to collective.project_url, collective.project_url, target: :_blank %></p>
</div>
<div class="flex-shrink-0">
<img src="<%= collective.icon_url %>" class="rounded" height='40' width='40' onerror="this.style.display='none'">
</div>
</div>
</div>
</div>
<% end %>

<p>
<i>
<small>
Displaying <%= pluralize @collectives.length, 'collective' %> with exactly 1 repository, that we can't detect a license for.
</small>
</i>
</p>
</div>
32 changes: 32 additions & 0 deletions app/views/audit/no_projects.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="container-md">
<h2>Audit</h2>

<%= render 'nav' %>

<% @collectives.each do |collective| %>
<div class="collective card my-2">
<div class='card-body'>
<div class="d-flex">

<div class="flex-grow-1 ms-3 text-break">
<h4><%= link_to collective.name, collective %></h4>
<p><%= collective.description %></p>
<p><%= number_with_delimiter collective.projects_count %> repositories - <%= number_with_delimiter collective.transactions_count %> transactions - Balance: <%= collective.balance.round(2)%> <%= collective.currency %></p>
<p>Project url: <%= link_to collective.project_url, collective.project_url, target: :_blank %></p>
</div>
<div class="flex-shrink-0">
<img src="<%= collective.icon_url %>" class="rounded" height='40' width='40' onerror="this.style.display='none'">
</div>
</div>
</div>
</div>
<% end %>

<p>
<i>
<small>
Displaying <%= pluralize @collectives.length, 'collective' %>, excluding collectives with no transactions, that we found a project url for, but couldn't load any projects from.
</small>
</i>
</p>
</div>
32 changes: 32 additions & 0 deletions app/views/audit/user_owners.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<div class="container-md">
<h2>Audit</h2>

<%= render 'nav' %>

<% @collectives.each do |collective| %>
<div class="collective card my-2">
<div class='card-body'>
<div class="d-flex">

<div class="flex-grow-1 ms-3 text-break">
<h4><%= link_to collective.name, collective %></h4>
<p><%= collective.description %></p>
<p><%= number_with_delimiter collective.projects_count %> repositories - <%= number_with_delimiter collective.transactions_count %> transactions - Balance: <%= collective.balance.round(2)%> <%= collective.currency %></p>
<p>Owner: <%= link_to collective.owner['login'], collective.owner['html_url'], target: :_blank %></p>
</div>
<div class="flex-shrink-0">
<img src="<%= collective.icon_url %>" class="rounded" height='40' width='40' onerror="this.style.display='none'">
</div>
</div>
</div>
</div>
<% end %>

<p>
<i>
<small>
Displaying <%= pluralize @collectives.length, 'collective' %>, excluding collectives with no transactions, owned by a user instead of an organization.
</small>
</i>
</p>
</div>
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@

resources :exports, only: [:index], path: 'open-data'

get '/audit/user_owners', to: 'audit#user_owners'
get '/audit/no_projects', to: 'audit#no_projects'
get '/audit/no_license', to: 'audit#no_license'
get '/audit/archived', to: 'audit#archived'
get '/audit', to: 'audit#index'

get '/404', to: 'errors#not_found'
Expand Down

0 comments on commit 3a564ad

Please sign in to comment.