2013-09-25 11:05:35 +00:00
|
|
|
class ProjectsController < ApplicationController
|
2015-02-24 16:02:11 +00:00
|
|
|
prepend_before_filter :render_go_import, only: [:show]
|
2013-09-24 12:58:39 +00:00
|
|
|
skip_before_filter :authenticate_user!, only: [:show]
|
2013-09-25 11:05:35 +00:00
|
|
|
before_filter :project, except: [:new, :create]
|
|
|
|
before_filter :repository, except: [:new, :create]
|
2011-10-08 21:36:38 +00:00
|
|
|
|
|
|
|
# Authorize
|
2014-11-29 22:50:25 +00:00
|
|
|
before_filter :authorize_admin_project!, only: [:edit, :update, :destroy, :transfer, :archive, :unarchive]
|
2015-02-18 08:16:42 +00:00
|
|
|
before_filter :set_title, only: [:new, :create]
|
|
|
|
before_filter :event_filter, only: :show
|
2011-10-15 15:51:58 +00:00
|
|
|
|
2013-06-10 18:40:23 +00:00
|
|
|
layout 'navless', only: [:new, :create, :fork]
|
2012-09-26 20:24:52 +00:00
|
|
|
|
2011-10-14 21:05:41 +00:00
|
|
|
def new
|
|
|
|
@project = Project.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2015-01-19 20:37:20 +00:00
|
|
|
render 'edit', layout: 'project_settings'
|
2011-10-14 21:05:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-06-26 11:30:07 +00:00
|
|
|
@project = ::Projects::CreateService.new(current_user, project_params).execute
|
2011-10-14 21:05:41 +00:00
|
|
|
|
2014-11-29 19:34:18 +00:00
|
|
|
if @project.saved?
|
2015-01-24 18:02:58 +00:00
|
|
|
redirect_to(
|
2015-02-26 03:34:16 +00:00
|
|
|
project_path(@project),
|
2015-01-24 18:02:58 +00:00
|
|
|
notice: 'Project was successfully created.'
|
|
|
|
)
|
2014-11-29 19:34:18 +00:00
|
|
|
else
|
|
|
|
render 'new'
|
2011-10-14 21:05:41 +00:00
|
|
|
end
|
|
|
|
end
|
2011-10-08 21:36:38 +00:00
|
|
|
|
2011-10-14 21:05:41 +00:00
|
|
|
def update
|
2014-06-26 11:30:07 +00:00
|
|
|
status = ::Projects::UpdateService.new(@project, current_user, project_params).execute
|
2012-11-24 20:00:30 +00:00
|
|
|
|
2011-10-08 21:36:38 +00:00
|
|
|
respond_to do |format|
|
2012-11-29 04:29:11 +00:00
|
|
|
if status
|
2012-11-24 20:00:30 +00:00
|
|
|
flash[:notice] = 'Project was successfully updated.'
|
2015-01-24 18:02:58 +00:00
|
|
|
format.html do
|
|
|
|
redirect_to(
|
2015-02-26 03:34:16 +00:00
|
|
|
edit_project_path(@project),
|
2015-01-24 18:02:58 +00:00
|
|
|
notice: 'Project was successfully updated.'
|
|
|
|
)
|
|
|
|
end
|
2011-10-26 13:46:25 +00:00
|
|
|
format.js
|
2011-10-14 21:05:41 +00:00
|
|
|
else
|
2015-01-19 20:37:20 +00:00
|
|
|
format.html { render 'edit', layout: 'project_settings' }
|
2011-10-26 13:46:25 +00:00
|
|
|
format.js
|
2011-10-14 21:05:41 +00:00
|
|
|
end
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|
2013-03-25 08:48:30 +00:00
|
|
|
end
|
2012-12-13 16:42:15 +00:00
|
|
|
|
2013-03-25 08:48:30 +00:00
|
|
|
def transfer
|
2015-01-24 18:02:58 +00:00
|
|
|
transfer_params = params.permit(:new_namespace_id)
|
|
|
|
::Projects::TransferService.new(project, current_user, transfer_params).execute
|
2014-12-15 13:10:56 +00:00
|
|
|
if @project.errors[:namespace_id].present?
|
|
|
|
flash[:alert] = @project.errors[:namespace_id].first
|
|
|
|
end
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2014-03-13 08:27:05 +00:00
|
|
|
if @project.import_in_progress?
|
2015-01-24 18:02:58 +00:00
|
|
|
redirect_to namespace_project_import_path(@project.namespace, @project)
|
2014-03-13 08:27:05 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-03-01 20:43:04 +00:00
|
|
|
limit = (params[:limit] || 20).to_i
|
2012-03-02 22:09:17 +00:00
|
|
|
|
2014-07-15 10:00:51 +00:00
|
|
|
@show_star = !(current_user && current_user.starred?(@project))
|
2014-07-14 13:17:59 +00:00
|
|
|
|
2012-03-02 22:09:17 +00:00
|
|
|
respond_to do |format|
|
2012-06-01 06:42:02 +00:00
|
|
|
format.html do
|
2014-11-29 22:50:25 +00:00
|
|
|
if @project.repository_exists?
|
|
|
|
if @project.empty_repo?
|
2015-01-19 20:37:20 +00:00
|
|
|
render 'projects/empty', layout: user_layout
|
2014-11-29 22:50:25 +00:00
|
|
|
else
|
|
|
|
@last_push = current_user.recent_push(@project.id) if current_user
|
|
|
|
render :show, layout: user_layout
|
|
|
|
end
|
2013-03-26 14:14:57 +00:00
|
|
|
else
|
2015-01-19 20:37:20 +00:00
|
|
|
render 'projects/no_repo', layout: user_layout
|
2012-12-07 21:05:17 +00:00
|
|
|
end
|
2012-03-02 22:09:17 +00:00
|
|
|
end
|
2014-03-12 17:25:48 +00:00
|
|
|
|
2015-02-18 08:16:42 +00:00
|
|
|
format.json do
|
|
|
|
@events = @project.events.recent
|
2015-02-18 17:38:46 +00:00
|
|
|
@events = event_filter.apply_filter(@events).with_associations
|
2015-02-18 08:16:42 +00:00
|
|
|
@events = @events.limit(limit).offset(params[:offset] || 0)
|
|
|
|
pager_json('events/_events', @events.count)
|
|
|
|
end
|
2014-03-12 17:25:48 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-08 21:36:38 +00:00
|
|
|
def destroy
|
2014-10-19 21:20:55 +00:00
|
|
|
return access_denied! unless can?(current_user, :remove_project, @project)
|
2012-12-05 03:14:05 +00:00
|
|
|
|
2014-06-17 20:49:17 +00:00
|
|
|
::Projects::DestroyService.new(@project, current_user, {}).execute
|
2011-10-08 21:36:38 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
2014-08-29 22:56:26 +00:00
|
|
|
format.html do
|
2015-01-19 20:37:20 +00:00
|
|
|
flash[:alert] = 'Project deleted.'
|
2014-09-05 22:35:46 +00:00
|
|
|
|
2015-01-19 20:37:20 +00:00
|
|
|
if request.referer.include?('/admin')
|
2015-02-24 00:19:03 +00:00
|
|
|
redirect_to admin_namespaces_projects_path
|
2014-09-05 22:35:46 +00:00
|
|
|
else
|
|
|
|
redirect_to projects_dashboard_path
|
|
|
|
end
|
2014-08-29 22:56:26 +00:00
|
|
|
end
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|
|
|
|
end
|
2013-03-19 15:37:50 +00:00
|
|
|
|
2013-05-03 15:39:18 +00:00
|
|
|
def autocomplete_sources
|
2014-03-25 11:40:49 +00:00
|
|
|
note_type = params['type']
|
|
|
|
note_id = params['type_id']
|
2015-01-23 01:51:35 +00:00
|
|
|
autocomplete = ::Projects::AutocompleteService.new(@project)
|
2015-02-04 16:10:39 +00:00
|
|
|
participants = ::Projects::ParticipantsService.new(@project, current_user).execute(note_type, note_id)
|
2015-01-23 01:51:35 +00:00
|
|
|
|
2013-05-03 15:39:18 +00:00
|
|
|
@suggestions = {
|
2015-01-24 00:17:27 +00:00
|
|
|
emojis: autocomplete_emojis,
|
2015-01-23 01:51:35 +00:00
|
|
|
issues: autocomplete.issues,
|
|
|
|
mergerequests: autocomplete.merge_requests,
|
2014-06-23 13:44:49 +00:00
|
|
|
members: participants
|
2013-05-03 15:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
respond_to do |format|
|
2015-01-23 22:38:20 +00:00
|
|
|
format.json { render json: @suggestions }
|
2013-05-03 15:39:18 +00:00
|
|
|
end
|
|
|
|
end
|
2013-06-07 14:31:12 +00:00
|
|
|
|
2013-11-29 16:10:59 +00:00
|
|
|
def archive
|
2014-10-19 21:20:55 +00:00
|
|
|
return access_denied! unless can?(current_user, :archive_project, @project)
|
|
|
|
@project.archive!
|
2013-11-29 16:10:59 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
2015-02-26 03:34:16 +00:00
|
|
|
format.html { redirect_to project_path(@project) }
|
2013-11-29 16:10:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unarchive
|
2014-10-19 21:20:55 +00:00
|
|
|
return access_denied! unless can?(current_user, :archive_project, @project)
|
|
|
|
@project.unarchive!
|
2013-11-29 16:10:59 +00:00
|
|
|
|
|
|
|
respond_to do |format|
|
2015-02-26 03:34:16 +00:00
|
|
|
format.html { redirect_to project_path(@project) }
|
2013-11-29 16:10:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-26 07:49:14 +00:00
|
|
|
def toggle_star
|
|
|
|
current_user.toggle_star(@project)
|
2014-07-14 13:17:59 +00:00
|
|
|
@project.reload
|
2014-06-26 07:49:14 +00:00
|
|
|
render json: { star_count: @project.star_count }
|
|
|
|
end
|
|
|
|
|
2014-10-15 07:21:21 +00:00
|
|
|
def markdown_preview
|
|
|
|
render text: view_context.markdown(params[:md_text])
|
|
|
|
end
|
|
|
|
|
2013-06-07 14:31:12 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def set_title
|
|
|
|
@title = 'New Project'
|
|
|
|
end
|
2013-09-24 19:14:28 +00:00
|
|
|
|
|
|
|
def user_layout
|
2015-01-19 20:37:20 +00:00
|
|
|
current_user ? 'projects' : 'public_projects'
|
2013-09-24 19:14:28 +00:00
|
|
|
end
|
2014-06-26 11:30:07 +00:00
|
|
|
|
|
|
|
def project_params
|
|
|
|
params.require(:project).permit(
|
2014-07-29 15:23:18 +00:00
|
|
|
:name, :path, :description, :issues_tracker, :tag_list,
|
2014-07-21 19:47:41 +00:00
|
|
|
:issues_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id, :default_branch,
|
2015-01-19 20:37:20 +00:00
|
|
|
:wiki_enabled, :visibility_level, :import_url, :last_activity_at, :namespace_id, :avatar
|
2014-06-26 11:30:07 +00:00
|
|
|
)
|
|
|
|
end
|
2015-01-24 00:17:27 +00:00
|
|
|
|
|
|
|
def autocomplete_emojis
|
|
|
|
Rails.cache.fetch("autocomplete-emoji-#{Emoji::VERSION}") do
|
|
|
|
Emoji.names.map do |e|
|
|
|
|
{
|
|
|
|
name: e,
|
|
|
|
path: view_context.image_url("emoji/#{e}.png")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-02-24 16:02:11 +00:00
|
|
|
|
|
|
|
def render_go_import
|
|
|
|
return unless params["go-get"] == "1"
|
|
|
|
|
|
|
|
@namespace = params[:namespace_id]
|
|
|
|
@id = params[:project_id] || params[:id]
|
|
|
|
@id = @id.gsub(/\.git\Z/, "")
|
|
|
|
|
|
|
|
render "go_import", layout: false
|
|
|
|
end
|
2011-10-08 21:36:38 +00:00
|
|
|
end
|