diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-10-01 12:33:51 +0200 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-10-01 12:33:51 +0200 |
commit | 7c7b664c01a87817ce3f35fb6bdab2498cff4f5d (patch) | |
tree | 19f001c79fb1ac98625b477152372b8b1ec49783 /app/controllers | |
parent | 333463ddf280180d1878186160eb5a5e9c5c6e3e (diff) | |
parent | 1ca119930fc5f6125ca4d5db4e1a658d5df9dfcd (diff) | |
download | gitlab-ce-7c7b664c01a87817ce3f35fb6bdab2498cff4f5d.tar.gz |
Merge branch 'master' into flevour/gitlab-ce-project-path-insensitive-lookup
Diffstat (limited to 'app/controllers')
22 files changed, 232 insertions, 271 deletions
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 6092c79c254..00f41a10dd1 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -56,13 +56,19 @@ class Admin::UsersController < Admin::ApplicationController end def confirm - if user.confirm! + if user.confirm redirect_to :back, notice: "Successfully confirmed" else redirect_to :back, alert: "Error occurred. User was not confirmed" end end + def login_as + sign_in(user) + flash[:alert] = "Logged in as #{user.username}" + redirect_to root_path + end + def disable_two_factor user.disable_two_factor! redirect_to admin_user_path(user), diff --git a/app/controllers/ci/application_controller.rb b/app/controllers/ci/application_controller.rb index 8d8ff75ff72..d8227e632e4 100644 --- a/app/controllers/ci/application_controller.rb +++ b/app/controllers/ci/application_controller.rb @@ -38,7 +38,7 @@ module Ci end def authorize_manage_builds! - unless can?(current_user, :admin_project, gl_project) + unless can?(current_user, :manage_builds, gl_project) return page_404 end end diff --git a/app/controllers/ci/charts_controller.rb b/app/controllers/ci/charts_controller.rb deleted file mode 100644 index aa875e70987..00000000000 --- a/app/controllers/ci/charts_controller.rb +++ /dev/null @@ -1,24 +0,0 @@ -module Ci - class ChartsController < Ci::ApplicationController - before_action :authenticate_user! - before_action :project - before_action :authorize_access_project! - before_action :authorize_manage_project! - - layout 'ci/project' - - def show - @charts = {} - @charts[:week] = Ci::Charts::WeekChart.new(@project) - @charts[:month] = Ci::Charts::MonthChart.new(@project) - @charts[:year] = Ci::Charts::YearChart.new(@project) - @charts[:build_times] = Ci::Charts::BuildTime.new(@project) - end - - protected - - def project - @project = Ci::Project.find(params[:project_id]) - end - end -end diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb index b1f1c087b9e..e8788955eba 100644 --- a/app/controllers/ci/projects_controller.rb +++ b/app/controllers/ci/projects_controller.rb @@ -1,12 +1,10 @@ module Ci class ProjectsController < Ci::ApplicationController - PROJECTS_BATCH = 100 - - before_action :authenticate_user!, except: [:build, :badge, :index, :show] + before_action :authenticate_user!, except: [:build, :badge, :show] before_action :authenticate_public_page!, only: :show - before_action :project, only: [:build, :integration, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml] - before_action :authorize_access_project!, except: [:build, :badge, :index, :show, :new, :create, :disabled] - before_action :authorize_manage_project!, only: [:edit, :integration, :update, :destroy, :toggle_shared_runners, :dumped_yaml] + before_action :project, only: [:build, :show, :badge, :toggle_shared_runners, :dumped_yaml] + before_action :authorize_access_project!, except: [:build, :badge, :show, :new, :disabled] + before_action :authorize_manage_project!, only: [:toggle_shared_runners, :dumped_yaml] before_action :authenticate_token!, only: [:build] before_action :no_cache, only: [:badge] skip_before_action :check_enable_flag!, only: [:disabled] @@ -17,26 +15,6 @@ module Ci def disabled end - def index - @limit, @offset = (params[:limit] || PROJECTS_BATCH).to_i, (params[:offset] || 0).to_i - @page = @offset == 0 ? 1 : (@offset / @limit + 1) - - if current_user - @projects = ProjectListBuilder.new.execute(current_user, params[:search]) - - @projects = @projects.page(@page).per(@limit) - - @total_count = @projects.size - end - - respond_to do |format| - format.json do - pager_json("ci/projects/index", @total_count) - end - format.html - end - end - def show @ref = params[:ref] @@ -45,57 +23,6 @@ module Ci @commits = @commits.page(params[:page]).per(20) end - def integration - end - - def create - project_data = OpenStruct.new(JSON.parse(params["project"])) - - unless can?(current_user, :admin_project, ::Project.find(project_data.id)) - return redirect_to ci_root_path, alert: 'You have to have at least master role to enable CI for this project' - end - - @project = Ci::CreateProjectService.new.execute(current_user, project_data, ci_project_url(":project_id")) - - if @project.persisted? - redirect_to ci_project_path(@project, show_guide: true), notice: 'Project was successfully created.' - else - redirect_to :back, alert: 'Cannot save project' - end - end - - def edit - end - - def update - if project.update_attributes(project_params) - Ci::EventService.new.change_project_settings(current_user, project) - - redirect_to :back, notice: 'Project was successfully updated.' - else - render action: "edit" - end - end - - def destroy - project.gl_project.gitlab_ci_service.update_attributes(active: false) - project.destroy - - Ci::EventService.new.remove_project(current_user, project) - - redirect_to ci_projects_url - end - - def build - @commit = Ci::CreateCommitService.new.execute(@project, params.dup) - - if @commit && @commit.valid? - head 201 - else - head 400 - end - end - # Project status badge # Image with build status for sha or ref def badge @@ -106,7 +33,8 @@ module Ci def toggle_shared_runners project.toggle!(:shared_runners_enabled) - redirect_to :back + + redirect_to namespace_project_runners_path(project.gl_project.namespace, project.gl_project) end def dumped_yaml @@ -124,12 +52,5 @@ module Ci response.headers["Pragma"] = "no-cache" response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT" end - - def project_params - params.require(:project).permit(:path, :timeout, :timeout_in_minutes, :default_ref, :always_build, - :polling_interval, :public, :ssh_url_to_repo, :allow_git_fetch, :email_recipients, - :email_add_pusher, :email_only_broken_builds, :coverage_regex, :shared_runners_enabled, :token, - { variables_attributes: [:id, :key, :value, :_destroy] }) - end end end diff --git a/app/controllers/ci/runner_projects_controller.rb b/app/controllers/ci/runner_projects_controller.rb index a8bdd5bb362..97f01d40af5 100644 --- a/app/controllers/ci/runner_projects_controller.rb +++ b/app/controllers/ci/runner_projects_controller.rb @@ -11,10 +11,12 @@ module Ci return head(403) unless current_user.ci_authorized_runners.include?(@runner) + path = runners_path(@project.gl_project) + if @runner.assign_to(project, current_user) - redirect_to ci_project_runners_path(project) + redirect_to path else - redirect_to ci_project_runners_path(project), alert: 'Failed adding runner to project' + redirect_to path, alert: 'Failed adding runner to project' end end @@ -22,7 +24,7 @@ module Ci runner_project = project.runner_projects.find(params[:id]) runner_project.destroy - redirect_to ci_project_runners_path(project) + redirect_to runners_path(@project.gl_project) end private diff --git a/app/controllers/ci/runners_controller.rb b/app/controllers/ci/runners_controller.rb deleted file mode 100644 index a672370302b..00000000000 --- a/app/controllers/ci/runners_controller.rb +++ /dev/null @@ -1,73 +0,0 @@ -module Ci - class RunnersController < Ci::ApplicationController - before_action :authenticate_user! - before_action :project - before_action :set_runner, only: [:edit, :update, :destroy, :pause, :resume, :show] - before_action :authorize_access_project! - before_action :authorize_manage_project! - - layout 'ci/project' - - def index - @runners = @project.runners.order('id DESC') - @specific_runners = - Ci::Runner.specific.includes(:runner_projects). - where(Ci::RunnerProject.table_name => { project_id: current_user.authorized_projects } ). - where.not(id: @runners).order("#{Ci::Runner.table_name}.id DESC").page(params[:page]).per(20) - @shared_runners = Ci::Runner.shared.active - @shared_runners_count = @shared_runners.count(:all) - end - - def edit - end - - def update - if @runner.update_attributes(runner_params) - redirect_to edit_ci_project_runner_path(@project, @runner), notice: 'Runner was successfully updated.' - else - redirect_to edit_ci_project_runner_path(@project, @runner), alert: 'Runner was not updated.' - end - end - - def destroy - if @runner.only_for?(@project) - @runner.destroy - end - - redirect_to ci_project_runners_path(@project) - end - - def resume - if @runner.update_attributes(active: true) - redirect_to ci_project_runners_path(@project, @runner), notice: 'Runner was successfully updated.' - else - redirect_to ci_project_runners_path(@project, @runner), alert: 'Runner was not updated.' - end - end - - def pause - if @runner.update_attributes(active: false) - redirect_to ci_project_runners_path(@project, @runner), notice: 'Runner was successfully updated.' - else - redirect_to ci_project_runners_path(@project, @runner), alert: 'Runner was not updated.' - end - end - - def show - end - - protected - - def project - @project = Ci::Project.find(params[:project_id]) - end - - def set_runner - @runner ||= @project.runners.find(params[:id]) - end - - def runner_params - params.require(:runner).permit(:description, :tag_list, :contacted_at, :active) - end - end -end diff --git a/app/controllers/ci/triggers_controller.rb b/app/controllers/ci/triggers_controller.rb deleted file mode 100644 index a39cc5d3a56..00000000000 --- a/app/controllers/ci/triggers_controller.rb +++ /dev/null @@ -1,43 +0,0 @@ -module Ci - class TriggersController < Ci::ApplicationController - before_action :authenticate_user! - before_action :project - before_action :authorize_access_project! - before_action :authorize_manage_project! - - layout 'ci/project' - - def index - @triggers = @project.triggers - @trigger = Ci::Trigger.new - end - - def create - @trigger = @project.triggers.new - @trigger.save - - if @trigger.valid? - redirect_to ci_project_triggers_path(@project) - else - @triggers = @project.triggers.select(&:persisted?) - render :index - end - end - - def destroy - trigger.destroy - - redirect_to ci_project_triggers_path(@project) - end - - private - - def trigger - @trigger ||= @project.triggers.find(params[:id]) - end - - def project - @project = Ci::Project.find(params[:project_id]) - end - end -end diff --git a/app/controllers/ci/variables_controller.rb b/app/controllers/ci/variables_controller.rb deleted file mode 100644 index 9c6c775fde8..00000000000 --- a/app/controllers/ci/variables_controller.rb +++ /dev/null @@ -1,33 +0,0 @@ -module Ci - class VariablesController < Ci::ApplicationController - before_action :authenticate_user! - before_action :project - before_action :authorize_access_project! - before_action :authorize_manage_project! - - layout 'ci/project' - - def show - end - - def update - if project.update_attributes(project_params) - Ci::EventService.new.change_project_settings(current_user, project) - - redirect_to ci_project_variables_path(project), notice: 'Variables were successfully updated.' - else - render action: 'show' - end - end - - private - - def project - @project ||= Ci::Project.find(params[:project_id]) - end - - def project_params - params.require(:project).permit({ variables_attributes: [:id, :key, :value, :_destroy] }) - end - end -end diff --git a/app/controllers/help_controller.rb b/app/controllers/help_controller.rb index ad00948da51..55050615473 100644 --- a/app/controllers/help_controller.rb +++ b/app/controllers/help_controller.rb @@ -4,6 +4,11 @@ class HelpController < ApplicationController layout 'help' def index + @help_index = File.read(Rails.root.join('doc', 'README.md')) + + # Prefix Markdown links with `help/` unless they already have been + # See http://rubular.com/r/nwwhzH6Z8X + @help_index.gsub!(/(\]\()(?!help\/)([^\)\(]+)(\))/, '\1help/\2\3') end def show diff --git a/app/controllers/profiles/two_factor_auths_controller.rb b/app/controllers/profiles/two_factor_auths_controller.rb index f9af0871cf1..e6b99be37fb 100644 --- a/app/controllers/profiles/two_factor_auths_controller.rb +++ b/app/controllers/profiles/two_factor_auths_controller.rb @@ -9,7 +9,7 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController end def create - if current_user.valid_otp?(params[:pin_code]) + if current_user.validate_and_consume_otp!(params[:pin_code]) current_user.two_factor_enabled = true @codes = current_user.generate_otp_backup_codes! current_user.save! diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb index ee88d49b400..519d6d6127e 100644 --- a/app/controllers/projects/application_controller.rb +++ b/app/controllers/projects/application_controller.rb @@ -25,4 +25,14 @@ class Projects::ApplicationController < ApplicationController ) end end + + private + + def ci_enabled + return render_404 unless @project.gitlab_ci? + end + + def ci_project + @ci_project ||= @project.ensure_gitlab_ci_project + end end diff --git a/app/controllers/projects/ci_settings_controller.rb b/app/controllers/projects/ci_settings_controller.rb new file mode 100644 index 00000000000..a263242a850 --- /dev/null +++ b/app/controllers/projects/ci_settings_controller.rb @@ -0,0 +1,36 @@ +class Projects::CiSettingsController < Projects::ApplicationController + before_action :ci_project + before_action :authorize_admin_project! + + layout "project_settings" + + def edit + end + + def update + if ci_project.update_attributes(project_params) + Ci::EventService.new.change_project_settings(current_user, ci_project) + + redirect_to edit_namespace_project_ci_settings_path(project.namespace, project), notice: 'Project was successfully updated.' + else + render action: "edit" + end + end + + def destroy + ci_project.destroy + Ci::EventService.new.remove_project(current_user, ci_project) + project.gitlab_ci_service.update_attributes(active: false) + + redirect_to project_path(project), notice: "CI was disabled for this project" + end + + protected + + def project_params + params.require(:project).permit(:path, :timeout, :timeout_in_minutes, :default_ref, :always_build, + :polling_interval, :public, :ssh_url_to_repo, :allow_git_fetch, :email_recipients, + :email_add_pusher, :email_only_broken_builds, :coverage_regex, :shared_runners_enabled, :token, + { variables_attributes: [:id, :key, :value, :_destroy] }) + end +end diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 78d42d695b6..2fae5057138 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -22,6 +22,8 @@ class Projects::CommitController < Projects::ApplicationController commit_id: @commit.id } + @ci_commit = project.ci_commit(commit.sha) + respond_to do |format| format.html format.diff { render text: @commit.to_diff } diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb index d9b3adae95b..d15004f93a6 100644 --- a/app/controllers/projects/compare_controller.rb +++ b/app/controllers/projects/compare_controller.rb @@ -16,10 +16,12 @@ class Projects::CompareController < Projects::ApplicationController compare_result = CompareService.new. execute(@project, head_ref, @project, base_ref) - @commits = compare_result.commits - @diffs = compare_result.diffs - @commit = @commits.last - @line_notes = [] + if compare_result + @commits = compare_result.commits + @diffs = compare_result.diffs + @commit = @commits.last + @line_notes = [] + end end def create diff --git a/app/controllers/projects/graphs_controller.rb b/app/controllers/projects/graphs_controller.rb index 0b6f7f5c91e..418b92040bc 100644 --- a/app/controllers/projects/graphs_controller.rb +++ b/app/controllers/projects/graphs_controller.rb @@ -5,6 +5,7 @@ class Projects::GraphsController < Projects::ApplicationController before_action :require_non_empty_project before_action :assign_ref_vars before_action :authorize_download_code! + before_action :ci_enabled, only: :ci def show respond_to do |format| @@ -23,6 +24,16 @@ class Projects::GraphsController < Projects::ApplicationController @commits_per_month = @commits_graph.commits_per_month end + def ci + ci_project = @project.gitlab_ci_project + + @charts = {} + @charts[:week] = Ci::Charts::WeekChart.new(ci_project) + @charts[:month] = Ci::Charts::MonthChart.new(ci_project) + @charts[:year] = Ci::Charts::YearChart.new(ci_project) + @charts[:build_times] = Ci::Charts::BuildTime.new(ci_project) + end + private def fetch_graph diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index f3054881daf..7574842cd43 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -7,6 +7,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController before_action :closes_issues, only: [:edit, :update, :show, :diffs, :commits] before_action :validates_merge_request, only: [:show, :diffs, :commits] before_action :define_show_vars, only: [:show, :diffs, :commits] + before_action :ensure_ref_fetched, only: [:show, :commits, :diffs] # Allow read any merge_request before_action :authorize_read_merge_request! @@ -257,8 +258,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController @commits = @merge_request.commits @merge_request_diff = @merge_request.merge_request_diff - @source_branch = @merge_request.source_project.repository.find_branch(@merge_request.source_branch).try(:name) - + if @merge_request.locked_long_ago? @merge_request.unlock_mr @merge_request.close @@ -277,4 +277,10 @@ class Projects::MergeRequestsController < Projects::ApplicationController :state_event, :description, :task_num, label_ids: [] ) end + + # Make sure merge requests created before 8.0 + # have head file in refs/merge-requests/ + def ensure_ref_fetched + @merge_request.ensure_ref_fetched + end end diff --git a/app/controllers/projects/runners_controller.rb b/app/controllers/projects/runners_controller.rb new file mode 100644 index 00000000000..6cb6e3ef6d4 --- /dev/null +++ b/app/controllers/projects/runners_controller.rb @@ -0,0 +1,65 @@ +class Projects::RunnersController < Projects::ApplicationController + before_action :ci_project + before_action :set_runner, only: [:edit, :update, :destroy, :pause, :resume, :show] + before_action :authorize_admin_project! + + layout 'project_settings' + + def index + @runners = @ci_project.runners.order('id DESC') + @specific_runners = + Ci::Runner.specific.includes(:runner_projects). + where(Ci::RunnerProject.table_name => { project_id: current_user.authorized_projects } ). + where.not(id: @runners).order("#{Ci::Runner.table_name}.id DESC").page(params[:page]).per(20) + @shared_runners = Ci::Runner.shared.active + @shared_runners_count = @shared_runners.count(:all) + end + + def edit + end + + def update + if @runner.update_attributes(runner_params) + redirect_to runner_path(@runner), notice: 'Runner was successfully updated.' + else + redirect_to runner_path(@runner), alert: 'Runner was not updated.' + end + end + + def destroy + if @runner.only_for?(@ci_project) + @runner.destroy + end + + redirect_to runners_path(@project) + end + + def resume + if @runner.update_attributes(active: true) + redirect_to runner_path(@runner), notice: 'Runner was successfully updated.' + else + redirect_to runner_path(@runner), alert: 'Runner was not updated.' + end + end + + def pause + if @runner.update_attributes(active: false) + redirect_to runner_path(@runner), notice: 'Runner was successfully updated.' + else + redirect_to runner_path(@runner), alert: 'Runner was not updated.' + end + end + + def show + end + + protected + + def set_runner + @runner ||= @ci_project.runners.find(params[:id]) + end + + def runner_params + params.require(:runner).permit(:description, :tag_list, :contacted_at, :active) + end +end diff --git a/app/controllers/projects/triggers_controller.rb b/app/controllers/projects/triggers_controller.rb new file mode 100644 index 00000000000..782ebd01b05 --- /dev/null +++ b/app/controllers/projects/triggers_controller.rb @@ -0,0 +1,35 @@ +class Projects::TriggersController < Projects::ApplicationController + before_action :ci_project + before_action :authorize_admin_project! + + layout 'project_settings' + + def index + @triggers = @ci_project.triggers + @trigger = Ci::Trigger.new + end + + def create + @trigger = @ci_project.triggers.new + @trigger.save + + if @trigger.valid? + redirect_to namespace_project_triggers_path(@project.namespace, @project) + else + @triggers = @ci_project.triggers.select(&:persisted?) + render :index + end + end + + def destroy + trigger.destroy + + redirect_to namespace_project_triggers_path(@project.namespace, @project) + end + + private + + def trigger + @trigger ||= @ci_project.triggers.find(params[:id]) + end +end diff --git a/app/controllers/projects/variables_controller.rb b/app/controllers/projects/variables_controller.rb new file mode 100644 index 00000000000..d6561a45a70 --- /dev/null +++ b/app/controllers/projects/variables_controller.rb @@ -0,0 +1,25 @@ +class Projects::VariablesController < Projects::ApplicationController + before_action :ci_project + before_action :authorize_admin_project! + + layout 'project_settings' + + def show + end + + def update + if ci_project.update_attributes(project_params) + Ci::EventService.new.change_project_settings(current_user, ci_project) + + redirect_to namespace_project_variables_path(project.namespace, project), notice: 'Variables were successfully updated.' + else + render action: 'show' + end + end + + private + + def project_params + params.require(:project).permit({ variables_attributes: [:id, :key, :value, :_destroy] }) + end +end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index f4d1a828aab..213c2a7173b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -86,6 +86,10 @@ class ProjectsController < ApplicationController if @project.empty_repo? render 'projects/empty' else + if current_user + @membership = @project.project_member_by_id(current_user.id) + end + render :show end else diff --git a/app/controllers/root_controller.rb b/app/controllers/root_controller.rb index 54171ff67c5..ad04c646e1b 100644 --- a/app/controllers/root_controller.rb +++ b/app/controllers/root_controller.rb @@ -22,6 +22,10 @@ class RootController < Dashboard::ProjectsController when 'stars' flash.keep redirect_to starred_dashboard_projects_path + when 'project_activity' + redirect_to activity_dashboard_path + when 'starred_project_activity' + redirect_to activity_dashboard_path(filter: 'starred') else return end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index cfa565cd03e..1b60d3e27d0 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -99,7 +99,7 @@ class SessionsController < Devise::SessionsController end def valid_otp_attempt?(user) - user.valid_otp?(user_params[:otp_attempt]) || + user.validate_and_consume_otp!(user_params[:otp_attempt]) || user.invalidate_otp_backup_code!(user_params[:otp_attempt]) end |