2012-05-02 10:18:07 +01:00
|
|
|
class Projects::ProjectsController < Projects::BaseController
|
2012-09-24 19:04:53 +01:00
|
|
|
include ProjectsHelper
|
2014-11-13 21:41:07 +00:00
|
|
|
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :authenticate_user!
|
2016-03-28 10:56:04 +01:00
|
|
|
skip_before_action :authenticate_user!, only: [:commit, :diff]
|
2015-03-04 23:19:19 +00:00
|
|
|
before_action :who_owns, only: [:new, :create, :mass_import, :run_mass_import]
|
2011-03-10 13:38:50 +00:00
|
|
|
|
2011-10-26 21:57:51 +01:00
|
|
|
def index
|
2015-03-17 22:33:16 +00:00
|
|
|
authorize :project
|
2012-03-27 16:50:00 +01:00
|
|
|
respond_to do |format|
|
2016-05-04 16:49:30 +01:00
|
|
|
format.html
|
2012-09-24 19:04:53 +01:00
|
|
|
format.json {
|
2016-04-29 15:10:30 +01:00
|
|
|
if not params[:search].present?
|
|
|
|
@projects = Project.find(current_user.build_lists.group(:project_id).limit(10).pluck(:project_id))
|
|
|
|
else
|
|
|
|
@projects = ProjectPolicy::Scope.new(current_user, Project).membered.search(params[:search]).limit(20)
|
|
|
|
end
|
2012-09-24 19:04:53 +01:00
|
|
|
}
|
2012-03-27 16:50:00 +01:00
|
|
|
end
|
2011-03-10 14:20:09 +00:00
|
|
|
end
|
|
|
|
|
2016-04-29 15:10:30 +01:00
|
|
|
def dashboard
|
2015-03-17 22:33:16 +00:00
|
|
|
authorize :project
|
2013-11-13 22:01:12 +00:00
|
|
|
end
|
|
|
|
|
2016-04-29 15:10:30 +01:00
|
|
|
def new
|
2015-12-16 18:36:38 +00:00
|
|
|
authorize :project
|
2016-04-29 15:10:30 +01:00
|
|
|
@project = Project.new
|
2015-12-16 18:36:38 +00:00
|
|
|
end
|
|
|
|
|
2011-10-26 21:57:51 +01:00
|
|
|
def edit
|
2015-03-17 22:33:16 +00:00
|
|
|
authorize @project
|
2011-10-26 21:57:51 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-05-22 19:35:34 +01:00
|
|
|
@project = Project.new project_params
|
2012-02-27 09:03:28 +00:00
|
|
|
@project.owner = choose_owner
|
2015-03-17 22:33:16 +00:00
|
|
|
authorize @project
|
2011-10-26 21:57:51 +01:00
|
|
|
|
2011-11-30 12:58:14 +00:00
|
|
|
if @project.save
|
2012-04-10 10:40:38 +01:00
|
|
|
flash[:notice] = t('flash.project.saved')
|
2016-06-15 01:17:42 +01:00
|
|
|
redirect_to project_build_lists_path(@project)
|
2011-10-26 21:57:51 +01:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.project.save_error')
|
2012-03-03 01:05:19 +00:00
|
|
|
flash[:warning] = @project.errors.full_messages.join('. ')
|
2014-01-21 04:51:49 +00:00
|
|
|
render action: :new
|
2011-10-26 21:57:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2015-03-17 22:33:16 +00:00
|
|
|
authorize @project
|
2012-08-31 18:47:52 +01:00
|
|
|
params[:project].delete(:maintainer_id) if params[:project][:maintainer_id].blank?
|
2014-02-18 19:16:23 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2015-05-22 19:35:34 +01:00
|
|
|
if @project.update_attributes(project_params)
|
2014-02-18 19:16:23 +00:00
|
|
|
flash[:notice] = t('flash.project.saved')
|
2016-04-29 15:10:30 +01:00
|
|
|
redirect_to root_path
|
2014-02-18 19:16:23 +00:00
|
|
|
else
|
|
|
|
flash[:error] = t('flash.project.save_error')
|
|
|
|
flash[:warning] = @project.errors.full_messages.join('. ')
|
|
|
|
render action: :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
format.json do
|
2015-05-22 19:35:34 +01:00
|
|
|
if @project.update_attributes(project_params)
|
2015-03-17 22:33:16 +00:00
|
|
|
render json: { notice: I18n.t('flash.project.saved') }
|
2014-02-18 19:16:23 +00:00
|
|
|
else
|
2015-03-17 22:33:16 +00:00
|
|
|
render json: { error: I18n.t('flash.project.save_error') }, status: 422
|
2014-02-18 19:16:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def schedule
|
2015-03-23 23:24:27 +00:00
|
|
|
authorize @project
|
2015-05-22 19:35:34 +01:00
|
|
|
p_to_r = @project.project_to_repositories.find_by(repository_id: params[:repository_id])
|
2014-02-18 19:16:23 +00:00
|
|
|
unless p_to_r.repository.publish_without_qa
|
2015-03-23 23:24:27 +00:00
|
|
|
authorize p_to_r.repository.platform, :local_admin_manage?
|
2011-10-26 21:57:51 +01:00
|
|
|
end
|
2014-02-18 19:16:23 +00:00
|
|
|
p_to_r.user_id = current_user.id
|
|
|
|
p_to_r.enabled = params[:enabled].present?
|
|
|
|
p_to_r.auto_publish = params[:auto_publish].present?
|
|
|
|
p_to_r.save
|
2014-02-19 09:16:27 +00:00
|
|
|
if p_to_r.save
|
|
|
|
render json: { notice: I18n.t('flash.project.saved') }.to_json
|
2011-10-26 21:57:51 +01:00
|
|
|
else
|
2014-02-19 09:16:27 +00:00
|
|
|
render json: { error: I18n.t('flash.project.save_error') }.to_json, status: 422
|
2011-10-26 21:57:51 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2015-03-17 22:33:16 +00:00
|
|
|
authorize @project
|
2011-10-26 21:57:51 +01:00
|
|
|
@project.destroy
|
|
|
|
flash[:notice] = t("flash.project.destroyed")
|
2011-10-27 13:49:21 +01:00
|
|
|
redirect_to @project.owner
|
2011-10-26 21:57:51 +01:00
|
|
|
end
|
|
|
|
|
2012-08-24 16:19:26 +01:00
|
|
|
def autocomplete_maintainers
|
2015-03-23 23:24:27 +00:00
|
|
|
authorize @project
|
2015-02-11 10:32:55 +00:00
|
|
|
term, limit = params[:query], params[:limit] || 10
|
2012-08-24 16:19:26 +01:00
|
|
|
items = User.member_of_project(@project)
|
|
|
|
.where("users.name ILIKE ? OR users.uname ILIKE ?", "%#{term}%", "%#{term}%")
|
2014-11-11 16:59:49 +00:00
|
|
|
.limit(limit).map { |u| {name: u.fullname, id: u.id} }
|
2014-01-21 04:51:49 +00:00
|
|
|
render json: items
|
2012-08-24 16:19:26 +01:00
|
|
|
end
|
|
|
|
|
2016-03-20 09:24:23 +00:00
|
|
|
def commit
|
|
|
|
redirect_to 'https://github.com/' + @project.github_get_organization + '/' + @project.name + '/commit/' + params[:sha]
|
2012-08-29 15:58:58 +01:00
|
|
|
end
|
|
|
|
|
2016-03-20 09:24:23 +00:00
|
|
|
def diff
|
|
|
|
redirect_to 'https://github.com/' + @project.github_get_organization + '/' + @project.name + '/compare/' + params[:diff]
|
|
|
|
end
|
|
|
|
|
2012-03-07 21:34:49 +00:00
|
|
|
protected
|
2012-02-27 09:03:28 +00:00
|
|
|
|
2015-05-22 19:35:34 +01:00
|
|
|
def project_params
|
|
|
|
subject_params(Project)
|
|
|
|
end
|
|
|
|
|
2013-11-13 22:01:12 +00:00
|
|
|
def who_owns
|
|
|
|
@who_owns = (@project.try(:owner_type) == 'User' ? :me : :group)
|
|
|
|
end
|
|
|
|
|
2012-03-07 21:34:49 +00:00
|
|
|
def choose_owner
|
|
|
|
if params[:who_owns] == 'group'
|
|
|
|
Group.find(params[:owner_id])
|
|
|
|
else
|
|
|
|
current_user
|
2012-02-27 09:03:28 +00:00
|
|
|
end
|
2012-03-07 21:34:49 +00:00
|
|
|
end
|
2011-03-10 11:35:46 +00:00
|
|
|
end
|