2013-09-25 07:05:35 -04:00
|
|
|
class ProjectsController < ApplicationController
|
2015-02-24 11:02:11 -05:00
|
|
|
prepend_before_filter :render_go_import, only: [:show]
|
2015-07-20 06:54:56 -04:00
|
|
|
skip_before_action :authenticate_user!, only: [:show, :activity]
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :project, except: [:new, :create]
|
|
|
|
before_action :repository, except: [:new, :create]
|
2011-10-08 17:36:38 -04:00
|
|
|
|
|
|
|
# Authorize
|
2015-04-16 08:03:37 -04:00
|
|
|
before_action :authorize_admin_project!, only: [:edit, :update, :destroy, :transfer, :archive, :unarchive]
|
2015-07-07 10:01:12 -04:00
|
|
|
before_action :event_filter, only: [:show, :activity]
|
2011-10-15 11:51:58 -04:00
|
|
|
|
2015-04-30 13:06:18 -04:00
|
|
|
layout :determine_layout
|
2012-09-26 16:24:52 -04:00
|
|
|
|
2011-10-14 17:05:41 -04:00
|
|
|
def new
|
|
|
|
@project = Project.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2015-04-30 13:06:18 -04:00
|
|
|
render 'edit'
|
2011-10-14 17:05:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2014-06-26 07:30:07 -04:00
|
|
|
@project = ::Projects::CreateService.new(current_user, project_params).execute
|
2011-10-14 17:05:41 -04:00
|
|
|
|
2014-11-29 14:34:18 -05:00
|
|
|
if @project.saved?
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to(
|
2015-02-25 22:34:16 -05:00
|
|
|
project_path(@project),
|
2015-07-29 18:06:16 -04:00
|
|
|
notice: "Project '#{@project.name}' was successfully created."
|
2015-01-24 13:02:58 -05:00
|
|
|
)
|
2014-11-29 14:34:18 -05:00
|
|
|
else
|
|
|
|
render 'new'
|
2011-10-14 17:05:41 -04:00
|
|
|
end
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
|
2011-10-14 17:05:41 -04:00
|
|
|
def update
|
2014-06-26 07:30:07 -04:00
|
|
|
status = ::Projects::UpdateService.new(@project, current_user, project_params).execute
|
2012-11-24 15:00:30 -05:00
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
respond_to do |format|
|
2012-11-28 23:29:11 -05:00
|
|
|
if status
|
2015-07-29 18:06:16 -04:00
|
|
|
flash[:notice] = "Project '#{@project.name}' was successfully updated."
|
2015-01-24 13:02:58 -05:00
|
|
|
format.html do
|
|
|
|
redirect_to(
|
2015-02-25 22:34:16 -05:00
|
|
|
edit_project_path(@project),
|
2015-07-29 18:06:16 -04:00
|
|
|
notice: "Project '#{@project.name}' was successfully updated."
|
2015-01-24 13:02:58 -05:00
|
|
|
)
|
|
|
|
end
|
2011-10-26 09:46:25 -04:00
|
|
|
format.js
|
2011-10-14 17:05:41 -04:00
|
|
|
else
|
2015-04-30 13:06:18 -04:00
|
|
|
format.html { render 'edit' }
|
2011-10-26 09:46:25 -04:00
|
|
|
format.js
|
2011-10-14 17:05:41 -04:00
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
2013-03-25 04:48:30 -04:00
|
|
|
end
|
2012-12-13 11:42:15 -05:00
|
|
|
|
2013-03-25 04:48:30 -04:00
|
|
|
def transfer
|
2015-07-02 08:31:25 -04:00
|
|
|
namespace = Namespace.find_by(id: params[:new_namespace_id])
|
|
|
|
::Projects::TransferService.new(project, current_user).execute(namespace)
|
|
|
|
|
|
|
|
if @project.errors[:new_namespace].present?
|
|
|
|
flash[:alert] = @project.errors[:new_namespace].first
|
2014-12-15 08:10:56 -05:00
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
|
|
|
|
2015-07-07 10:01:12 -04:00
|
|
|
def activity
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.json do
|
|
|
|
load_events
|
|
|
|
pager_json('events/_events', @events.count)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
def show
|
2014-03-13 04:27:05 -04:00
|
|
|
if @project.import_in_progress?
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to namespace_project_import_path(@project.namespace, @project)
|
2014-03-13 04:27:05 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2012-03-02 17:09:17 -05:00
|
|
|
respond_to do |format|
|
2012-06-01 02:42:02 -04:00
|
|
|
format.html do
|
2014-11-29 17:50:25 -05:00
|
|
|
if @project.repository_exists?
|
|
|
|
if @project.empty_repo?
|
2015-04-30 13:06:18 -04:00
|
|
|
render 'projects/empty'
|
2014-11-29 17:50:25 -05:00
|
|
|
else
|
2015-04-30 13:06:18 -04:00
|
|
|
render :show
|
2014-11-29 17:50:25 -05:00
|
|
|
end
|
2013-03-26 10:14:57 -04:00
|
|
|
else
|
2015-04-30 13:06:18 -04:00
|
|
|
render 'projects/no_repo'
|
2012-12-07 16:05:17 -05:00
|
|
|
end
|
2012-03-02 17:09:17 -05:00
|
|
|
end
|
2014-03-12 13:25:48 -04:00
|
|
|
|
2015-04-21 10:57:01 -04:00
|
|
|
format.atom do
|
|
|
|
load_events
|
|
|
|
render layout: false
|
|
|
|
end
|
2014-03-12 13:25:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
def destroy
|
2014-10-19 17:20:55 -04:00
|
|
|
return access_denied! unless can?(current_user, :remove_project, @project)
|
2012-12-04 22:14:05 -05:00
|
|
|
|
2014-06-17 16:49:17 -04:00
|
|
|
::Projects::DestroyService.new(@project, current_user, {}).execute
|
2015-07-29 18:06:16 -04:00
|
|
|
flash[:alert] = "Project '#{@project.name}' was deleted."
|
2011-10-08 17:36:38 -04:00
|
|
|
|
2015-06-03 05:50:08 -04:00
|
|
|
if request.referer.include?('/admin')
|
|
|
|
redirect_to admin_namespaces_projects_path
|
|
|
|
else
|
|
|
|
redirect_to dashboard_path
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
2015-06-03 05:50:08 -04:00
|
|
|
rescue Projects::DestroyService::DestroyError => ex
|
|
|
|
redirect_to edit_project_path(@project), alert: ex.message
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|
2013-03-19 11:37:50 -04:00
|
|
|
|
2013-05-03 11:39:18 -04:00
|
|
|
def autocomplete_sources
|
2014-03-25 07:40:49 -04:00
|
|
|
note_type = params['type']
|
|
|
|
note_id = params['type_id']
|
2015-01-22 20:51:35 -05:00
|
|
|
autocomplete = ::Projects::AutocompleteService.new(@project)
|
2015-02-04 11:10:39 -05:00
|
|
|
participants = ::Projects::ParticipantsService.new(@project, current_user).execute(note_type, note_id)
|
2015-01-22 20:51:35 -05:00
|
|
|
|
2013-05-03 11:39:18 -04:00
|
|
|
@suggestions = {
|
2015-01-23 19:17:27 -05:00
|
|
|
emojis: autocomplete_emojis,
|
2015-01-22 20:51:35 -05:00
|
|
|
issues: autocomplete.issues,
|
|
|
|
mergerequests: autocomplete.merge_requests,
|
2014-06-23 09:44:49 -04:00
|
|
|
members: participants
|
2013-05-03 11:39:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
respond_to do |format|
|
2015-01-23 17:38:20 -05:00
|
|
|
format.json { render json: @suggestions }
|
2013-05-03 11:39:18 -04:00
|
|
|
end
|
|
|
|
end
|
2013-06-07 10:31:12 -04:00
|
|
|
|
2013-11-29 11:10:59 -05:00
|
|
|
def archive
|
2014-10-19 17:20:55 -04:00
|
|
|
return access_denied! unless can?(current_user, :archive_project, @project)
|
|
|
|
@project.archive!
|
2013-11-29 11:10:59 -05:00
|
|
|
|
|
|
|
respond_to do |format|
|
2015-02-25 22:34:16 -05:00
|
|
|
format.html { redirect_to project_path(@project) }
|
2013-11-29 11:10:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def unarchive
|
2014-10-19 17:20:55 -04:00
|
|
|
return access_denied! unless can?(current_user, :archive_project, @project)
|
|
|
|
@project.unarchive!
|
2013-11-29 11:10:59 -05:00
|
|
|
|
|
|
|
respond_to do |format|
|
2015-02-25 22:34:16 -05:00
|
|
|
format.html { redirect_to project_path(@project) }
|
2013-11-29 11:10:59 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-06-26 03:49:14 -04:00
|
|
|
def toggle_star
|
|
|
|
current_user.toggle_star(@project)
|
2014-07-14 09:17:59 -04:00
|
|
|
@project.reload
|
2015-07-08 06:25:34 -04:00
|
|
|
|
|
|
|
render json: {
|
|
|
|
html: view_to_html_string("projects/buttons/_star")
|
|
|
|
}
|
2014-06-26 03:49:14 -04:00
|
|
|
end
|
|
|
|
|
2014-10-15 03:21:21 -04:00
|
|
|
def markdown_preview
|
2015-07-07 10:01:12 -04:00
|
|
|
text = params[:text]
|
2015-06-02 08:56:50 -04:00
|
|
|
|
|
|
|
ext = Gitlab::ReferenceExtractor.new(@project, current_user)
|
|
|
|
ext.analyze(text)
|
|
|
|
|
|
|
|
render json: {
|
|
|
|
body: view_context.markdown(text),
|
|
|
|
references: {
|
|
|
|
users: ext.users.map(&:username)
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 03:21:21 -04:00
|
|
|
end
|
|
|
|
|
2013-06-07 10:31:12 -04:00
|
|
|
private
|
|
|
|
|
2015-04-30 13:06:18 -04:00
|
|
|
def determine_layout
|
|
|
|
if [:new, :create].include?(action_name.to_sym)
|
|
|
|
'application'
|
|
|
|
elsif [:edit, :update].include?(action_name.to_sym)
|
|
|
|
'project_settings'
|
|
|
|
else
|
|
|
|
'project'
|
|
|
|
end
|
2013-09-24 15:14:28 -04:00
|
|
|
end
|
2014-06-26 07:30:07 -04:00
|
|
|
|
2015-04-21 10:57:01 -04:00
|
|
|
def load_events
|
|
|
|
@events = @project.events.recent
|
|
|
|
@events = event_filter.apply_filter(@events).with_associations
|
|
|
|
limit = (params[:limit] || 20).to_i
|
|
|
|
@events = @events.limit(limit).offset(params[:offset] || 0)
|
|
|
|
end
|
|
|
|
|
2014-06-26 07:30:07 -04:00
|
|
|
def project_params
|
|
|
|
params.require(:project).permit(
|
2014-07-29 11:23:18 -04:00
|
|
|
:name, :path, :description, :issues_tracker, :tag_list,
|
2014-07-21 15:47:41 -04:00
|
|
|
:issues_enabled, :merge_requests_enabled, :snippets_enabled, :issues_tracker_id, :default_branch,
|
2015-01-19 15:37:20 -05:00
|
|
|
:wiki_enabled, :visibility_level, :import_url, :last_activity_at, :namespace_id, :avatar
|
2014-06-26 07:30:07 -04:00
|
|
|
)
|
|
|
|
end
|
2015-01-23 19:17:27 -05:00
|
|
|
|
|
|
|
def autocomplete_emojis
|
2015-03-11 19:05:01 -04:00
|
|
|
Rails.cache.fetch("autocomplete-emoji-#{Gemojione::VERSION}") do
|
|
|
|
Emoji.emojis.map do |name, emoji|
|
2015-01-23 19:17:27 -05:00
|
|
|
{
|
2015-03-11 19:05:01 -04:00
|
|
|
name: name,
|
|
|
|
path: view_context.image_url("emoji/#{emoji["unicode"]}.png")
|
2015-01-23 19:17:27 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-02-24 11:02:11 -05: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 17:36:38 -04:00
|
|
|
end
|