Skip to content

Commit

Permalink
Refactor Collective and Project scopes and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jan 22, 2024
1 parent 1792601 commit f595127
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions app/controllers/audit_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ def no_projects
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?}
@collectives = Collective.with_projects.order(transactions_count: :desc).select{|c| c.no_license? }
end

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

def inactive
@collectives = Collective.select{|c| c.inactive?}
@collectives = Collective.with_projects.order(transactions_count: :desc).select{|c| c.inactive? }
end

# collectives with no funding links
Expand Down
10 changes: 9 additions & 1 deletion app/models/collective.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Collective < ApplicationRecord

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

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

scope :with_owner, -> { where.not(owner: nil) }
scope :with_org_owner, -> { with_owner.where("owner ->> 'kind' = 'organization'") }
Expand Down Expand Up @@ -55,6 +55,14 @@ def inactive?
last_project_activity_at < 1.year.ago
end

def archived?
projects.all?{|p| p.archived? }
end

def no_license?
projects.all?{|p| p.no_license? }
end

def sync_async
SyncCollectiveWorker.perform_async(id)
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ def open_source_license?
(packages_licenses + [repository_license]).compact.uniq.any?
end

def no_license?
!open_source_license?
end

def packages_licenses
[] # TODO
end

def archived?
return false unless repository.present?
repository['archived']
Expand Down

0 comments on commit f595127

Please sign in to comment.