-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10013 from vpereira/refactor_user_relevant_packag…
…es_for_status Refactor method User#user_relevant_packages_for_status
- Loading branch information
Showing
2 changed files
with
31 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class MaintainedPackagesByUserFinder | ||
def initialize(user) | ||
@user = user | ||
end | ||
|
||
def call | ||
packages_maintained_by_the_user | ||
end | ||
|
||
# private | ||
|
||
def maintainer_role_id | ||
Role.hashed['maintainer'].id | ||
end | ||
|
||
def involved_projects_ids | ||
@user.involved_projects.select(:id) | ||
end | ||
|
||
def packages_by_role | ||
Package.left_outer_joins(:relationships).where('relationships.role_id = ?', maintainer_role_id) | ||
end | ||
|
||
def packages_maintained_by_the_user | ||
packages_by_role.where([ | ||
'(relationships.user_id = ?) OR '\ | ||
'(relationships.user_id is null AND packages.project_id in (?) )', @user.id, involved_projects_ids | ||
]) | ||
end | ||
end |