diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-02-25 21:15:08 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-02-25 21:15:08 +0400 |
commit | 645e8d470559b07a22164c55b76195a60fb8b37b (patch) | |
tree | d77b7a795c0bf503586e1e704064432e2df96c0b /app/services | |
parent | 0f473674920dfc6759ddf131b32eb0b4b06256d0 (diff) |
Move services for collecting items to Finders
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/filtering_service.rb | 138 | ||||
-rw-r--r-- | app/services/notes/load_service.rb | 20 | ||||
-rw-r--r-- | app/services/projects/collect_service.rb | 69 |
3 files changed, 0 insertions, 227 deletions
diff --git a/app/services/filtering_service.rb b/app/services/filtering_service.rb deleted file mode 100644 index cbbb04ccba9..00000000000 --- a/app/services/filtering_service.rb +++ /dev/null @@ -1,138 +0,0 @@ -# FilteringService class -# -# Used to filter Issues and MergeRequests collections by set of params -# -# Arguments: -# klass - actual class like Issue or MergeRequest -# current_user - which user use -# params: -# scope: 'created-by-me' or 'assigned-to-me' or 'all' -# state: 'open' or 'closed' or 'all' -# group_id: integer -# project_id: integer -# milestone_id: integer -# assignee_id: integer -# search: string -# label_name: string -# sort: string -# -class FilteringService - attr_accessor :klass, :current_user, :params - - def execute(klass, current_user, params) - @klass = klass - @current_user = current_user - @params = params - - items = init_collection - items = by_scope(items) - items = by_state(items) - items = by_group(items) - items = by_project(items) - items = by_search(items) - items = by_milestone(items) - items = by_assignee(items) - items = by_label(items) - items = sort(items) - end - - private - - def init_collection - table_name = klass.table_name - - if project - if project.public? || (current_user && current_user.can?(:read_project, project)) - project.send(table_name) - else - [] - end - elsif current_user && params[:authorized_only].presence - klass.of_projects(current_user.authorized_projects) - else - klass.of_projects(Project.accessible_to(current_user)) - end - end - - def by_scope(items) - case params[:scope] - when 'created-by-me', 'authored' then - items.where(author_id: current_user.id) - when 'all' then - items - when 'assigned-to-me' then - items.where(assignee_id: current_user.id) - else - raise 'You must specify default scope' - end - end - - def by_state(items) - case params[:state] - when 'closed' - items.closed - when 'all' - items - when 'opened' - items.opened - else - raise 'You must specify default state' - end - end - - def by_group(items) - if params[:group_id].present? - items = items.of_group(Group.find(params[:group_id])) - end - - items - end - - def by_project(items) - if params[:project_id].present? - items = items.of_projects(params[:project_id]) - end - - items - end - - def by_search(items) - if params[:search].present? - items = items.search(params[:search]) - end - - items - end - - def sort(items) - items.sort(params[:sort]) - end - - def by_milestone(items) - if params[:milestone_id].present? - items = items.where(milestone_id: (params[:milestone_id] == '0' ? nil : params[:milestone_id])) - end - - items - end - - def by_assignee(items) - if params[:assignee_id].present? - items = items.where(assignee_id: (params[:assignee_id] == '0' ? nil : params[:assignee_id])) - end - - items - end - - def by_label(items) - if params[:label_name].present? - items = items.tagged_with(params[:label_name]) - end - - items - end - - def project - Project.where(id: params[:project_id]).first if params[:project_id].present? - end -end diff --git a/app/services/notes/load_service.rb b/app/services/notes/load_service.rb deleted file mode 100644 index f7ad7d60a3a..00000000000 --- a/app/services/notes/load_service.rb +++ /dev/null @@ -1,20 +0,0 @@ -module Notes - class LoadService < BaseService - def execute - target_type = params[:target_type] - target_id = params[:target_id] - - - @notes = case target_type - when "commit" - project.notes.for_commit_id(target_id).not_inline.fresh - when "issue" - project.issues.find(target_id).notes.inc_author.fresh - when "merge_request" - project.merge_requests.find(target_id).mr_and_commit_notes.inc_author.fresh - when "snippet" - project.snippets.find(target_id).notes.fresh - end - end - end -end diff --git a/app/services/projects/collect_service.rb b/app/services/projects/collect_service.rb deleted file mode 100644 index 0c26231f6ec..00000000000 --- a/app/services/projects/collect_service.rb +++ /dev/null @@ -1,69 +0,0 @@ -# Projects::CollectService class -# -# Used to collect projects user has access to -# -module Projects - class CollectService - def execute(current_user, options) - group = options[:group] - - if group - group_projects(current_user, group) - else - all_projects(current_user) - end - end - - private - - def group_projects(current_user, group) - if current_user - if group.users.include?(current_user) - # User is group member - # - # Return ALL group projects - group.projects - else - projects_members = UsersProject.where( - project_id: group.projects, - user_id: current_user - ) - - if projects_members.any? - # User is a project member - # - # Return only: - # public projects - # internal projects - # joined projects - # - group.projects.where( - "projects.id IN (?) OR projects.visibility_level IN (?)", - projects_members.pluck(:project_id), - Project.public_and_internal_levels - ) - else - # User has no access to group or group projects - # - # Return only: - # public projects - # internal projects - # - group.projects.public_and_internal_only - end - end - else - # Not authenticated - # - # Return only: - # public projects - group.projects.public_only - end - end - end - - def all_projects - # TODO: implement - raise 'Not implemented yet' - end -end |