Skip to content

Commit

Permalink
Add missing_s action to AuditController and corresponding route
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jan 22, 2024
1 parent cd2b80a commit 03990e2
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/audit_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def inactive
@collectives = Collective.with_projects.inactive.order(transactions_count: :desc)
end

def missing_s
@collectives = Collective.where(projects_count: 0).order(transactions_count: :desc).select{|c| c.missing_s? }
end

# collectives with no funding links
# collectives with invalid urls
end
6 changes: 6 additions & 0 deletions app/models/collective.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,4 +423,10 @@ def total_expenses
def current_balance
transactions.sum(:net_amount)
end

def missing_s?
return false if project_owner.nil?
# TODO
project_owner.downcase != slug.downcase && project_owner.downcase.gsub('s', '') == slug.downcase.gsub('s', '')
end
end
3 changes: 3 additions & 0 deletions app/views/audit/_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
<li class="nav-item">
<a class="nav-link <%= 'active' if params[:action] == 'inactive' %>" href='/audit/inactive'>Inactive</a>
</li>
<li class="nav-item">
<a class="nav-link <%= 'active' if params[:action] == 'missing_s' %>" href='/audit/missing_s'>Missing S</a>
</li>
</ul>
5 changes: 5 additions & 0 deletions app/views/audit/missing_s.csv.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%- headers = ['slug', 'project_url', 'projects_count'] -%>
<%= CSV.generate_line headers -%>
<%- @collectives.each do |collective| -%>
<%= CSV.generate_line([collective.slug, collective.project_url, collective.projects_count]) -%>
<%- end -%>
34 changes: 34 additions & 0 deletions app/views/audit/missing_s.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<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' %> that appear to be missing an S in the github url.
</small>
</i>
</p>

<%= link_to 'Export as CSV', audit_missing_s_path(format: :csv), class: 'btn btn-primary' %>
</div>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
get '/audit/no_license', to: 'audit#no_license'
get '/audit/archived', to: 'audit#archived'
get '/audit/inactive', to: 'audit#inactive'
get '/audit/missing_s', to: 'audit#missing_s'
get '/audit', to: 'audit#index'

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

0 comments on commit 03990e2

Please sign in to comment.