diff options
Diffstat (limited to 'app/controllers')
29 files changed, 1024 insertions, 11 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ef1170e16da..54d15b7d7c1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,9 +1,13 @@ require 'gon' class ApplicationController < ActionController::Base + def self.railtie_helpers_paths + "app/helpers/gitlab" + end + include Gitlab::CurrentSettings - include GitlabRoutingHelper - include PageLayoutHelper + include Gitlab::GitlabRoutingHelper + include Gitlab::PageLayoutHelper PER_PAGE = 20 @@ -133,9 +137,6 @@ class ApplicationController < ActionController::Base def repository @repository ||= project.repository - rescue Grit::NoSuchPathError => e - log_exception(e) - nil end def authorize_project!(action) diff --git a/app/controllers/ci/admin/application_controller.rb b/app/controllers/ci/admin/application_controller.rb new file mode 100644 index 00000000000..430fae14c7d --- /dev/null +++ b/app/controllers/ci/admin/application_controller.rb @@ -0,0 +1,10 @@ +module Ci + module Admin + class ApplicationController < Ci::ApplicationController + before_filter :authenticate_user! + before_filter :authenticate_admin! + + layout "ci/admin" + end + end +end diff --git a/app/controllers/ci/admin/application_settings_controller.rb b/app/controllers/ci/admin/application_settings_controller.rb new file mode 100644 index 00000000000..71e253fac67 --- /dev/null +++ b/app/controllers/ci/admin/application_settings_controller.rb @@ -0,0 +1,31 @@ +module Ci + class Admin::ApplicationSettingsController < Ci::Admin::ApplicationController + before_action :set_application_setting + + def show + end + + def update + if @application_setting.update_attributes(application_setting_params) + redirect_to ci_admin_application_settings_path, + notice: 'Application settings saved successfully' + else + render :show + end + end + + private + + def set_application_setting + @application_setting = Ci::ApplicationSetting.current + @application_setting ||= Ci::ApplicationSetting.create_from_defaults + end + + def application_setting_params + params.require(:application_setting).permit( + :all_broken_builds, + :add_pusher, + ) + end + end +end diff --git a/app/controllers/ci/admin/builds_controller.rb b/app/controllers/ci/admin/builds_controller.rb new file mode 100644 index 00000000000..8fc776dd98e --- /dev/null +++ b/app/controllers/ci/admin/builds_controller.rb @@ -0,0 +1,12 @@ +module Ci + class Admin::BuildsController < Ci::Admin::ApplicationController + def index + @scope = params[:scope] + @builds = Ci::Build.order('created_at DESC').page(params[:page]).per(30) + + if ["pending", "running"].include? @scope + @builds = @builds.send(@scope) + end + end + end +end diff --git a/app/controllers/ci/admin/events_controller.rb b/app/controllers/ci/admin/events_controller.rb new file mode 100644 index 00000000000..5939efff980 --- /dev/null +++ b/app/controllers/ci/admin/events_controller.rb @@ -0,0 +1,9 @@ +module Ci + class Admin::EventsController < Ci::Admin::ApplicationController + EVENTS_PER_PAGE = 50 + + def index + @events = Ci::Event.admin.order('created_at DESC').page(params[:page]).per(EVENTS_PER_PAGE) + end + end +end diff --git a/app/controllers/ci/admin/projects_controller.rb b/app/controllers/ci/admin/projects_controller.rb new file mode 100644 index 00000000000..5bbd0ce7396 --- /dev/null +++ b/app/controllers/ci/admin/projects_controller.rb @@ -0,0 +1,19 @@ +module Ci + class Admin::ProjectsController < Ci::Admin::ApplicationController + def index + @projects = Ci::Project.ordered_by_last_commit_date.page(params[:page]).per(30) + end + + def destroy + project.destroy + + redirect_to ci_projects_url + end + + protected + + def project + @project ||= Ci::Project.find(params[:id]) + end + end +end diff --git a/app/controllers/ci/admin/runner_projects_controller.rb b/app/controllers/ci/admin/runner_projects_controller.rb new file mode 100644 index 00000000000..e7de6eb12ca --- /dev/null +++ b/app/controllers/ci/admin/runner_projects_controller.rb @@ -0,0 +1,34 @@ +module Ci + class Admin::RunnerProjectsController < Ci::Admin::ApplicationController + layout 'ci/project' + + def index + @runner_projects = project.runner_projects.all + @runner_project = project.runner_projects.new + end + + def create + @runner = Ci::Runner.find(params[:runner_project][:runner_id]) + + if @runner.assign_to(project, current_user) + redirect_to ci_admin_runner_path(@runner) + else + redirect_to ci_admin_runner_path(@runner), alert: 'Failed adding runner to project' + end + end + + def destroy + rp = Ci::RunnerProject.find(params[:id]) + runner = rp.runner + rp.destroy + + redirect_to ci_admin_runner_path(runner) + end + + private + + def project + @project ||= Ci::Project.find(params[:project_id]) + end + end +end diff --git a/app/controllers/ci/admin/runners_controller.rb b/app/controllers/ci/admin/runners_controller.rb new file mode 100644 index 00000000000..4f5f3776ddc --- /dev/null +++ b/app/controllers/ci/admin/runners_controller.rb @@ -0,0 +1,69 @@ +module Ci + class Admin::RunnersController < Ci::Admin::ApplicationController + before_filter :runner, except: :index + + def index + @runners = Ci::Runner.order('id DESC') + @runners = @runners.search(params[:search]) if params[:search].present? + @runners = @runners.page(params[:page]).per(30) + @active_runners_cnt = Ci::Runner.where("contacted_at > ?", 1.minutes.ago).count + end + + def show + @builds = @runner.builds.order('id DESC').first(30) + @projects = Ci::Project.all + @projects = @projects.search(params[:search]) if params[:search].present? + @projects = @projects.where("projects.id NOT IN (?)", @runner.projects.pluck(:id)) if @runner.projects.any? + @projects = @projects.page(params[:page]).per(30) + end + + def update + @runner.update_attributes(runner_params) + + respond_to do |format| + format.js + format.html { redirect_to ci_admin_runner_path(@runner) } + end + end + + def destroy + @runner.destroy + + redirect_to ci_admin_runners_path + end + + def resume + if @runner.update_attributes(active: true) + redirect_to ci_admin_runners_path, notice: 'Runner was successfully updated.' + else + redirect_to ci_admin_runners_path, alert: 'Runner was not updated.' + end + end + + def pause + if @runner.update_attributes(active: false) + redirect_to ci_admin_runners_path, notice: 'Runner was successfully updated.' + else + redirect_to ci_admin_runners_path, alert: 'Runner was not updated.' + end + end + + def assign_all + Ci::Project.unassigned(@runner).all.each do |project| + @runner.assign_to(project, current_user) + end + + redirect_to ci_admin_runner_path(@runner), notice: "Runner was assigned to all projects" + end + + private + + def runner + @runner ||= Ci::Runner.find(params[:id]) + end + + def runner_params + params.require(:runner).permit(:token, :description, :tag_list, :contacted_at, :active) + end + end +end diff --git a/app/controllers/ci/application_controller.rb b/app/controllers/ci/application_controller.rb new file mode 100644 index 00000000000..726781cb30b --- /dev/null +++ b/app/controllers/ci/application_controller.rb @@ -0,0 +1,133 @@ +module Ci + class ApplicationController < ActionController::Base + def self.railtie_helpers_paths + "app/helpers/ci" + end + + include Ci::UserSessionsHelper + + rescue_from Ci::Network::UnauthorizedError, with: :invalid_token + before_filter :default_headers + before_filter :check_config + + protect_from_forgery + + helper_method :current_user + before_filter :reset_cache + + private + + def current_user + @current_user ||= session[:ci_current_user] + end + + def sign_in(user) + session[:ci_current_user] = user + end + + def sign_out + reset_session + end + + def authenticate_user! + unless current_user + redirect_to new_ci_user_sessions_path + return + end + end + + def authenticate_admin! + unless current_user && current_user.is_admin + redirect_to new_ci_user_sessions_path + return + end + end + + def authenticate_public_page! + unless project.public + unless current_user + redirect_to(new_ci_user_sessions_path(state: generate_oauth_state(request.fullpath))) and return + end + + unless current_user.can_access_project?(project.gitlab_id) + page_404 and return + end + end + end + + def authenticate_token! + unless project.valid_token?(params[:token]) + return head(403) + end + end + + def authorize_access_project! + unless current_user.can_access_project?(@project.gitlab_id) + return page_404 + end + end + + def authorize_project_developer! + unless current_user.has_developer_access?(@project.gitlab_id) + return page_404 + end + end + + def authorize_manage_project! + unless current_user.can_manage_project?(@project.gitlab_id) + return page_404 + end + end + + def page_404 + render file: "#{Rails.root}/public/404.html", status: 404, layout: false + end + + # Reset user cache every day for security purposes + def reset_cache + if current_user && current_user.sync_at < (Time.zone.now - 24.hours) + current_user.reset_cache + end + end + + def default_headers + headers['X-Frame-Options'] = 'DENY' + headers['X-XSS-Protection'] = '1; mode=block' + end + + # JSON for infinite scroll via Pager object + def pager_json(partial, count) + html = render_to_string( + partial, + layout: false, + formats: [:html] + ) + + render json: { + html: html, + count: count + } + end + + def check_config + redirect_to oauth2_ci_help_path unless valid_config? + end + + def valid_config? + server = GitlabCi.config.gitlab_server + + if server.blank? || server.url.blank? || server.app_id.blank? || server.app_secret.blank? + false + else + true + end + rescue Settingslogic::MissingSetting, NoMethodError + false + end + + def invalid_token + reset_session + redirect_to ci_root_path + end + end +end diff --git a/app/controllers/ci/builds_controller.rb b/app/controllers/ci/builds_controller.rb new file mode 100644 index 00000000000..eeff3f1e0a0 --- /dev/null +++ b/app/controllers/ci/builds_controller.rb @@ -0,0 +1,77 @@ +module Ci + class BuildsController < Ci::ApplicationController + before_filter :authenticate_user!, except: [:status, :show] + before_filter :authenticate_public_page!, only: :show + before_filter :project + before_filter :authorize_access_project!, except: [:status, :show] + before_filter :authorize_manage_project!, except: [:status, :show, :retry, :cancel] + before_filter :authorize_project_developer!, only: [:retry, :cancel] + before_filter :build, except: [:show] + + def show + if params[:id] =~ /\A\d+\Z/ + @build = build + else + # try to find commit by sha + commit = commit_by_sha + + if commit + # Redirect to commit page + redirect_to ci_project_ref_commit_path(@project, @build.commit.ref, @build.commit.sha) + return + end + end + + raise ActiveRecord::RecordNotFound unless @build + + @builds = @project.commits.find_by_sha(@build.sha).builds.order('id DESC') + @builds = @builds.where("id not in (?)", @build.id).page(params[:page]).per(20) + @commit = @build.commit + + respond_to do |format| + format.html + format.json do + render json: @build.to_json(methods: :trace_html) + end + end + end + + def retry + if @build.commands.blank? + return page_404 + end + + build = Ci::Build.retry(@build) + + if params[:return_to] + redirect_to URI.parse(params[:return_to]).path + else + redirect_to ci_project_build_path(project, build) + end + end + + def status + render json: @build.to_json(only: [:status, :id, :sha, :coverage], methods: :sha) + end + + def cancel + @build.cancel + + redirect_to ci_project_build_path(@project, @build) + end + + protected + + def project + @project = Ci::Project.find(params[:project_id]) + end + + def build + @build ||= project.builds.unscoped.find_by(id: params[:id]) + end + + def commit_by_sha + @project.commits.find_by(sha: params[:id]) + end + end +end diff --git a/app/controllers/ci/charts_controller.rb b/app/controllers/ci/charts_controller.rb new file mode 100644 index 00000000000..63326ef36cc --- /dev/null +++ b/app/controllers/ci/charts_controller.rb @@ -0,0 +1,24 @@ +module Ci + class ChartsController < Ci::ApplicationController + before_filter :authenticate_user! + before_filter :project + before_filter :authorize_access_project! + before_filter :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/commits_controller.rb b/app/controllers/ci/commits_controller.rb new file mode 100644 index 00000000000..9f74a2fd807 --- /dev/null +++ b/app/controllers/ci/commits_controller.rb @@ -0,0 +1,37 @@ +module Ci + class CommitsController < Ci::ApplicationController + before_filter :authenticate_user!, except: [:status, :show] + before_filter :authenticate_public_page!, only: :show + before_filter :project + before_filter :authorize_access_project!, except: [:status, :show, :cancel] + before_filter :authorize_project_developer!, only: [:cancel] + before_filter :commit, only: :show + + def show + @builds = @commit.builds + end + + def status + commit = Ci::Project.find(params[:project_id]).commits.find_by_sha_and_ref!(params[:id], params[:ref_id]) + render json: commit.to_json(only: [:id, :sha], methods: [:status, :coverage]) + rescue ActiveRecord::RecordNotFound + render json: { status: "not_found" } + end + + def cancel + commit.builds.running_or_pending.each(&:cancel) + + redirect_to ci_project_ref_commit_path(project, commit.ref, commit.sha) + end + + private + + def project + @project ||= Ci::Project.find(params[:project_id]) + end + + def commit + @commit ||= Ci::Project.find(params[:project_id]).commits.find_by_sha_and_ref!(params[:id], params[:ref_id]) + end + end +end diff --git a/app/controllers/ci/events_controller.rb b/app/controllers/ci/events_controller.rb new file mode 100644 index 00000000000..c515caabe63 --- /dev/null +++ b/app/controllers/ci/events_controller.rb @@ -0,0 +1,21 @@ +module Ci + class EventsController < Ci::ApplicationController + EVENTS_PER_PAGE = 50 + + before_filter :authenticate_user! + before_filter :project + before_filter :authorize_manage_project! + + layout 'ci/project' + + def index + @events = project.events.order("created_at DESC").page(params[:page]).per(EVENTS_PER_PAGE) + end + + private + + def project + @project ||= Ci::Project.find(params[:project_id]) + end + end +end diff --git a/app/controllers/ci/helps_controller.rb b/app/controllers/ci/helps_controller.rb new file mode 100644 index 00000000000..a1ee4111614 --- /dev/null +++ b/app/controllers/ci/helps_controller.rb @@ -0,0 +1,16 @@ +module Ci + class HelpsController < Ci::ApplicationController + skip_filter :check_config + + def show + end + + def oauth2 + if valid_config? + redirect_to ci_root_path + else + render layout: 'ci/empty' + end + end + end +end diff --git a/app/controllers/ci/lints_controller.rb b/app/controllers/ci/lints_controller.rb new file mode 100644 index 00000000000..62c2ba86e86 --- /dev/null +++ b/app/controllers/ci/lints_controller.rb @@ -0,0 +1,26 @@ +module Ci + class LintsController < Ci::ApplicationController + before_filter :authenticate_user! + + def show + end + + def create + if params[:content].blank? + @status = false + @error = "Please provide content of .gitlab-ci.yml" + else + @config_processor = Ci::GitlabCiYamlProcessor.new params[:content] + @stages = @config_processor.stages + @builds = @config_processor.builds + @status = true + end + rescue Ci::GitlabCiYamlProcessor::ValidationError => e + @error = e.message + @status = false + rescue Exception => e + @error = "Undefined error" + @status = false + end + end +end diff --git a/app/controllers/ci/projects_controller.rb b/app/controllers/ci/projects_controller.rb new file mode 100644 index 00000000000..6ff7fc9f77a --- /dev/null +++ b/app/controllers/ci/projects_controller.rb @@ -0,0 +1,136 @@ +module Ci + class ProjectsController < Ci::ApplicationController + PROJECTS_BATCH = 100 + + before_filter :authenticate_user!, except: [:build, :badge, :index, :show] + before_filter :authenticate_public_page!, only: :show + before_filter :project, only: [:build, :integration, :show, :badge, :edit, :update, :destroy, :toggle_shared_runners, :dumped_yaml] + before_filter :authorize_access_project!, except: [:build, :gitlab, :badge, :index, :show, :new, :create] + before_filter :authorize_manage_project!, only: [:edit, :integration, :update, :destroy, :toggle_shared_runners, :dumped_yaml] + before_filter :authenticate_token!, only: [:build] + before_filter :no_cache, only: [:badge] + protect_from_forgery except: :build + + layout 'ci/project', except: [:index, :gitlab] + + def index + @projects = Ci::Project.ordered_by_last_commit_date.public_only.page(params[:page]) unless current_user + end + + def gitlab + @limit, @offset = (params[:limit] || PROJECTS_BATCH).to_i, (params[:offset] || 0).to_i + @page = @offset == 0 ? 1 : (@offset / @limit + 1) + + current_user.reset_cache if params[:reset_cache] + + @gl_projects = current_user.gitlab_projects(params[:search], @page, @limit) + @projects = Ci::Project.where(gitlab_id: @gl_projects.map(&:id)).ordered_by_last_commit_date + @total_count = @gl_projects.size + @gl_projects.reject! { |gl_project| @projects.map(&:gitlab_id).include?(gl_project.id) } + respond_to do |format| + format.json do + pager_json("ci/projects/gitlab", @total_count) + end + end + rescue Ci::Network::UnauthorizedError + raise + rescue + @error = 'Failed to fetch GitLab projects' + end + + def show + @ref = params[:ref] + + @commits = @project.commits.reverse_order + @commits = @commits.where(ref: @ref) if @ref + @commits = @commits.page(params[:page]).per(20) + end + + def integration + end + + def create + project_data = OpenStruct.new(JSON.parse(params["project"])) + + unless current_user.can_manage_project?(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.destroy + Ci::Network.new.disable_ci(project.gitlab_id, current_user.authenticate_options) + + 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 + image = Ci::ImageForBuildService.new.execute(@project, params) + + send_file image.path, filename: image.name, disposition: 'inline', type:"image/svg+xml" + end + + def toggle_shared_runners + project.toggle!(:shared_runners_enabled) + redirect_to :back + end + + def dumped_yaml + send_data @project.generated_yaml_config, filename: '.gitlab-ci.yml' + end + + protected + + def project + @project ||= Ci::Project.find(params[:id]) + end + + def no_cache + response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate" + 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 new file mode 100644 index 00000000000..3a52087cc6b --- /dev/null +++ b/app/controllers/ci/runner_projects_controller.rb @@ -0,0 +1,34 @@ +module Ci + class RunnerProjectsController < Ci::ApplicationController + before_filter :authenticate_user! + before_filter :project + before_filter :authorize_manage_project! + + layout 'ci/project' + + def create + @runner = Ci::Runner.find(params[:runner_project][:runner_id]) + + return head(403) unless current_user.authorized_runners.include?(@runner) + + if @runner.assign_to(project, current_user) + redirect_to ci_project_runners_path(project) + else + redirect_to ci_project_runners_path(project), alert: 'Failed adding runner to project' + end + end + + def destroy + runner_project = project.runner_projects.find(params[:id]) + runner_project.destroy + + redirect_to ci_project_runners_path(project) + end + + private + + def project + @project ||= Ci::Project.find(params[:project_id]) + end + end +end diff --git a/app/controllers/ci/runners_controller.rb b/app/controllers/ci/runners_controller.rb new file mode 100644 index 00000000000..0ef32ce928f --- /dev/null +++ b/app/controllers/ci/runners_controller.rb @@ -0,0 +1,71 @@ +module Ci + class RunnersController < Ci::ApplicationController + before_filter :authenticate_user! + before_filter :project + before_filter :set_runner, only: [:edit, :update, :destroy, :pause, :resume, :show] + before_filter :authorize_access_project! + before_filter :authorize_manage_project! + + layout 'ci/project' + + def index + @runners = @project.runners.order('id DESC') + @specific_runners = current_user.authorized_runners. + 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/services_controller.rb b/app/controllers/ci/services_controller.rb new file mode 100644 index 00000000000..e99f40f3a0a --- /dev/null +++ b/app/controllers/ci/services_controller.rb @@ -0,0 +1,59 @@ +module Ci + class ServicesController < Ci::ApplicationController + before_filter :authenticate_user! + before_filter :project + before_filter :authorize_access_project! + before_filter :authorize_manage_project! + before_filter :service, only: [:edit, :update, :test] + + respond_to :html + + layout 'ci/project' + + def index + @project.build_missing_services + @services = @project.services.reload + end + + def edit + end + + def update + if @service.update_attributes(service_params) + redirect_to edit_ci_project_service_path(@project, @service.to_param), notice: 'Service was successfully updated.' + else + render 'edit' + end + end + + def test + last_build = @project.builds.last + + if @service.execute(last_build) + message = { notice: 'We successfully tested the service' } + else + message = { alert: 'We tried to test the service but error occurred' } + end + + redirect_to :back, message + end + + private + + def project + @project = Ci::Project.find(params[:project_id]) + end + + def service + @service ||= @project.services.find { |service| service.to_param == params[:id] } + end + + def service_params + params.require(:service).permit( + :type, :active, :webhook, :notify_only_broken_builds, + :email_recipients, :email_only_broken_builds, :email_add_pusher, + :hipchat_token, :hipchat_room, :hipchat_server + ) + end + end +end diff --git a/app/controllers/ci/triggers_controller.rb b/app/controllers/ci/triggers_controller.rb new file mode 100644 index 00000000000..6ba37cd843e --- /dev/null +++ b/app/controllers/ci/triggers_controller.rb @@ -0,0 +1,43 @@ +module Ci + class TriggersController < Ci::ApplicationController + before_filter :authenticate_user! + before_filter :project + before_filter :authorize_access_project! + before_filter :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/user_sessions_controller.rb b/app/controllers/ci/user_sessions_controller.rb new file mode 100644 index 00000000000..82134c1f7ba --- /dev/null +++ b/app/controllers/ci/user_sessions_controller.rb @@ -0,0 +1,65 @@ +module Ci + class UserSessionsController < Ci::ApplicationController + before_filter :authenticate_user!, except: [:new, :callback, :auth] + + def show + @user = current_user + end + + def new + end + + def auth + unless is_oauth_state_valid?(params[:state]) + redirect_to new_ci_user_sessions_path + return + end + + redirect_to client.auth_code.authorize_url({ + redirect_uri: callback_ci_user_sessions_url, + state: params[:state] + }) + end + + def callback + unless is_oauth_state_valid?(params[:state]) + redirect_to new_ci_user_sessions_path + return + end + + token = client.auth_code.get_token(params[:code], redirect_uri: callback_ci_user_sessions_url).token + + @user_session = Ci::UserSession.new + user = @user_session.authenticate(access_token: token) + + if user && sign_in(user) + return_to = get_ouath_state_return_to(params[:state]) + redirect_to(return_to || ci_root_path) + else + @error = 'Invalid credentials' + render :new + end + + end + + def destroy + sign_out + + redirect_to new_ci_user_sessions_path + end + + protected + + def client + @client ||= ::OAuth2::Client.new( + GitlabCi.config.gitlab_server.app_id, + GitlabCi.config.gitlab_server.app_secret, + { + site: GitlabCi.config.gitlab_server.url, + authorize_url: 'oauth/authorize', + token_url: 'oauth/token' + } + ) + end + end +end diff --git a/app/controllers/ci/variables_controller.rb b/app/controllers/ci/variables_controller.rb new file mode 100644 index 00000000000..6908e0877f0 --- /dev/null +++ b/app/controllers/ci/variables_controller.rb @@ -0,0 +1,33 @@ +module Ci + class VariablesController < Ci::ApplicationController + before_filter :authenticate_user! + before_filter :project + before_filter :authorize_access_project! + before_filter :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/ci/web_hooks_controller.rb b/app/controllers/ci/web_hooks_controller.rb new file mode 100644 index 00000000000..eea4842c91c --- /dev/null +++ b/app/controllers/ci/web_hooks_controller.rb @@ -0,0 +1,53 @@ +module Ci + class WebHooksController < Ci::ApplicationController + before_filter :authenticate_user! + before_filter :project + before_filter :authorize_access_project! + before_filter :authorize_manage_project! + + layout 'ci/project' + + def index + @web_hooks = @project.web_hooks + @web_hook = Ci::WebHook.new + end + + def create + @web_hook = @project.web_hooks.new(web_hook_params) + @web_hook.save + + if @web_hook.valid? + redirect_to ci_project_web_hooks_path(@project) + else + @web_hooks = @project.web_hooks.select(&:persisted?) + render :index + end + end + + def test + Ci::TestHookService.new.execute(hook, current_user) + + redirect_to :back + end + + def destroy + hook.destroy + + redirect_to ci_project_web_hooks_path(@project) + end + + private + + def hook + @web_hook ||= @project.web_hooks.find(params[:id]) + end + + def project + @project = Ci::Project.find(params[:project_id]) + end + + def web_hook_params + params.require(:web_hook).permit(:url) + end + end +end diff --git a/app/controllers/oauth/applications_controller.rb b/app/controllers/oauth/applications_controller.rb index fc31118124b..4e007d2a4d0 100644 --- a/app/controllers/oauth/applications_controller.rb +++ b/app/controllers/oauth/applications_controller.rb @@ -1,6 +1,6 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController include Gitlab::CurrentSettings - include PageLayoutHelper + include Gitlab::PageLayoutHelper before_action :verify_user_oauth_applications_enabled before_action :authenticate_user! diff --git a/app/controllers/oauth/authorized_applications_controller.rb b/app/controllers/oauth/authorized_applications_controller.rb index 4193ac11399..08d94408fc8 100644 --- a/app/controllers/oauth/authorized_applications_controller.rb +++ b/app/controllers/oauth/authorized_applications_controller.rb @@ -1,5 +1,5 @@ class Oauth::AuthorizedApplicationsController < Doorkeeper::AuthorizedApplicationsController - include PageLayoutHelper + include Gitlab::PageLayoutHelper layout 'profile' diff --git a/app/controllers/projects/network_controller.rb b/app/controllers/projects/network_controller.rb index b181c47baec..b70e12365da 100644 --- a/app/controllers/projects/network_controller.rb +++ b/app/controllers/projects/network_controller.rb @@ -1,6 +1,6 @@ class Projects::NetworkController < Projects::ApplicationController include ExtractsPath - include ApplicationHelper + include Gitlab::ApplicationHelper before_action :require_non_empty_project before_action :assign_ref_vars diff --git a/app/controllers/projects/refs_controller.rb b/app/controllers/projects/refs_controller.rb index 6080c849c8d..a9081a5ae16 100644 --- a/app/controllers/projects/refs_controller.rb +++ b/app/controllers/projects/refs_controller.rb @@ -1,6 +1,6 @@ class Projects::RefsController < Projects::ApplicationController include ExtractsPath - include TreeHelper + include Gitlab::TreeHelper before_action :require_non_empty_project before_action :assign_ref_vars diff --git a/app/controllers/projects/wikis_controller.rb b/app/controllers/projects/wikis_controller.rb index 50512cb6dc3..870ff035b03 100644 --- a/app/controllers/projects/wikis_controller.rb +++ b/app/controllers/projects/wikis_controller.rb @@ -5,7 +5,7 @@ class Projects::WikisController < Projects::ApplicationController before_action :authorize_create_wiki!, only: [:edit, :create, :history] before_action :authorize_admin_wiki!, only: :destroy before_action :load_project_wiki - include WikiHelper + include Gitlab::WikiHelper def pages @wiki_pages = Kaminari.paginate_array(@project_wiki.pages).page(params[:page]).per(PER_PAGE) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index eb0408a95e5..63d336b2bd5 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -1,5 +1,5 @@ class SearchController < ApplicationController - include SearchHelper + include Gitlab::SearchHelper layout 'search' |