Skip to content
Snippets Groups Projects
Commit b98fa9ef authored by GitLab Bot's avatar GitLab Bot
Browse files

Add latest changes from gitlab-org/gitlab@master

parent 7e300596
No related branches found
No related tags found
No related merge requests found
Showing
with 87 additions and 53 deletions
import { viewerInformationForPath } from '~/vue_shared/components/content_viewer/lib/viewer_utils'; import { viewerInformationForPath } from '~/vue_shared/components/content_viewer/lib/viewer_utils';
import { escapeFileUrl } from '~/lib/utils/url_utility';
import { decorateData, sortTree } from '../stores/utils'; import { decorateData, sortTree } from '../stores/utils';
   
export const splitParent = path => { export const splitParent = path => {
Loading
@@ -48,7 +47,7 @@ export const decorateFiles = ({
Loading
@@ -48,7 +47,7 @@ export const decorateFiles = ({
id: path, id: path,
name, name,
path, path,
url: `/${projectId}/tree/${branchId}/-/${escapeFileUrl(path)}/`, url: `/${projectId}/tree/${branchId}/-/${path}/`,
type: 'tree', type: 'tree',
parentTreeUrl: parentFolder ? parentFolder.url : `/${projectId}/tree/${branchId}/`, parentTreeUrl: parentFolder ? parentFolder.url : `/${projectId}/tree/${branchId}/`,
tempFile, tempFile,
Loading
@@ -85,7 +84,7 @@ export const decorateFiles = ({
Loading
@@ -85,7 +84,7 @@ export const decorateFiles = ({
id: path, id: path,
name, name,
path, path,
url: `/${projectId}/blob/${branchId}/-/${escapeFileUrl(path)}`, url: `/${projectId}/blob/${branchId}/-/${path}`,
type: 'blob', type: 'blob',
parentTreeUrl: fileFolder ? fileFolder.url : `/${projectId}/blob/${branchId}`, parentTreeUrl: fileFolder ? fileFolder.url : `/${projectId}/blob/${branchId}`,
tempFile, tempFile,
Loading
Loading
import { commitActionTypes, FILE_VIEW_MODE_EDITOR } from '../constants'; import { commitActionTypes, FILE_VIEW_MODE_EDITOR } from '../constants';
import { escapeFileUrl } from '~/lib/utils/url_utility';
   
export const dataStructure = () => ({ export const dataStructure = () => ({
id: '', id: '',
Loading
@@ -220,9 +219,7 @@ export const mergeTrees = (fromTree, toTree) => {
Loading
@@ -220,9 +219,7 @@ export const mergeTrees = (fromTree, toTree) => {
   
export const replaceFileUrl = (url, oldPath, newPath) => { export const replaceFileUrl = (url, oldPath, newPath) => {
// Add `/-/` so that we don't accidentally replace project path // Add `/-/` so that we don't accidentally replace project path
const result = url.replace(`/-/${escapeFileUrl(oldPath)}`, `/-/${escapeFileUrl(newPath)}`); return url.replace(`/-/${oldPath}`, `/-/${newPath}`);
return result;
}; };
   
export const swapInStateArray = (state, arr, key, entryPath) => export const swapInStateArray = (state, arr, key, entryPath) =>
Loading
Loading
<script> <script>
import { omit } from 'underscore'; import { omit } from 'lodash';
import { GlEmptyState, GlPagination, GlSkeletonLoading } from '@gitlab/ui'; import { GlEmptyState, GlPagination, GlSkeletonLoading } from '@gitlab/ui';
import flash from '~/flash'; import flash from '~/flash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
Loading
Loading
<script> <script>
import FileHeader from '~/vue_shared/components/file_row_header.vue'; import FileHeader from '~/vue_shared/components/file_row_header.vue';
import FileIcon from '~/vue_shared/components/file_icon.vue'; import FileIcon from '~/vue_shared/components/file_icon.vue';
import { escapeFileUrl } from '~/lib/utils/url_utility';
   
export default { export default {
name: 'FileRow', name: 'FileRow',
Loading
@@ -94,7 +95,7 @@ export default {
Loading
@@ -94,7 +95,7 @@ export default {
hasUrlAtCurrentRoute() { hasUrlAtCurrentRoute() {
if (!this.$router || !this.$router.currentRoute) return true; 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)}`;
}, },
}, },
}; };
Loading
Loading
Loading
@@ -6,20 +6,18 @@ module SnippetsActions
Loading
@@ -6,20 +6,18 @@ module SnippetsActions
def edit def edit
end end
   
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def raw def raw
disposition = params[:inline] == 'false' ? 'attachment' : 'inline' disposition = params[:inline] == 'false' ? 'attachment' : 'inline'
   
workhorse_set_content_type! workhorse_set_content_type!
   
send_data( send_data(
convert_line_endings(@snippet.content), convert_line_endings(blob.data),
type: 'text/plain; charset=utf-8', type: 'text/plain; charset=utf-8',
disposition: disposition, disposition: disposition,
filename: @snippet.sanitized_file_name filename: Snippet.sanitized_file_name(blob.name)
) )
end end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
   
def js_request? def js_request?
request.format.js? request.format.js?
Loading
Loading
Loading
@@ -66,7 +66,6 @@ class Projects::SnippetsController < Projects::ApplicationController
Loading
@@ -66,7 +66,6 @@ class Projects::SnippetsController < Projects::ApplicationController
end end
   
def show def show
blob = @snippet.blob
conditionally_expand_blob(blob) conditionally_expand_blob(blob)
   
respond_to do |format| respond_to do |format|
Loading
@@ -115,6 +114,16 @@ class Projects::SnippetsController < Projects::ApplicationController
Loading
@@ -115,6 +114,16 @@ class Projects::SnippetsController < Projects::ApplicationController
alias_method :awardable, :snippet alias_method :awardable, :snippet
alias_method :spammable, :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 def spammable_path
project_snippet_path(@project, @snippet) project_snippet_path(@project, @snippet)
end end
Loading
Loading
Loading
@@ -68,17 +68,15 @@ class SnippetsController < ApplicationController
Loading
@@ -68,17 +68,15 @@ class SnippetsController < ApplicationController
end end
   
def show def show
blob = @snippet.blob
conditionally_expand_blob(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| respond_to do |format|
format.html do 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' render 'show'
end end
   
Loading
@@ -121,6 +119,16 @@ class SnippetsController < ApplicationController
Loading
@@ -121,6 +119,16 @@ class SnippetsController < ApplicationController
alias_method :awardable, :snippet alias_method :awardable, :snippet
alias_method :spammable, :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 def spammable_path
snippet_path(@snippet) snippet_path(@snippet)
end end
Loading
Loading
Loading
@@ -62,6 +62,7 @@ module Types
Loading
@@ -62,6 +62,7 @@ module Types
   
field :blob, type: Types::Snippets::BlobType, field :blob, type: Types::Snippets::BlobType,
description: 'Snippet blob', description: 'Snippet blob',
calls_gitaly: true,
null: false null: false
   
markdown_field :description_html, null: true, method: :description markdown_field :description_html, null: true, method: :description
Loading
Loading
# frozen_string_literal: true # frozen_string_literal: true
   
# Applicable for blob classes with project attribute
module BlobLanguageFromGitAttributes module BlobLanguageFromGitAttributes
extend ActiveSupport::Concern extend ActiveSupport::Concern
   
def language_from_gitattributes def language_from_gitattributes
return unless project return unless repository&.exists?
   
repository = project.repository
repository.gitattribute(path, 'gitlab-language') repository.gitattribute(path, 'gitlab-language')
end end
end end
Loading
@@ -197,7 +197,11 @@ class Snippet < ApplicationRecord
Loading
@@ -197,7 +197,11 @@ class Snippet < ApplicationRecord
end end
   
def blob 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 end
   
def hook_attrs def hook_attrs
Loading
@@ -208,7 +212,7 @@ class Snippet < ApplicationRecord
Loading
@@ -208,7 +212,7 @@ class Snippet < ApplicationRecord
super.to_s super.to_s
end end
   
def sanitized_file_name def self.sanitized_file_name(file_name)
file_name.gsub(/[^a-zA-Z0-9_\-\.]+/, '') file_name.gsub(/[^a-zA-Z0-9_\-\.]+/, '')
end end
   
Loading
Loading
Loading
@@ -32,7 +32,7 @@ class SnippetBlobPresenter < BlobPresenter
Loading
@@ -32,7 +32,7 @@ class SnippetBlobPresenter < BlobPresenter
end end
   
def snippet def snippet
blob.snippet blob.container
end end
   
def language def language
Loading
Loading
Loading
@@ -27,6 +27,14 @@ class SnippetPresenter < Gitlab::View::Presenter::Delegated
Loading
@@ -27,6 +27,14 @@ class SnippetPresenter < Gitlab::View::Presenter::Delegated
snippet.submittable_as_spam_by?(current_user) snippet.submittable_as_spam_by?(current_user)
end end
   
def blob
if Feature.enabled?(:version_snippets, current_user) && !snippet.repository.empty?
snippet.blobs.first
else
snippet.blob
end
end
private private
   
def can_access_resource?(ability_prefix) def can_access_resource?(ability_prefix)
Loading
Loading
Loading
@@ -3,14 +3,13 @@
Loading
@@ -3,14 +3,13 @@
class AuditEventService class AuditEventService
# Instantiates a new service # Instantiates a new service
# #
# @param author [User] the user who authors the change # @param [User] author the user who authors the change
# @param entity [Object] an instance of either Project/Group/User type. This # @param [User, Project, Group] entity the scope which audit event belongs to
# param is also used to determine at which level the audit events are # This param is also used to determine the visibility of the audit event.
# shown. # - Project: events are visible at Project and Instance level
# - Project: events are visible at Project level # - Group: events are visible at Group and Instance level
# - Group: events are visible at Group level
# - User: events are visible at 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] # @return [AuditEventService]
def initialize(author, entity, details = {}) def initialize(author, entity, details = {})
Loading
@@ -21,7 +20,7 @@ class AuditEventService
Loading
@@ -21,7 +20,7 @@ class AuditEventService
   
# Builds the @details attribute for authentication # 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] # @return [AuditEventService]
def for_authentication def for_authentication
Loading
Loading
Loading
@@ -9,8 +9,7 @@
Loading
@@ -9,8 +9,7 @@
= render 'shared/snippets/header' = render 'shared/snippets/header'
   
.project-snippets .project-snippets
%article.file-holder.snippet-file-content = render 'shared/snippets/blob', blob: @blob
= render 'shared/snippets/blob'
   
.row-content-block.top-block.content-component-block .row-content-block.top-block.content-component-block
= render 'award_emoji/awards_block', awardable: @snippet, inline: true = render 'award_emoji/awards_block', awardable: @snippet, inline: true
Loading
Loading
- blob = @snippet.blob %article.file-holder.snippet-file-content
.js-file-title.file-title-flex-parent .js-file-title.file-title-flex-parent
= render 'projects/blob/header_content', blob: blob = render 'projects/blob/header_content', blob: blob
   
.file-actions.d-none.d-sm-block .file-actions.d-none.d-sm-block
= render 'projects/blob/viewer_switcher', blob: blob = render 'projects/blob/viewer_switcher', blob: blob
   
.btn-group{ role: "group" }< .btn-group{ role: "group" }<
= copy_blob_source_button(blob) = copy_blob_source_button(blob)
= open_raw_blob_button(blob) = open_raw_blob_button(blob)
= download_raw_snippet_button(@snippet) = download_raw_snippet_button(@snippet)
   
= render 'projects/blob/content', blob: blob = render 'projects/blob/content', blob: blob
- blob = @snippet.blob
.gitlab-embed-snippets .gitlab-embed-snippets
.js-file-title.file-title-flex-parent .js-file-title.file-title-flex-parent
.file-header-content .file-header-content
Loading
@@ -6,10 +5,10 @@
Loading
@@ -6,10 +5,10 @@
   
%strong.file-title-name %strong.file-title-name
%a.gitlab-embedded-snippets-title{ href: url_for(only_path: false, overwrite_params: nil) } %a.gitlab-embedded-snippets-title{ href: url_for(only_path: false, overwrite_params: nil) }
= blob.name = @blob.name
   
%small %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' } %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" } %img.gitlab-logo{ src: image_url('ext_snippet_icons/logo.svg'), alt: "GitLab logo" }
   
Loading
@@ -19,4 +18,4 @@
Loading
@@ -19,4 +18,4 @@
   
= embedded_snippet_download_button = embedded_snippet_download_button
%article.file-holder.snippet-file-content %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
Loading
@@ -10,8 +10,7 @@
Loading
@@ -10,8 +10,7 @@
= render 'shared/snippets/header' = render 'shared/snippets/header'
   
.personal-snippets .personal-snippets
%article.file-holder.snippet-file-content = render 'shared/snippets/blob', blob: @blob
= render 'shared/snippets/blob'
   
.row-content-block.top-block.content-component-block .row-content-block.top-block.content-component-block
= render 'award_emoji/awards_block', awardable: @snippet, inline: true = render 'award_emoji/awards_block', awardable: @snippet, inline: true
Loading
Loading
---
title: Fixed regression when URL was encoded in a loop
merge_request: 25849
author:
type: fixed
---
title: 'Fix: tableflip quick action is interpreted even if inside code block'
merge_request:
author: Pavlo Dudchenko
type: fixed
---
title: Render single snippet blob in repository
merge_request: 23848
author:
type: added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment