#648: small refactoring
This commit is contained in:
parent
ceeae09332
commit
cee1ee6cb6
|
@ -5,7 +5,7 @@ class Projects::ProjectsController < Projects::BaseController
|
|||
|
||||
def index
|
||||
@groups = params[:groups] || []
|
||||
@user_owner = params[:user_owner] == ['true'] ? true : false
|
||||
@user_owner = params[:user_owner] ? true : false
|
||||
@projects = Project.accessible_by(current_ability, :membered)
|
||||
|
||||
respond_to do |format|
|
||||
|
@ -107,18 +107,14 @@ class Projects::ProjectsController < Projects::BaseController
|
|||
|
||||
res[:total_count] = projects.count
|
||||
|
||||
if user_owner
|
||||
project_ids = current_user.own_projects.map(&:id)
|
||||
if groups.present?
|
||||
projects = projects.where("groups.id in (?) OR projects.id in (?)", groups, project_ids).
|
||||
joins(:relations).
|
||||
joins('RIGHT OUTER JOIN "groups" ON "groups"."id" = "relations"."actor_id"')
|
||||
else
|
||||
projects = projects.where(:id => project_ids)
|
||||
end
|
||||
else
|
||||
projects = projects.where(:groups => {:id => groups}).joins(:groups) if groups.present?
|
||||
if user_owner && groups.present?
|
||||
projects = projects.by_groups_or_owner(groups, current_user)
|
||||
elsif groups.present?
|
||||
projects = projects.where(:groups => {:id => groups}).joins(:groups)
|
||||
elsif user_owner
|
||||
projects = projects.where(:owner_id => current_user, :owner_type => 'User')
|
||||
end
|
||||
|
||||
projects = projects.search(params[:sSearch]).search_order if params[:sSearch].present?
|
||||
|
||||
res[:filtered_count] = projects.count
|
||||
|
|
|
@ -49,6 +49,11 @@ class Project < ActiveRecord::Base
|
|||
WHERE (ptr.repository_id = #{ repository_id })
|
||||
)
|
||||
) }
|
||||
scope :by_groups_or_owner, lambda { |group_ids, owner_id|
|
||||
where("(relations.actor_id IN (?) AND relations.actor_type = 'Group') OR (projects.owner_id = ? AND projects.owner_type = 'User')", group_ids, owner_id).
|
||||
joins(:relations)
|
||||
}
|
||||
|
||||
|
||||
before_create :set_maintainer
|
||||
after_save :attach_to_personal_repository
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
:color => '00a651',
|
||||
:check_box_name => 'user_owner',
|
||||
:check_box_value => 'true',
|
||||
:name => t("layout.relations.user_owner"),
|
||||
:name => t("layout.relations.my"),
|
||||
:count => current_user.own_projects.count
|
||||
|
||||
.bordered.bpadding20
|
|
@ -1,5 +1,5 @@
|
|||
-set_meta_tags :title => t('layout.projects.list_header')
|
||||
-render 'filter'
|
||||
-render 'filters'
|
||||
.toolbar
|
||||
= link_to t('layout.projects.new'), new_project_path, :class => 'button' if can?(:create, Project)
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
en:
|
||||
layout:
|
||||
relations:
|
||||
my: My
|
||||
user_owner: I'm owner
|
||||
group_owner: I'm member of owner group
|
||||
user: I'm collaborator
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
ru:
|
||||
layout:
|
||||
relations:
|
||||
my: Мои
|
||||
user_owner: Я - владелец
|
||||
group_owner: Я состою в группе-владельцев
|
||||
user: Я - участник
|
||||
|
|
Loading…
Reference in New Issue