Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-02-25 12:09:10 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-02-25 12:09:10 +0300
commitb98fa9ef3d5bead417ae2f325cb64637883264e9 (patch)
tree409f2002dd056f12d82d3959b3e6f012c4087123 /app
parent7e3005967df23a957fe1998c8de4f50b412e69e7 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/ide/lib/files.js5
-rw-r--r--app/assets/javascripts/ide/stores/utils.js5
-rw-r--r--app/assets/javascripts/issuables_list/components/issuables_list_app.vue2
-rw-r--r--app/assets/javascripts/vue_shared/components/file_row.vue3
-rw-r--r--app/controllers/concerns/snippets_actions.rb6
-rw-r--r--app/controllers/projects/snippets_controller.rb11
-rw-r--r--app/controllers/snippets_controller.rb22
-rw-r--r--app/graphql/types/snippet_type.rb1
-rw-r--r--app/models/concerns/blob_language_from_git_attributes.rb4
-rw-r--r--app/models/snippet.rb8
-rw-r--r--app/presenters/snippet_blob_presenter.rb2
-rw-r--r--app/presenters/snippet_presenter.rb8
-rw-r--r--app/services/audit_event_service.rb15
-rw-r--r--app/views/projects/snippets/show.html.haml3
-rw-r--r--app/views/shared/snippets/_blob.html.haml20
-rw-r--r--app/views/shared/snippets/_embed.html.haml7
-rw-r--r--app/views/snippets/show.html.haml3
17 files changed, 72 insertions, 53 deletions
diff --git a/app/assets/javascripts/ide/lib/files.js b/app/assets/javascripts/ide/lib/files.js
index bee867fa47c..26518a2abac 100644
--- a/app/assets/javascripts/ide/lib/files.js
+++ b/app/assets/javascripts/ide/lib/files.js
@@ -1,5 +1,4 @@
import { viewerInformationForPath } from '~/vue_shared/components/content_viewer/lib/viewer_utils';
-import { escapeFileUrl } from '~/lib/utils/url_utility';
import { decorateData, sortTree } from '../stores/utils';
export const splitParent = path => {
@@ -48,7 +47,7 @@ export const decorateFiles = ({
id: path,
name,
path,
- url: `/${projectId}/tree/${branchId}/-/${escapeFileUrl(path)}/`,
+ url: `/${projectId}/tree/${branchId}/-/${path}/`,
type: 'tree',
parentTreeUrl: parentFolder ? parentFolder.url : `/${projectId}/tree/${branchId}/`,
tempFile,
@@ -85,7 +84,7 @@ export const decorateFiles = ({
id: path,
name,
path,
- url: `/${projectId}/blob/${branchId}/-/${escapeFileUrl(path)}`,
+ url: `/${projectId}/blob/${branchId}/-/${path}`,
type: 'blob',
parentTreeUrl: fileFolder ? fileFolder.url : `/${projectId}/blob/${branchId}`,
tempFile,
diff --git a/app/assets/javascripts/ide/stores/utils.js b/app/assets/javascripts/ide/stores/utils.js
index 06e66da1069..4e5b01596d8 100644
--- a/app/assets/javascripts/ide/stores/utils.js
+++ b/app/assets/javascripts/ide/stores/utils.js
@@ -1,5 +1,4 @@
import { commitActionTypes, FILE_VIEW_MODE_EDITOR } from '../constants';
-import { escapeFileUrl } from '~/lib/utils/url_utility';
export const dataStructure = () => ({
id: '',
@@ -220,9 +219,7 @@ export const mergeTrees = (fromTree, toTree) => {
export const replaceFileUrl = (url, oldPath, newPath) => {
// Add `/-/` so that we don't accidentally replace project path
- const result = url.replace(`/-/${escapeFileUrl(oldPath)}`, `/-/${escapeFileUrl(newPath)}`);
-
- return result;
+ return url.replace(`/-/${oldPath}`, `/-/${newPath}`);
};
export const swapInStateArray = (state, arr, key, entryPath) =>
diff --git a/app/assets/javascripts/issuables_list/components/issuables_list_app.vue b/app/assets/javascripts/issuables_list/components/issuables_list_app.vue
index 6b6a8bd4068..1e071f46347 100644
--- a/app/assets/javascripts/issuables_list/components/issuables_list_app.vue
+++ b/app/assets/javascripts/issuables_list/components/issuables_list_app.vue
@@ -1,5 +1,5 @@
<script>
-import { omit } from 'underscore';
+import { omit } from 'lodash';
import { GlEmptyState, GlPagination, GlSkeletonLoading } from '@gitlab/ui';
import flash from '~/flash';
import axios from '~/lib/utils/axios_utils';
diff --git a/app/assets/javascripts/vue_shared/components/file_row.vue b/app/assets/javascripts/vue_shared/components/file_row.vue
index 578fcc819b0..4d60cf5b1cc 100644
--- a/app/assets/javascripts/vue_shared/components/file_row.vue
+++ b/app/assets/javascripts/vue_shared/components/file_row.vue
@@ -1,6 +1,7 @@
<script>
import FileHeader from '~/vue_shared/components/file_row_header.vue';
import FileIcon from '~/vue_shared/components/file_icon.vue';
+import { escapeFileUrl } from '~/lib/utils/url_utility';
export default {
name: 'FileRow',
@@ -94,7 +95,7 @@ export default {
hasUrlAtCurrentRoute() {
if (!this.$router || !this.$router.currentRoute) return true;
- return this.$router.currentRoute.path === `/project${this.file.url}`;
+ return this.$router.currentRoute.path === `/project${escapeFileUrl(this.file.url)}`;
},
},
};
diff --git a/app/controllers/concerns/snippets_actions.rb b/app/controllers/concerns/snippets_actions.rb
index 014232a7d05..bb46345d362 100644
--- a/app/controllers/concerns/snippets_actions.rb
+++ b/app/controllers/concerns/snippets_actions.rb
@@ -6,20 +6,18 @@ module SnippetsActions
def edit
end
- # rubocop:disable Gitlab/ModuleWithInstanceVariables
def raw
disposition = params[:inline] == 'false' ? 'attachment' : 'inline'
workhorse_set_content_type!
send_data(
- convert_line_endings(@snippet.content),
+ convert_line_endings(blob.data),
type: 'text/plain; charset=utf-8',
disposition: disposition,
- filename: @snippet.sanitized_file_name
+ filename: Snippet.sanitized_file_name(blob.name)
)
end
- # rubocop:enable Gitlab/ModuleWithInstanceVariables
def js_request?
request.format.js?
diff --git a/app/controllers/projects/snippets_controller.rb b/app/controllers/projects/snippets_controller.rb
index b9c7468890b..8317d9fc6d5 100644
--- a/app/controllers/projects/snippets_controller.rb
+++ b/app/controllers/projects/snippets_controller.rb
@@ -66,7 +66,6 @@ class Projects::SnippetsController < Projects::ApplicationController
end
def show
- blob = @snippet.blob
conditionally_expand_blob(blob)
respond_to do |format|
@@ -115,6 +114,16 @@ class Projects::SnippetsController < Projects::ApplicationController
alias_method :awardable, :snippet
alias_method :spammable, :snippet
+ def blob
+ return unless snippet
+
+ @blob ||= if Feature.enabled?(:version_snippets, current_user) && !snippet.repository.empty?
+ snippet.blobs.first
+ else
+ snippet.blob
+ end
+ end
+
def spammable_path
project_snippet_path(@project, @snippet)
end
diff --git a/app/controllers/snippets_controller.rb b/app/controllers/snippets_controller.rb
index b6ad5fd02b0..e6840e46226 100644
--- a/app/controllers/snippets_controller.rb
+++ b/app/controllers/snippets_controller.rb
@@ -68,17 +68,15 @@ class SnippetsController < ApplicationController
end
def show
- blob = @snippet.blob
conditionally_expand_blob(blob)
- @note = Note.new(noteable: @snippet)
- @noteable = @snippet
-
- @discussions = @snippet.discussions
- @notes = prepare_notes_for_rendering(@discussions.flat_map(&:notes), @noteable)
-
respond_to do |format|
format.html do
+ @note = Note.new(noteable: @snippet)
+ @noteable = @snippet
+
+ @discussions = @snippet.discussions
+ @notes = prepare_notes_for_rendering(@discussions.flat_map(&:notes), @noteable)
render 'show'
end
@@ -121,6 +119,16 @@ class SnippetsController < ApplicationController
alias_method :awardable, :snippet
alias_method :spammable, :snippet
+ def blob
+ return unless snippet
+
+ @blob ||= if Feature.enabled?(:version_snippets, current_user) && !snippet.repository.empty?
+ snippet.blobs.first
+ else
+ snippet.blob
+ end
+ end
+
def spammable_path
snippet_path(@snippet)
end
diff --git a/app/graphql/types/snippet_type.rb b/app/graphql/types/snippet_type.rb
index c4d65174990..cb0bd5205b0 100644
--- a/app/graphql/types/snippet_type.rb
+++ b/app/graphql/types/snippet_type.rb
@@ -62,6 +62,7 @@ module Types
field :blob, type: Types::Snippets::BlobType,
description: 'Snippet blob',
+ calls_gitaly: true,
null: false
markdown_field :description_html, null: true, method: :description
diff --git a/app/models/concerns/blob_language_from_git_attributes.rb b/app/models/concerns/blob_language_from_git_attributes.rb
index 56e1276a220..01878e067b9 100644
--- a/app/models/concerns/blob_language_from_git_attributes.rb
+++ b/app/models/concerns/blob_language_from_git_attributes.rb
@@ -1,13 +1,11 @@
# frozen_string_literal: true
-# Applicable for blob classes with project attribute
module BlobLanguageFromGitAttributes
extend ActiveSupport::Concern
def language_from_gitattributes
- return unless project
+ return unless repository&.exists?
- repository = project.repository
repository.gitattribute(path, 'gitlab-language')
end
end
diff --git a/app/models/snippet.rb b/app/models/snippet.rb
index 814a88dbd09..745700b1c65 100644
--- a/app/models/snippet.rb
+++ b/app/models/snippet.rb
@@ -197,7 +197,11 @@ class Snippet < ApplicationRecord
end
def blob
- @blob ||= Blob.decorate(SnippetBlob.new(self), nil)
+ @blob ||= Blob.decorate(SnippetBlob.new(self), self)
+ end
+
+ def blobs
+ repository.ls_files(repository.root_ref).map { |file| Blob.lazy(self, repository.root_ref, file) }
end
def hook_attrs
@@ -208,7 +212,7 @@ class Snippet < ApplicationRecord
super.to_s
end
- def sanitized_file_name
+ def self.sanitized_file_name(file_name)
file_name.gsub(/[^a-zA-Z0-9_\-\.]+/, '')
end
diff --git a/app/presenters/snippet_blob_presenter.rb b/app/presenters/snippet_blob_presenter.rb
index 70a373619d6..8e593d3a5fe 100644
--- a/app/presenters/snippet_blob_presenter.rb
+++ b/app/presenters/snippet_blob_presenter.rb
@@ -32,7 +32,7 @@ class SnippetBlobPresenter < BlobPresenter
end
def snippet
- blob.snippet
+ blob.container
end
def language
diff --git a/app/presenters/snippet_presenter.rb b/app/presenters/snippet_presenter.rb
index a453be18b95..ba9d566932a 100644
--- a/app/presenters/snippet_presenter.rb
+++ b/app/presenters/snippet_presenter.rb
@@ -27,6 +27,14 @@ class SnippetPresenter < Gitlab::View::Presenter::Delegated
snippet.submittable_as_spam_by?(current_user)
end
+ def blob
+ if Feature.enabled?(:version_snippets, current_user) && !snippet.repository.empty?
+ snippet.blobs.first
+ else
+ snippet.blob
+ end
+ end
+
private
def can_access_resource?(ability_prefix)
diff --git a/app/services/audit_event_service.rb b/app/services/audit_event_service.rb
index 43bd0f39d68..42ed5f17d8d 100644
--- a/app/services/audit_event_service.rb
+++ b/app/services/audit_event_service.rb
@@ -3,14 +3,13 @@
class AuditEventService
# Instantiates a new service
#
- # @param author [User] the user who authors the change
- # @param entity [Object] an instance of either Project/Group/User type. This
- # param is also used to determine at which level the audit events are
- # shown.
- # - Project: events are visible at Project level
- # - Group: events are visible at Group level
+ # @param [User] author the user who authors the change
+ # @param [User, Project, Group] entity the scope which audit event belongs to
+ # This param is also used to determine the visibility of the audit event.
+ # - Project: events are visible at Project and Instance level
+ # - Group: events are visible at Group and Instance level
# - User: events are visible at Instance level
- # @param details [Hash] details to be added to audit event
+ # @param [Hash] details extra data of audit event
#
# @return [AuditEventService]
def initialize(author, entity, details = {})
@@ -21,7 +20,7 @@ class AuditEventService
# Builds the @details attribute for authentication
#
- # This uses the @author as the target object being changed
+ # This uses the @author as the target object being audited
#
# @return [AuditEventService]
def for_authentication
diff --git a/app/views/projects/snippets/show.html.haml b/app/views/projects/snippets/show.html.haml
index 422a467574b..ccf109968fc 100644
--- a/app/views/projects/snippets/show.html.haml
+++ b/app/views/projects/snippets/show.html.haml
@@ -9,8 +9,7 @@
= render 'shared/snippets/header'
.project-snippets
- %article.file-holder.snippet-file-content
- = render 'shared/snippets/blob'
+ = render 'shared/snippets/blob', blob: @blob
.row-content-block.top-block.content-component-block
= render 'award_emoji/awards_block', awardable: @snippet, inline: true
diff --git a/app/views/shared/snippets/_blob.html.haml b/app/views/shared/snippets/_blob.html.haml
index 6a5e777706c..a2169deb592 100644
--- a/app/views/shared/snippets/_blob.html.haml
+++ b/app/views/shared/snippets/_blob.html.haml
@@ -1,13 +1,13 @@
-- blob = @snippet.blob
-.js-file-title.file-title-flex-parent
- = render 'projects/blob/header_content', blob: blob
+%article.file-holder.snippet-file-content
+ .js-file-title.file-title-flex-parent
+ = render 'projects/blob/header_content', blob: blob
- .file-actions.d-none.d-sm-block
- = render 'projects/blob/viewer_switcher', blob: blob
+ .file-actions.d-none.d-sm-block
+ = render 'projects/blob/viewer_switcher', blob: blob
- .btn-group{ role: "group" }<
- = copy_blob_source_button(blob)
- = open_raw_blob_button(blob)
- = download_raw_snippet_button(@snippet)
+ .btn-group{ role: "group" }<
+ = copy_blob_source_button(blob)
+ = open_raw_blob_button(blob)
+ = download_raw_snippet_button(@snippet)
-= render 'projects/blob/content', blob: blob
+ = render 'projects/blob/content', blob: blob
diff --git a/app/views/shared/snippets/_embed.html.haml b/app/views/shared/snippets/_embed.html.haml
index b401820daf6..f1abd3a2ce4 100644
--- a/app/views/shared/snippets/_embed.html.haml
+++ b/app/views/shared/snippets/_embed.html.haml
@@ -1,4 +1,3 @@
-- blob = @snippet.blob
.gitlab-embed-snippets
.js-file-title.file-title-flex-parent
.file-header-content
@@ -6,10 +5,10 @@
%strong.file-title-name
%a.gitlab-embedded-snippets-title{ href: url_for(only_path: false, overwrite_params: nil) }
- = blob.name
+ = @blob.name
%small
- = number_to_human_size(blob.raw_size)
+ = number_to_human_size(@blob.raw_size)
%a.gitlab-logo-wrapper{ href: url_for(only_path: false, overwrite_params: nil), title: 'view on gitlab' }
%img.gitlab-logo{ src: image_url('ext_snippet_icons/logo.svg'), alt: "GitLab logo" }
@@ -19,4 +18,4 @@
= embedded_snippet_download_button
%article.file-holder.snippet-file-content
- = render 'projects/blob/viewer', viewer: @snippet.blob.simple_viewer, load_async: false, external_embed: true
+ = render 'projects/blob/viewer', viewer: @blob.simple_viewer, load_async: false, external_embed: true
diff --git a/app/views/snippets/show.html.haml b/app/views/snippets/show.html.haml
index 30f760f2122..741e38e3d84 100644
--- a/app/views/snippets/show.html.haml
+++ b/app/views/snippets/show.html.haml
@@ -10,8 +10,7 @@
= render 'shared/snippets/header'
.personal-snippets
- %article.file-holder.snippet-file-content
- = render 'shared/snippets/blob'
+ = render 'shared/snippets/blob', blob: @blob
.row-content-block.top-block.content-component-block
= render 'award_emoji/awards_block', awardable: @snippet, inline: true