2012-05-02 10:18:07 +01:00
|
|
|
class Projects::BaseController < ApplicationController
|
2015-04-20 23:05:38 +01:00
|
|
|
prepend_before_action :authenticate_user_and_find_project
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :init_statistics
|
2012-05-02 10:18:07 +01:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
2013-03-21 21:20:36 +00:00
|
|
|
def find_collaborators
|
|
|
|
search = "%#{params[:search_user]}%"
|
2014-04-09 22:20:39 +01:00
|
|
|
@users = @project.collaborators.where("users.uname ILIKE ?", search)
|
|
|
|
@users |= @project.owner.members.where("users.uname ILIKE ?", search) if @project.owner.is_a?(Group)
|
|
|
|
@users = @users.sort_by(&:uname).first(10)
|
2013-03-21 21:20:36 +00:00
|
|
|
end
|
|
|
|
|
2015-04-20 23:05:38 +01:00
|
|
|
def authenticate_user_and_find_project
|
|
|
|
authenticate_user
|
2015-04-03 22:42:25 +01:00
|
|
|
return if params[:name_with_owner].blank?
|
|
|
|
authorize @project = Project.find_by_owner_and_name!(params[:name_with_owner]), :show?
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|
2013-02-15 11:16:34 +00:00
|
|
|
|
|
|
|
def init_statistics
|
2013-02-15 12:00:34 +00:00
|
|
|
if @project
|
|
|
|
@opened_issues_count = @project.issues.without_pull_requests.not_closed_or_merged.count
|
|
|
|
@opened_pull_requests_count = @project.issues.joins(:pull_request).not_closed_or_merged.count
|
|
|
|
end
|
2013-02-15 11:16:34 +00:00
|
|
|
end
|
2012-05-02 10:18:07 +01:00
|
|
|
end
|