2016-03-20 16:03:53 -04:00
|
|
|
class ProjectsController < Projects::ApplicationController
|
2016-09-16 15:15:39 -04:00
|
|
|
include IssuableCollections
|
2015-10-17 13:16:40 -04:00
|
|
|
include ExtractsPath
|
|
|
|
|
2016-11-07 09:13:31 -05:00
|
|
|
before_action :authenticate_user!, except: [:index, :show, :activity, :refs]
|
|
|
|
before_action :project, except: [:index, :new, :create]
|
|
|
|
before_action :repository, except: [:index, :new, :create]
|
2016-06-20 15:50:19 -04:00
|
|
|
before_action :assign_ref_vars, only: [:show], if: :repo_exists?
|
2016-08-23 20:22:30 -04:00
|
|
|
before_action :tree, only: [:show], if: [:repo_exists?, :project_view_files?]
|
2011-10-08 17:36:38 -04:00
|
|
|
|
|
|
|
# Authorize
|
2016-06-17 09:47:00 -04:00
|
|
|
before_action :authorize_admin_project!, only: [:edit, :update, :housekeeping, :download_export, :export, :remove_export, :generate_new_export]
|
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
|
|
|
|
2015-09-08 09:49:20 -04:00
|
|
|
def index
|
2015-09-08 10:14:14 -04:00
|
|
|
redirect_to(current_user ? root_path : explore_root_path)
|
2015-09-08 09:49:20 -04:00
|
|
|
end
|
|
|
|
|
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?
|
2016-10-14 13:27:58 -04:00
|
|
|
cookies[:issue_board_welcome_hidden] = { path: project_path(@project), value: nil, expires: Time.at(0) }
|
|
|
|
|
2015-01-24 13:02:58 -05:00
|
|
|
redirect_to(
|
2015-02-25 22:34:16 -05:00
|
|
|
project_path(@project),
|
2016-10-28 08:07:08 -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
|
2017-01-15 01:58:05 -05:00
|
|
|
result = ::Projects::UpdateService.new(@project, current_user, project_params).execute
|
2012-11-24 15:00:30 -05:00
|
|
|
|
2016-04-04 17:59:54 -04:00
|
|
|
# Refresh the repo in case anything changed
|
2017-01-15 01:58:05 -05:00
|
|
|
@repository = @project.repository
|
2016-04-04 17:59:54 -04:00
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
respond_to do |format|
|
2017-01-15 01:58:05 -05:00
|
|
|
if result[:status] == :success
|
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
|
2017-01-15 01:58:05 -05:00
|
|
|
redirect_to(edit_project_path(@project))
|
2015-01-24 13:02:58 -05:00
|
|
|
end
|
2011-10-14 17:05:41 -04:00
|
|
|
else
|
2015-04-30 13:06:18 -04:00
|
|
|
format.html { render 'edit' }
|
2011-10-14 17:05:41 -04:00
|
|
|
end
|
2016-06-30 07:20:15 -04:00
|
|
|
|
|
|
|
format.js
|
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-10-13 18:04:22 -04:00
|
|
|
return access_denied! unless can?(current_user, :change_namespace, @project)
|
|
|
|
|
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-10-13 06:24:44 -04:00
|
|
|
def remove_fork
|
2015-10-13 18:04:22 -04:00
|
|
|
return access_denied! unless can?(current_user, :remove_fork_project, @project)
|
|
|
|
|
2016-03-22 10:34:35 -04:00
|
|
|
if ::Projects::UnlinkForkService.new(@project, current_user).execute
|
2015-10-18 06:37:50 -04:00
|
|
|
flash[:notice] = 'The fork relationship has been removed.'
|
2015-10-13 06:24:44 -04:00
|
|
|
end
|
|
|
|
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
|
|
|
|
|
2016-01-22 14:13:37 -05:00
|
|
|
if @project.pending_delete?
|
2016-07-29 19:23:13 -04:00
|
|
|
flash[:alert] = "Project #{@project.name} queued for deletion."
|
2016-01-22 14:13:37 -05:00
|
|
|
end
|
|
|
|
|
2012-03-02 17:09:17 -05:00
|
|
|
respond_to do |format|
|
2012-06-01 02:42:02 -04:00
|
|
|
format.html do
|
2016-05-06 15:40:27 -04:00
|
|
|
@notification_setting = current_user.notification_settings_for(@project) if current_user
|
2016-09-16 15:15:39 -04:00
|
|
|
render_landing_page
|
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
|
|
|
|
2016-08-06 10:25:51 -04:00
|
|
|
::Projects::DestroyService.new(@project, current_user, {}).async_execute
|
2016-01-22 14:13:37 -05:00
|
|
|
flash[:alert] = "Project '#{@project.name}' will be deleted."
|
2011-10-08 17:36:38 -04:00
|
|
|
|
2015-11-26 02:11:35 -05:00
|
|
|
redirect_to dashboard_projects_path
|
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
|
|
|
|
2016-10-18 14:03:31 -04:00
|
|
|
def new_issue_address
|
|
|
|
return render_404 unless Gitlab::IncomingEmail.supports_issue_creation?
|
|
|
|
|
|
|
|
current_user.reset_incoming_email_token!
|
|
|
|
render json: { new_issue_address: @project.new_issue_address(current_user) }
|
|
|
|
end
|
|
|
|
|
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)
|
2015-10-18 06:37:50 -04:00
|
|
|
|
2014-10-19 17:20:55 -04:00
|
|
|
@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)
|
2015-10-18 06:37:50 -04:00
|
|
|
|
2014-10-19 17:20:55 -04:00
|
|
|
@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
|
2015-10-21 09:15:54 -04:00
|
|
|
|
|
|
|
def housekeeping
|
2016-03-15 06:03:43 -04:00
|
|
|
::Projects::HousekeepingService.new(@project).execute
|
|
|
|
|
|
|
|
redirect_to(
|
|
|
|
project_path(@project),
|
|
|
|
notice: "Housekeeping successfully started"
|
|
|
|
)
|
|
|
|
rescue ::Projects::HousekeepingService::LeaseTaken => ex
|
|
|
|
redirect_to(
|
|
|
|
edit_project_path(@project),
|
|
|
|
alert: ex.to_s
|
|
|
|
)
|
2015-10-21 09:15:54 -04:00
|
|
|
end
|
2013-11-29 11:10:59 -05:00
|
|
|
|
2016-04-14 12:01:21 -04:00
|
|
|
def export
|
2016-06-15 11:31:00 -04:00
|
|
|
@project.add_export_job(current_user: current_user)
|
2016-04-14 12:01:21 -04:00
|
|
|
|
|
|
|
redirect_to(
|
2016-04-15 09:38:34 -04:00
|
|
|
edit_project_path(@project),
|
2016-06-17 09:47:00 -04:00
|
|
|
notice: "Project export started. A download link will be sent by email."
|
2016-04-14 12:01:21 -04:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2016-04-15 09:38:34 -04:00
|
|
|
def download_export
|
2016-06-15 11:31:00 -04:00
|
|
|
export_project_path = @project.export_project_path
|
|
|
|
|
2016-05-04 04:57:09 -04:00
|
|
|
if export_project_path
|
|
|
|
send_file export_project_path, disposition: 'attachment'
|
|
|
|
else
|
2016-06-15 11:31:00 -04:00
|
|
|
redirect_to(
|
|
|
|
edit_project_path(@project),
|
|
|
|
alert: "Project export link has expired. Please generate a new export from your project settings."
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_export
|
|
|
|
if @project.remove_exports
|
2016-06-17 09:47:00 -04:00
|
|
|
flash[:notice] = "Project export has been deleted."
|
|
|
|
else
|
|
|
|
flash[:alert] = "Project export could not be deleted."
|
|
|
|
end
|
|
|
|
redirect_to(edit_project_path(@project))
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_new_export
|
|
|
|
if @project.remove_exports
|
|
|
|
export
|
2016-06-15 11:31:00 -04:00
|
|
|
else
|
|
|
|
redirect_to(
|
|
|
|
edit_project_path(@project),
|
|
|
|
alert: "Project export could not be deleted."
|
|
|
|
)
|
2016-05-04 04:57:09 -04:00
|
|
|
end
|
2016-04-15 09:38:34 -04:00
|
|
|
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: {
|
2015-12-18 16:06:48 -05:00
|
|
|
star_count: @project.star_count
|
2015-07-08 06:25:34 -04:00
|
|
|
}
|
2014-06-26 03:49:14 -04:00
|
|
|
end
|
|
|
|
|
2016-04-13 08:17:42 -04:00
|
|
|
def preview_markdown
|
2015-07-07 10:01:12 -04:00
|
|
|
text = params[:text]
|
2015-06-02 08:56:50 -04:00
|
|
|
|
2016-05-26 07:16:43 -04:00
|
|
|
ext = Gitlab::ReferenceExtractor.new(@project, current_user)
|
|
|
|
ext.analyze(text, author: current_user)
|
2015-06-02 08:56:50 -04:00
|
|
|
|
|
|
|
render json: {
|
|
|
|
body: view_context.markdown(text),
|
|
|
|
references: {
|
|
|
|
users: ext.users.map(&:username)
|
|
|
|
}
|
|
|
|
}
|
2014-10-15 03:21:21 -04:00
|
|
|
end
|
|
|
|
|
2016-06-07 09:40:21 -04:00
|
|
|
def refs
|
2016-11-03 08:16:15 -04:00
|
|
|
branches = BranchesFinder.new(@repository, params).execute.map(&:name)
|
2016-11-02 07:11:47 -04:00
|
|
|
|
2016-06-07 09:40:21 -04:00
|
|
|
options = {
|
2016-11-02 08:15:25 -04:00
|
|
|
'Branches' => branches.take(100),
|
2016-06-07 09:40:21 -04:00
|
|
|
}
|
|
|
|
|
2016-06-16 07:53:58 -04:00
|
|
|
unless @repository.tag_count.zero?
|
2016-11-03 08:16:15 -04:00
|
|
|
tags = TagsFinder.new(@repository, params).execute.map(&:name)
|
|
|
|
|
2016-11-02 08:15:25 -04:00
|
|
|
options['Tags'] = tags.take(100)
|
2016-06-08 08:29:18 -04:00
|
|
|
end
|
|
|
|
|
2016-06-07 09:40:21 -04:00
|
|
|
# If reference is commit id - we should add it to branch/tag selectbox
|
2016-06-20 06:37:27 -04:00
|
|
|
ref = Addressable::URI.unescape(params[:ref])
|
|
|
|
if ref && options.flatten(2).exclude?(ref) && ref =~ /\A[0-9a-zA-Z]{6,52}\z/
|
2016-06-16 07:53:58 -04:00
|
|
|
options['Commits'] = [ref]
|
2016-06-07 09:40:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
render json: options.to_json
|
|
|
|
end
|
|
|
|
|
2013-06-07 10:31:12 -04:00
|
|
|
private
|
|
|
|
|
2016-09-16 15:15:39 -04:00
|
|
|
# Render project landing depending of which features are available
|
|
|
|
# So if page is not availble in the list it renders the next page
|
|
|
|
#
|
|
|
|
# pages list order: repository readme, wiki home, issues list, customize workflow
|
|
|
|
def render_landing_page
|
|
|
|
if @project.feature_available?(:repository, current_user)
|
|
|
|
return render 'projects/no_repo' unless @project.repository_exists?
|
|
|
|
render 'projects/empty' if @project.empty_repo?
|
|
|
|
else
|
|
|
|
if @project.wiki_enabled?
|
2016-11-01 05:18:49 -04:00
|
|
|
@project_wiki = @project.wiki
|
|
|
|
@wiki_home = @project_wiki.find_page('home', params[:version_id])
|
2016-09-16 15:15:39 -04:00
|
|
|
elsif @project.feature_available?(:issues, current_user)
|
|
|
|
@issues = issues_collection
|
|
|
|
@issues = @issues.page(params[:page])
|
|
|
|
end
|
|
|
|
|
|
|
|
render :show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
2016-11-07 12:55:20 -05:00
|
|
|
params.require(:project)
|
|
|
|
.permit(project_params_ce)
|
|
|
|
end
|
2016-08-01 18:31:21 -04:00
|
|
|
|
2016-11-07 12:55:20 -05:00
|
|
|
def project_params_ce
|
|
|
|
[
|
|
|
|
:avatar,
|
|
|
|
:build_allow_git_fetch,
|
|
|
|
:build_coverage_regex,
|
|
|
|
:build_timeout_in_minutes,
|
2016-08-01 18:31:21 -04:00
|
|
|
:container_registry_enabled,
|
2016-11-07 12:55:20 -05:00
|
|
|
:default_branch,
|
|
|
|
:description,
|
|
|
|
:import_url,
|
|
|
|
:issues_tracker,
|
|
|
|
:issues_tracker_id,
|
|
|
|
:last_activity_at,
|
|
|
|
:lfs_enabled,
|
|
|
|
:name,
|
|
|
|
:namespace_id,
|
2016-09-16 07:02:42 -04:00
|
|
|
:only_allow_merge_if_all_discussions_are_resolved,
|
2016-11-07 12:55:20 -05:00
|
|
|
:only_allow_merge_if_build_succeeds,
|
|
|
|
:path,
|
|
|
|
:public_builds,
|
|
|
|
:request_access_enabled,
|
|
|
|
:runners_token,
|
|
|
|
:tag_list,
|
|
|
|
:visibility_level,
|
|
|
|
|
|
|
|
project_feature_attributes: %i[
|
|
|
|
builds_access_level
|
|
|
|
issues_access_level
|
|
|
|
merge_requests_access_level
|
|
|
|
repository_access_level
|
|
|
|
snippets_access_level
|
|
|
|
wiki_access_level
|
|
|
|
]
|
|
|
|
]
|
2014-06-26 07:30:07 -04:00
|
|
|
end
|
2015-01-23 19:17:27 -05:00
|
|
|
|
2015-10-18 05:22:33 -04:00
|
|
|
def repo_exists?
|
2016-09-23 03:42:07 -04:00
|
|
|
project.repository_exists? && !project.empty_repo? && project.repo
|
|
|
|
|
|
|
|
rescue Gitlab::Git::Repository::NoRepository
|
|
|
|
project.repository.expire_exists_cache
|
|
|
|
|
|
|
|
false
|
2015-10-18 05:22:33 -04:00
|
|
|
end
|
|
|
|
|
2016-06-20 15:50:19 -04:00
|
|
|
def project_view_files?
|
|
|
|
current_user && current_user.project_view == 'files'
|
|
|
|
end
|
|
|
|
|
2016-06-20 15:41:46 -04:00
|
|
|
# Override extract_ref from ExtractsPath, which returns the branch and file path
|
2015-10-19 05:40:13 -04:00
|
|
|
# for the blob/tree, which in this case is just the root of the default branch.
|
2016-06-20 15:41:46 -04:00
|
|
|
# This way we avoid to access the repository.ref_names.
|
|
|
|
def extract_ref(_id)
|
|
|
|
[get_id, '']
|
|
|
|
end
|
|
|
|
|
|
|
|
# Override get_id from ExtractsPath in this case is just the root of the default branch.
|
2015-10-17 13:16:40 -04:00
|
|
|
def get_id
|
|
|
|
project.repository.root_ref
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|