Commit 6348b76e authored by GitLab Bot's avatar GitLab Bot

Add latest changes from gitlab-org/gitlab@master

parent 03a70b84
...@@ -30,12 +30,26 @@ class AuditEvent < ApplicationRecord ...@@ -30,12 +30,26 @@ class AuditEvent < ApplicationRecord
end end
def author_name def author_name
self.user.name lazy_author.name
end end
def formatted_details def formatted_details
details.merge(details.slice(:from, :to).transform_values(&:to_s)) details.merge(details.slice(:from, :to).transform_values(&:to_s))
end end
def lazy_author
BatchLoader.for(author_id).batch(default_value: default_author_value) do |author_ids, loader|
User.where(id: author_ids).find_each do |user|
loader.call(user.id, user)
end
end
end
private
def default_author_value
::Gitlab::Audit::NullAuthor.for(author_id, details[:author_name])
end
end end
AuditEvent.prepend_if_ee('EE::AuditEvent') AuditEvent.prepend_if_ee('EE::AuditEvent')
...@@ -13,7 +13,7 @@ class AuditEventService ...@@ -13,7 +13,7 @@ class AuditEventService
# #
# @return [AuditEventService] # @return [AuditEventService]
def initialize(author, entity, details = {}) def initialize(author, entity, details = {})
@author = author @author = build_author(author)
@entity = entity @entity = entity
@details = details @details = details
end end
...@@ -49,6 +49,14 @@ class AuditEventService ...@@ -49,6 +49,14 @@ class AuditEventService
private private
def build_author(author)
if author.is_a?(User)
author
else
Gitlab::Audit::UnauthenticatedAuthor.new(name: author)
end
end
def base_payload def base_payload
{ {
author_id: @author.id, author_id: @author.id,
......
...@@ -9,72 +9,77 @@ module Snippets ...@@ -9,72 +9,77 @@ module Snippets
def execute def execute
filter_spam_check_params filter_spam_check_params
snippet = if project @snippet = if project
project.snippets.build(params) project.snippets.build(params)
else else
PersonalSnippet.new(params) PersonalSnippet.new(params)
end end
unless Gitlab::VisibilityLevel.allowed_for?(current_user, snippet.visibility_level) unless Gitlab::VisibilityLevel.allowed_for?(current_user, @snippet.visibility_level)
deny_visibility_level(snippet) deny_visibility_level(@snippet)
return snippet_error_response(snippet, 403) return snippet_error_response(@snippet, 403)
end end
snippet.author = current_user @snippet.author = current_user
spam_check(snippet, current_user) spam_check(@snippet, current_user)
if save_and_commit(snippet) if save_and_commit
UserAgentDetailService.new(snippet, @request).create UserAgentDetailService.new(@snippet, @request).create
Gitlab::UsageDataCounters::SnippetCounter.count(:create) Gitlab::UsageDataCounters::SnippetCounter.count(:create)
ServiceResponse.success(payload: { snippet: snippet } ) ServiceResponse.success(payload: { snippet: @snippet } )
else else
snippet_error_response(snippet, 400) snippet_error_response(@snippet, 400)
end end
end end
private private
def save_and_commit(snippet) def save_and_commit
snippet_saved = snippet.with_transaction_returning_status do snippet_saved = @snippet.with_transaction_returning_status do
snippet.save && snippet.store_mentions! @snippet.save && @snippet.store_mentions!
end end
if snippet_saved && Feature.enabled?(:version_snippets, current_user) if snippet_saved && Feature.enabled?(:version_snippets, current_user)
create_repository_for(snippet) create_repository
create_commit(snippet) create_commit
end end
snippet_saved snippet_saved
rescue => e # Rescuing all because we can receive Creation exceptions, GRPC exceptions, Git exceptions, ... rescue => e # Rescuing all because we can receive Creation exceptions, GRPC exceptions, Git exceptions, ...
snippet.errors.add(:base, e.message)
log_error(e.message) log_error(e.message)
# If the commit action failed we need to remove the repository if exists # If the commit action failed we need to remove the repository if exists
snippet.repository.remove if snippet.repository_exists? @snippet.repository.remove if @snippet.repository_exists?
# If the snippet was created, we need to remove it as we # If the snippet was created, we need to remove it as we
# would do like if it had had any validation error # would do like if it had had any validation error
snippet.delete if snippet.persisted? # and reassign a dupe so we don't return the deleted snippet
if @snippet.persisted?
@snippet.delete
@snippet = @snippet.dup
end
@snippet.errors.add(:base, e.message)
false false
end end
def create_repository_for(snippet) def create_repository
snippet.create_repository @snippet.create_repository
raise CreateRepositoryError, 'Repository could not be created' unless snippet.repository_exists? raise CreateRepositoryError, 'Repository could not be created' unless @snippet.repository_exists?
end end
def create_commit(snippet) def create_commit
commit_attrs = { commit_attrs = {
branch_name: 'master', branch_name: 'master',
message: 'Initial commit' message: 'Initial commit'
} }
snippet.snippet_repository.multi_files_action(current_user, snippet_files, commit_attrs) @snippet.snippet_repository.multi_files_action(current_user, snippet_files, commit_attrs)
end end
def snippet_files def snippet_files
......
---
title: Resolve Snippet creation failure bug
merge_request: 27891
author:
type: fixed
---
title: Add DS_REMEDIATE env var to dependency scanning template
merge_request: 27947
author:
type: added
...@@ -160,7 +160,7 @@ class Gitlab::Seeder::CycleAnalytics ...@@ -160,7 +160,7 @@ class Gitlab::Seeder::CycleAnalytics
creator: admin, creator: admin,
namespace: FactoryBot.create( namespace: FactoryBot.create(
:group, :group,
name: "Value Stream Management Group (#{suffix})", name: "Value Stream Management Group #{suffix}",
path: "vsmg-#{suffix}" path: "vsmg-#{suffix}"
) )
) )
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
To enable the Custom Issue Tracker integration in a project, navigate to the To enable the Custom Issue Tracker integration in a project, navigate to the
[Integrations page](project_services.md#accessing-the-project-services), click [Integrations page](project_services.md#accessing-the-project-services), click
the **Customer Issue Tracker** service, and fill in the required details on the page as described the **Customer Issue Tracker** service, and fill in the required details on the page as described
in the table below. in the table below. You will be able to edit the title and description later as well.
| Field | Description | | Field | Description |
| ----- | ----------- | | ----- | ----------- |
...@@ -17,6 +17,9 @@ Once you have configured and enabled Custom Issue Tracker Service you'll see a l ...@@ -17,6 +17,9 @@ Once you have configured and enabled Custom Issue Tracker Service you'll see a l
## Referencing issues ## Referencing issues
- Issues are referenced with `ANYTHING-<ID>`, where `ANYTHING` can be any string and `<ID>` is a number used in the target project of the custom integration (example `PROJECT-143`). - Issues are referenced with `ANYTHING-<ID>`, where `ANYTHING` can be any string in CAPS and `<ID>`
is a number used in the target project of the custom integration (for example, `PROJECT-143`).
- `ANYTHING` is a placeholder to differentiate against GitLab issues, which are referenced with `#<ID>`. You can use a project name or project key to replace it for example. - `ANYTHING` is a placeholder to differentiate against GitLab issues, which are referenced with `#<ID>`. You can use a project name or project key to replace it for example.
- So with the example above, `PROJECT-143` would refer to `https://customissuetracker.com/project-name/143`. - When building the hyperlink, the `ANYTHING` part is ignored, and links always point to the address
specified in `issues_url`, so in the example above, `PROJECT-143` would refer to
`https://customissuetracker.com/project-name/143`.
...@@ -62,6 +62,7 @@ dependency_scanning: ...@@ -62,6 +62,7 @@ dependency_scanning:
BUNDLER_AUDIT_ADVISORY_DB_REF_NAME \ BUNDLER_AUDIT_ADVISORY_DB_REF_NAME \
RETIREJS_JS_ADVISORY_DB \ RETIREJS_JS_ADVISORY_DB \
RETIREJS_NODE_ADVISORY_DB \ RETIREJS_NODE_ADVISORY_DB \
DS_REMEDIATE \
) \ ) \
--volume "$PWD:/code" \ --volume "$PWD:/code" \
--volume /var/run/docker.sock:/var/run/docker.sock \ --volume /var/run/docker.sock:/var/run/docker.sock \
......
...@@ -5,7 +5,6 @@ module QA ...@@ -5,7 +5,6 @@ module QA
module Project module Project
module Settings module Settings
class Members < Page::Base class Members < Page::Base
include Page::Component::UsersSelect
include QA::Page::Component::Select2 include QA::Page::Component::Select2
view 'app/views/shared/members/_invite_member.html.haml' do view 'app/views/shared/members/_invite_member.html.haml' do
...@@ -43,7 +42,8 @@ module QA ...@@ -43,7 +42,8 @@ module QA
end end
def add_member(username) def add_member(username)
select_user :member_select_field, username click_element :member_select_field
search_and_select username
click_element :invite_member_button click_element :invite_member_button
end end
......
...@@ -99,6 +99,11 @@ shared_examples_for 'snippet editor' do ...@@ -99,6 +99,11 @@ shared_examples_for 'snippet editor' do
it 'renders new page' do it 'renders new page' do
expect(page).to have_content('New Snippet') expect(page).to have_content('New Snippet')
end end
it 'has the correct action path' do
action = find('form.snippet-form')['action']
expect(action).to match(%r{/snippets\z})
end
end end
it 'validation fails for the first time' do it 'validation fails for the first time' do
......
...@@ -172,6 +172,10 @@ describe Snippets::CreateService do ...@@ -172,6 +172,10 @@ describe Snippets::CreateService do
it 'returns the error' do it 'returns the error' do
expect(snippet.errors.full_messages).to include('Repository could not be created') expect(snippet.errors.full_messages).to include('Repository could not be created')
end end
it 'does not return a snippet with an id' do
expect(snippet.id).to be_nil
end
end end
context 'when the commit action fails' do context 'when the commit action fails' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment