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

Add latest changes from gitlab-org/gitlab@master

parent 5c521d1f
No related branches found
No related tags found
No related merge requests found
Showing
with 138 additions and 27 deletions
Loading
Loading
@@ -5,7 +5,7 @@ class Explore::SnippetsController < Explore::ApplicationController
include Gitlab::NoteableMetadata
 
def index
@snippets = SnippetsFinder.new(current_user)
@snippets = SnippetsFinder.new(current_user, explore: true)
.execute
.page(params[:page])
.inc_author
Loading
Loading
Loading
Loading
@@ -50,8 +50,6 @@ class NotificationSettingsController < ApplicationController
end
 
def notification_setting_params_for(source)
allowed_fields = NotificationSetting.email_events(source).dup
allowed_fields << :level
params.require(:notification_setting).permit(allowed_fields)
params.require(:notification_setting).permit(NotificationSetting.allowed_fields(source))
end
end
Loading
Loading
@@ -5,7 +5,7 @@ class Profiles::GroupsController < Profiles::ApplicationController
 
def update
group = find_routable!(Group, params[:id])
notification_setting = current_user.notification_settings.find_by(source: group) # rubocop: disable CodeReuse/ActiveRecord
notification_setting = current_user.notification_settings_for(group)
 
if notification_setting.update(update_params)
flash[:notice] = "Notification settings for #{group.name} saved"
Loading
Loading
Loading
Loading
@@ -3,9 +3,14 @@
class Profiles::NotificationsController < Profiles::ApplicationController
# rubocop: disable CodeReuse/ActiveRecord
def show
@user = current_user
@group_notifications = current_user.notification_settings.for_groups.order(:id)
@project_notifications = current_user.notification_settings.for_projects.order(:id)
@user = current_user
@group_notifications = current_user.notification_settings.for_groups.order(:id)
@group_notifications += GroupsFinder.new(
current_user,
all_available: false,
exclude_group_ids: @group_notifications.select(:source_id)
).execute.map { |group| current_user.notification_settings_for(group, inherit: true) }
@project_notifications = current_user.notification_settings.for_projects.order(:id)
@global_notification_setting = current_user.global_notification_setting
end
# rubocop: enable CodeReuse/ActiveRecord
Loading
Loading
Loading
Loading
@@ -41,13 +41,14 @@
class SnippetsFinder < UnionFinder
include FinderMethods
 
attr_accessor :current_user, :project, :author, :scope
attr_accessor :current_user, :project, :author, :scope, :explore
 
def initialize(current_user = nil, params = {})
@current_user = current_user
@project = params[:project]
@author = params[:author]
@scope = params[:scope].to_s
@explore = params[:explore]
 
if project && author
raise(
Loading
Loading
@@ -66,13 +67,23 @@ class SnippetsFinder < UnionFinder
private
 
def init_collection
if project
if explore
snippets_for_explore
elsif project
snippets_for_a_single_project
else
snippets_for_multiple_projects
end
end
 
# Produces a query that retrieves snippets for the Explore page
#
# We only show personal snippets here because this page is meant for
# discovery, and project snippets are of limited interest here.
def snippets_for_explore
Snippet.public_to_user(current_user).only_personal_snippets
end
# Produces a query that retrieves snippets from multiple projects.
#
# The resulting query will, depending on the user's permissions, include the
Loading
Loading
@@ -86,7 +97,7 @@ class SnippetsFinder < UnionFinder
# Each collection is constructed in isolation, allowing for greater control
# over the resulting SQL query.
def snippets_for_multiple_projects
queries = [global_snippets]
queries = [personal_snippets]
 
if Ability.allowed?(current_user, :read_cross_project)
queries << snippets_of_visible_projects
Loading
Loading
@@ -100,8 +111,8 @@ class SnippetsFinder < UnionFinder
Snippet.for_project_with_user(project, current_user)
end
 
def global_snippets
snippets_for_author_or_visible_to_user.only_global_snippets
def personal_snippets
snippets_for_author_or_visible_to_user.only_personal_snippets
end
 
# Returns the snippets that the current user (logged in or not) can view.
Loading
Loading
Loading
Loading
@@ -11,15 +11,15 @@ module Stepable
initial_result = {}
 
steps.inject(initial_result) do |previous_result, callback|
result = method(callback).call
result = method(callback).call(previous_result)
 
if result[:status] == :error
result[:failed_step] = callback
if result[:status] != :success
result[:last_step] = callback
 
break result
end
 
previous_result.merge(result)
result
end
end
 
Loading
Loading
Loading
Loading
@@ -47,6 +47,10 @@ class NotificationSetting < ApplicationRecord
EMAIL_EVENTS
end
 
def self.allowed_fields(source = nil)
NotificationSetting.email_events(source).dup + %i(level notification_email)
end
def email_events
self.class.email_events(source)
end
Loading
Loading
Loading
Loading
@@ -71,7 +71,7 @@ class Snippet < ApplicationRecord
end
end
 
def self.only_global_snippets
def self.only_personal_snippets
where(project_id: nil)
end
 
Loading
Loading
Loading
Loading
@@ -1317,14 +1317,27 @@ class User < ApplicationRecord
notification_group&.notification_email_for(self) || notification_email
end
 
def notification_settings_for(source)
def notification_settings_for(source, inherit: false)
if notification_settings.loaded?
notification_settings.find do |notification|
notification.source_type == source.class.base_class.name &&
notification.source_id == source.id
end
else
notification_settings.find_or_initialize_by(source: source)
notification_settings.find_or_initialize_by(source: source) do |ns|
next unless source.is_a?(Group) && inherit
# If we're here it means we're trying to create a NotificationSetting for a group that doesn't have one.
# Find the closest parent with a notification_setting that's not Global level, or that has an email set.
ancestor_ns = source
.notification_settings(hierarchy_order: :asc)
.where(user: self)
.find_by('level != ? OR notification_email IS NOT NULL', NotificationSetting.levels[:global])
# Use it to seed the settings
ns.assign_attributes(ancestor_ns&.slice(*NotificationSetting.allowed_fields))
ns.source = source
ns.user = self
end
end
end
 
Loading
Loading
Loading
Loading
@@ -20,7 +20,11 @@ module ApplicationSettings
add_to_outbound_local_requests_whitelist(@params.delete(:add_to_outbound_local_requests_whitelist))
 
if params.key?(:performance_bar_allowed_group_path)
params[:performance_bar_allowed_group_id] = performance_bar_allowed_group_id
group_id = process_performance_bar_allowed_group_id
return false if application_setting.errors.any?
params[:performance_bar_allowed_group_id] = group_id
end
 
if usage_stats_updated? && !params.delete(:skip_usage_stats_user)
Loading
Loading
@@ -65,12 +69,27 @@ module ApplicationSettings
@application_setting.reset_memoized_terms
end
 
def performance_bar_allowed_group_id
performance_bar_enabled = !params.key?(:performance_bar_enabled) || params.delete(:performance_bar_enabled)
def process_performance_bar_allowed_group_id
group_full_path = params.delete(:performance_bar_allowed_group_path)
return unless Gitlab::Utils.to_boolean(performance_bar_enabled)
enable_param_on = Gitlab::Utils.to_boolean(params.delete(:performance_bar_enabled))
performance_bar_enabled = enable_param_on.nil? || enable_param_on # Default to true
return if group_full_path.blank?
return if enable_param_on == false # Explicitly disabling
unless performance_bar_enabled
application_setting.errors.add(:performance_bar_allowed_group_id, 'not allowed when performance bar is disabled')
return
end
group = Group.find_by_full_path(group_full_path.chomp('/'))
unless group
application_setting.errors.add(:performance_bar_allowed_group_id, 'not found')
return
end
 
Group.find_by_full_path(group_full_path)&.id if group_full_path.present?
group.id
end
 
def bypass_external_auth?
Loading
Loading
Loading
Loading
@@ -5,6 +5,8 @@
= auto_discovery_link_tag(:atom, group_url(@group, rss_url_options), title: "#{@group.name} activity")
 
%div{ class: [("limit-container-width" unless fluid_layout)] }
= render_if_exists 'trials/banner', namespace: @group
= render 'groups/home_panel'
 
.groups-listing{ data: { endpoints: { default: group_children_path(@group, format: :json), shared: group_shared_projects_path(@group, format: :json) } } }
Loading
Loading
Loading
Loading
@@ -12,5 +12,5 @@
= render 'shared/notifications/button', notification_setting: setting, emails_disabled: emails_disabled
 
.table-section.section-30
= form_for @user.notification_settings.find { |ns| ns.source == group }, url: profile_notifications_group_path(group), method: :put, html: { class: 'update-notifications' } do |f|
= form_for setting, url: profile_notifications_group_path(group), method: :put, html: { class: 'update-notifications' } do |f|
= f.select :notification_email, @user.all_emails, { include_blank: 'Global notification email' }, class: 'select2 js-group-notification-email'
---
title: Show all groups user belongs to in Notification settings
merge_request: 17303
author:
type: fixed
---
title: Show only personal snippets on explore page
merge_request: 18092
author:
type: performance
---
title: Resolve missing design system notes icons
merge_request: 18693
author:
type: fixed
---
title: Show error message when setting an invalid group ID for the performance bar
merge_request:
author:
type: fixed
---
title: Sort vulnerabilities by severity then confidence for dashboard and pipeline views
merge_request: 18675
author:
type: changed
# frozen_string_literal: true
class AddIndexOnSnippetsProjectIdAndVisibilityLevel < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
add_concurrent_index :snippets, [:project_id, :visibility_level]
end
def down
remove_concurrent_index :snippets, [:project_id, :visibility_level]
end
end
# frozen_string_literal: true
class RemoveIndexOnSnippetsProjectId < ActiveRecord::Migration[5.2]
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
disable_ddl_transaction!
def up
remove_concurrent_index :snippets, [:project_id]
end
def down
add_concurrent_index :snippets, [:project_id]
end
end
Loading
Loading
@@ -3449,7 +3449,7 @@ ActiveRecord::Schema.define(version: 2019_10_16_220135) do
t.index ["author_id"], name: "index_snippets_on_author_id"
t.index ["content"], name: "index_snippets_on_content_trigram", opclass: :gin_trgm_ops, using: :gin
t.index ["file_name"], name: "index_snippets_on_file_name_trigram", opclass: :gin_trgm_ops, using: :gin
t.index ["project_id"], name: "index_snippets_on_project_id"
t.index ["project_id", "visibility_level"], name: "index_snippets_on_project_id_and_visibility_level"
t.index ["title"], name: "index_snippets_on_title_trigram", opclass: :gin_trgm_ops, using: :gin
t.index ["updated_at"], name: "index_snippets_on_updated_at"
t.index ["visibility_level"], name: "index_snippets_on_visibility_level"
Loading
Loading
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