diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-18 21:06:34 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-18 21:06:34 +0000 |
commit | e4c711546c693fff89b0b1c92f1b0dde927e0c84 (patch) | |
tree | 2afa79ebbb72960fd54f1392e0a18031a1d9ee54 /app | |
parent | b08279013423a66f06f5edde4e067f328fe135bd (diff) | |
download | gitlab-ce-e4c711546c693fff89b0b1c92f1b0dde927e0c84.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/project_find_file.js | 2 | ||||
-rw-r--r-- | app/assets/stylesheets/framework/sidebar.scss | 4 | ||||
-rw-r--r-- | app/controllers/projects/artifacts_controller.rb | 38 | ||||
-rw-r--r-- | app/finders/artifacts_finder.rb | 24 | ||||
-rw-r--r-- | app/helpers/sorting_helper.rb | 20 | ||||
-rw-r--r-- | app/models/ci/job_artifact.rb | 5 | ||||
-rw-r--r-- | app/models/project.rb | 1 | ||||
-rw-r--r-- | app/models/protected_branch.rb | 5 | ||||
-rw-r--r-- | app/models/release.rb | 1 |
9 files changed, 89 insertions, 11 deletions
diff --git a/app/assets/javascripts/project_find_file.js b/app/assets/javascripts/project_find_file.js index e73a828c0ae..c198c4eea4a 100644 --- a/app/assets/javascripts/project_find_file.js +++ b/app/assets/javascripts/project_find_file.js @@ -81,7 +81,7 @@ export default class ProjectFindFile { // find file } - // files pathes load + // files paths load load(url) { axios .get(url) diff --git a/app/assets/stylesheets/framework/sidebar.scss b/app/assets/stylesheets/framework/sidebar.scss index 43d0e51e4c9..b9cfcf6ce5c 100644 --- a/app/assets/stylesheets/framework/sidebar.scss +++ b/app/assets/stylesheets/framework/sidebar.scss @@ -171,7 +171,7 @@ position: absolute; top: $gl-padding; bottom: $gl-padding; - left: map-get($spacers, 2) - 1px; + left: map-get($spacers, 2) - px-to-rem(1px); } &-row { @@ -187,7 +187,7 @@ * 2px extra is to give a little more height than needed * to hide timeline line before/after the element starts/ends */ - height: map-get($spacers, 4) + 2px; + height: map-get($spacers, 4) + px-to-rem(2px); z-index: 1; position: relative; top: -3px; diff --git a/app/controllers/projects/artifacts_controller.rb b/app/controllers/projects/artifacts_controller.rb index da8a371acaa..50399a8cfbb 100644 --- a/app/controllers/projects/artifacts_controller.rb +++ b/app/controllers/projects/artifacts_controller.rb @@ -8,10 +8,37 @@ class Projects::ArtifactsController < Projects::ApplicationController layout 'project' before_action :authorize_read_build! before_action :authorize_update_build!, only: [:keep] + before_action :authorize_destroy_artifacts!, only: [:destroy] before_action :extract_ref_name_and_path - before_action :validate_artifacts!, except: [:download] + before_action :validate_artifacts!, except: [:index, :download, :destroy] before_action :entry, only: [:file] + MAX_PER_PAGE = 20 + + def index + # Loading artifacts is very expensive in projects with a lot of artifacts. + # This feature flag prevents a DOS attack vector. + # It should be removed only after resolving the underlying performance + # issues: https://gitlab.com/gitlab-org/gitlab/issues/32281 + return head :no_content unless Feature.enabled?(:artifacts_management_page, @project) + + finder = ArtifactsFinder.new(@project, artifacts_params) + all_artifacts = finder.execute + + @artifacts = all_artifacts.page(params[:page]).per(MAX_PER_PAGE) + @total_size = all_artifacts.total_size + end + + def destroy + notice = if artifact.destroy + _('Artifact was successfully deleted.') + else + _('Artifact could not be deleted.') + end + + redirect_to project_artifacts_path(@project), status: :see_other, notice: notice + end + def download return render_404 unless artifacts_file @@ -74,6 +101,10 @@ class Projects::ArtifactsController < Projects::ApplicationController @ref_name, @path = extract_ref(params[:ref_name_and_path]) end + def artifacts_params + params.permit(:sort) + end + def validate_artifacts! render_404 unless build&.artifacts? end @@ -85,6 +116,11 @@ class Projects::ArtifactsController < Projects::ApplicationController end end + def artifact + @artifact ||= + project.job_artifacts.find(params[:id]) + end + def build_from_id project.builds.find_by_id(params[:job_id]) if params[:job_id] end diff --git a/app/finders/artifacts_finder.rb b/app/finders/artifacts_finder.rb new file mode 100644 index 00000000000..81c5168d782 --- /dev/null +++ b/app/finders/artifacts_finder.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +class ArtifactsFinder + def initialize(project, params = {}) + @project = project + @params = params + end + + def execute + artifacts = @project.job_artifacts + + sort(artifacts) + end + + private + + def sort_key + @params[:sort] || 'created_desc' + end + + def sort(artifacts) + artifacts.order_by(sort_key) + end +end diff --git a/app/helpers/sorting_helper.rb b/app/helpers/sorting_helper.rb index d680e10525d..33f3bb0b749 100644 --- a/app/helpers/sorting_helper.rb +++ b/app/helpers/sorting_helper.rb @@ -28,7 +28,9 @@ module SortingHelper sort_value_priority => sort_title_priority, sort_value_upvotes => sort_title_upvotes, sort_value_contacted_date => sort_title_contacted_date, - sort_value_relative_position => sort_title_relative_position + sort_value_relative_position => sort_title_relative_position, + sort_value_size => sort_title_size, + sort_value_expire_date => sort_title_expire_date } end @@ -406,6 +408,14 @@ module SortingHelper s_('SortOptions|Manual') end + def sort_title_size + s_('SortOptions|Size') + end + + def sort_title_expire_date + s_('SortOptions|Expired date') + end + # Values. def sort_value_access_level_asc 'access_level_asc' @@ -558,4 +568,12 @@ module SortingHelper def sort_value_relative_position 'relative_position' end + + def sort_value_size + 'size_desc' + end + + def sort_value_expire_date + 'expired_asc' + end end diff --git a/app/models/ci/job_artifact.rb b/app/models/ci/job_artifact.rb index da2758507ce..add9110ee5e 100644 --- a/app/models/ci/job_artifact.rb +++ b/app/models/ci/job_artifact.rb @@ -5,6 +5,7 @@ module Ci include AfterCommitQueue include ObjectStorage::BackgroundMove include UpdateProjectStatistics + include Sortable extend Gitlab::Ci::Model NotSupportedAdapterError = Class.new(StandardError) @@ -143,6 +144,10 @@ module Ci self.update_column(:file_store, file.object_store) end + def self.total_size + self.sum(:size) + end + def self.artifacts_size_for(project) self.where(project: project).sum(:size) end diff --git a/app/models/project.rb b/app/models/project.rb index 7c065db9829..18afccf7ddc 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -273,6 +273,7 @@ class Project < ApplicationRecord has_many :builds, class_name: 'Ci::Build', inverse_of: :project, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent has_many :build_trace_section_names, class_name: 'Ci::BuildTraceSectionName' has_many :build_trace_chunks, class_name: 'Ci::BuildTraceChunk', through: :builds, source: :trace_chunks + has_many :job_artifacts, class_name: 'Ci::JobArtifact' has_many :runner_projects, class_name: 'Ci::RunnerProject', inverse_of: :project has_many :runners, through: :runner_projects, source: :runner, class_name: 'Ci::Runner' has_many :variables, class_name: 'Ci::Variable' diff --git a/app/models/protected_branch.rb b/app/models/protected_branch.rb index 1857a59e01c..8769d3eb916 100644 --- a/app/models/protected_branch.rb +++ b/app/models/protected_branch.rb @@ -40,11 +40,6 @@ class ProtectedBranch < ApplicationRecord def self.protected_refs(project) project.protected_branches.select(:name) end - - def self.branch_requires_code_owner_approval?(project, branch_name) - # NOOP - # - end end ProtectedBranch.prepend_if_ee('EE::ProtectedBranch') diff --git a/app/models/release.rb b/app/models/release.rb index cd63b4d5fef..9117a475ee9 100644 --- a/app/models/release.rb +++ b/app/models/release.rb @@ -22,7 +22,6 @@ class Release < ApplicationRecord accepts_nested_attributes_for :links, allow_destroy: true validates :description, :project, :tag, presence: true - validates :name, presence: true, on: :create validates_associated :milestone_releases, message: -> (_, obj) { obj[:value].map(&:errors).map(&:full_messages).join(",") } scope :sorted, -> { order(released_at: :desc) } |