diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-21 12:10:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-21 12:10:07 +0300 |
commit | 081c20decabe2154802daedc9cd1f7fcee2165ed (patch) | |
tree | 7e26fe4080f1a90de74fe0621218a8eabce7f28a /app | |
parent | 020afca7491c6c9178e8dd1c6d79562430e74ee0 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/diffs/utils/diff_file.js | 11 | ||||
-rw-r--r-- | app/assets/javascripts/diffs/utils/merge_request.js | 18 | ||||
-rw-r--r-- | app/helpers/visibility_level_helper.rb | 110 |
3 files changed, 49 insertions, 90 deletions
diff --git a/app/assets/javascripts/diffs/utils/diff_file.js b/app/assets/javascripts/diffs/utils/diff_file.js index 69d0e49e501..2cb88e34856 100644 --- a/app/assets/javascripts/diffs/utils/diff_file.js +++ b/app/assets/javascripts/diffs/utils/diff_file.js @@ -4,6 +4,7 @@ import { DIFF_FILE_MANUAL_COLLAPSE, DIFF_FILE_AUTOMATIC_COLLAPSE, } from '../constants'; +import { getDerivedMergeRequestInformation } from './merge_request'; import { uuids } from './uuids'; function fileSymlinkInformation(file, fileList) { @@ -34,8 +35,12 @@ function collapsed(file) { } function identifier(file) { + const { userOrGroup, project, id } = getDerivedMergeRequestInformation({ + endpoint: file.load_collapsed_diff_url, + }); + return uuids({ - seeds: [file.file_identifier_hash, file.blob?.id], + seeds: [userOrGroup, project, id, file.file_identifier_hash, file.blob?.id], })[0]; } @@ -48,10 +53,10 @@ export function prepareRawDiffFile({ file, allFiles, meta = false }) { }, }; - // It's possible, but not confirmed, that `content_sha` isn't available sometimes + // It's possible, but not confirmed, that `blob.id` isn't available sometimes // See: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/49506#note_464692057 // We don't want duplicate IDs if that's the case, so we just don't assign an ID - if (!meta && file.blob?.id) { + if (!meta && file.blob?.id && file.load_collapsed_diff_url) { additionalProperties.id = identifier(file); } diff --git a/app/assets/javascripts/diffs/utils/merge_request.js b/app/assets/javascripts/diffs/utils/merge_request.js index 10e2a4b2cf2..edb4304f558 100644 --- a/app/assets/javascripts/diffs/utils/merge_request.js +++ b/app/assets/javascripts/diffs/utils/merge_request.js @@ -1,10 +1,20 @@ +const endpointRE = /^(\/?(.+?)\/(.+?)\/-\/merge_requests\/(\d+)).*$/i; + export function getDerivedMergeRequestInformation({ endpoint } = {}) { - const mrPath = endpoint - ?.split('/') - .slice(0, -1) - .join('/'); + let mrPath; + let userOrGroup; + let project; + let id; + const matches = endpointRE.exec(endpoint); + + if (matches) { + [, mrPath, userOrGroup, project, id] = matches; + } return { mrPath, + userOrGroup, + project, + id, }; } diff --git a/app/helpers/visibility_level_helper.rb b/app/helpers/visibility_level_helper.rb index 0a37257e124..696f29164fd 100644 --- a/app/helpers/visibility_level_helper.rb +++ b/app/helpers/visibility_level_helper.rb @@ -26,76 +26,6 @@ module VisibilityLevelHelper end end - def project_visibility_level_description(level) - case level - when Gitlab::VisibilityLevel::PRIVATE - _("Project access must be granted explicitly to each user. If this project is part of a group, access will be granted to members of the group.") - when Gitlab::VisibilityLevel::INTERNAL - _("The project can be accessed by any logged in user except external users.") - when Gitlab::VisibilityLevel::PUBLIC - _("The project can be accessed without any authentication.") - end - end - - def group_visibility_level_description(level) - case level - when Gitlab::VisibilityLevel::PRIVATE - _("The group and its projects can only be viewed by members.") - when Gitlab::VisibilityLevel::INTERNAL - _("The group and any internal projects can be viewed by any logged in user except external users.") - when Gitlab::VisibilityLevel::PUBLIC - _("The group and any public projects can be viewed without any authentication.") - end - end - - # Note: these messages closely mirror the form validation strings found in the project - # model and any changes or additons to these may also need to be made there. - def disallowed_project_visibility_level_description(level, project) - level_name = Gitlab::VisibilityLevel.level_name(level).downcase - reasons = [] - instructions = [] - - unless project.visibility_level_allowed_as_fork?(level) - reasons << "the fork source project has lower visibility" - end - - unless project.visibility_level_allowed_by_group?(level) - errors = visibility_level_errors_for_group(project.group, level_name) - - reasons << errors[:reason] - instructions << errors[:instruction] - end - - reasons = reasons.any? ? ' because ' + reasons.to_sentence : '' - "This project cannot be #{level_name}#{reasons}.#{instructions.join}".html_safe - end - - # Note: these messages closely mirror the form validation strings found in the group - # model and any changes or additons to these may also need to be made there. - def disallowed_group_visibility_level_description(level, group) - level_name = Gitlab::VisibilityLevel.level_name(level).downcase - reasons = [] - instructions = [] - - unless group.visibility_level_allowed_by_projects?(level) - reasons << "it contains projects with higher visibility" - end - - unless group.visibility_level_allowed_by_sub_groups?(level) - reasons << "it contains sub-groups with higher visibility" - end - - unless group.visibility_level_allowed_by_parent?(level) - errors = visibility_level_errors_for_group(group.parent, level_name) - - reasons << errors[:reason] - instructions << errors[:instruction] - end - - reasons = reasons.any? ? ' because ' + reasons.to_sentence : '' - "This group cannot be #{level_name}#{reasons}.#{instructions.join}".html_safe - end - def visibility_icon_description(form_model) if form_model.respond_to?(:visibility_level_allowed_as_fork?) project_visibility_icon_description(form_model.visibility_level) @@ -104,14 +34,6 @@ module VisibilityLevelHelper end end - def group_visibility_icon_description(level) - "#{visibility_level_label(level)} - #{group_visibility_level_description(level)}" - end - - def project_visibility_icon_description(level) - "#{visibility_level_label(level)} - #{project_visibility_level_description(level)}" - end - def visibility_level_label(level) # The visibility level can be: # 'VisibilityLevel|Private', 'VisibilityLevel|Internal', 'VisibilityLevel|Public' @@ -203,11 +125,33 @@ module VisibilityLevelHelper current_level end - def visibility_level_errors_for_group(group, level_name) - group_name = link_to group.name, group_path(group) - change_visibility = link_to 'change the visibility', edit_group_path(group) + def project_visibility_level_description(level) + case level + when Gitlab::VisibilityLevel::PRIVATE + _("Project access must be granted explicitly to each user. If this project is part of a group, access will be granted to members of the group.") + when Gitlab::VisibilityLevel::INTERNAL + _("The project can be accessed by any logged in user except external users.") + when Gitlab::VisibilityLevel::PUBLIC + _("The project can be accessed without any authentication.") + end + end + + def group_visibility_level_description(level) + case level + when Gitlab::VisibilityLevel::PRIVATE + _("The group and its projects can only be viewed by members.") + when Gitlab::VisibilityLevel::INTERNAL + _("The group and any internal projects can be viewed by any logged in user except external users.") + when Gitlab::VisibilityLevel::PUBLIC + _("The group and any public projects can be viewed without any authentication.") + end + end - { reason: "the visibility of #{group_name} is #{group.visibility}", - instruction: " To make this group #{level_name}, you must first #{change_visibility} of the parent group." } + def project_visibility_icon_description(level) + "#{visibility_level_label(level)} - #{project_visibility_level_description(level)}" + end + + def group_visibility_icon_description(level) + "#{visibility_level_label(level)} - #{group_visibility_level_description(level)}" end end |