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