Commit 7f4e4d28 authored by Stan Hu's avatar Stan Hu

Merge branch 'refactoring-entities-file-15' into 'master'

Separate access classes into own class files

See merge request gitlab-org/gitlab!24845
parents 04d8f2f0 01f8766c
---
title: Separate access entities into own class files
merge_request: 24845
author: Rajendra Kadam
type: added
...@@ -129,40 +129,6 @@ module API ...@@ -129,40 +129,6 @@ module API
end end
end end
class Namespace < NamespaceBasic
expose :members_count_with_descendants, if: -> (namespace, opts) { expose_members_count_with_descendants?(namespace, opts) } do |namespace, _|
namespace.users_with_descendants.count
end
def expose_members_count_with_descendants?(namespace, opts)
namespace.kind == 'group' && Ability.allowed?(opts[:current_user], :admin_group, namespace)
end
end
class MemberAccess < Grape::Entity
expose :access_level
expose :notification_level do |member, options|
if member.notification_setting
::NotificationSetting.levels[member.notification_setting.level]
end
end
end
class ProjectAccess < MemberAccess
end
class GroupAccess < MemberAccess
end
class NotificationSetting < Grape::Entity
expose :level
expose :events, if: ->(notification_setting, _) { notification_setting.custom? } do
::NotificationSetting.email_events.each do |event|
expose event
end
end
end
class Trigger < Grape::Entity class Trigger < Grape::Entity
include ::API::Helpers::Presentable include ::API::Helpers::Presentable
......
# frozen_string_literal: true
module API
module Entities
class GroupAccess < MemberAccess
end
end
end
# frozen_string_literal: true
module API
module Entities
class MemberAccess < Grape::Entity
expose :access_level
expose :notification_level do |member, options|
if member.notification_setting
::NotificationSetting.levels[member.notification_setting.level]
end
end
end
end
end
# frozen_string_literal: true
module API
module Entities
class Namespace < Entities::NamespaceBasic
expose :members_count_with_descendants, if: -> (namespace, opts) { expose_members_count_with_descendants?(namespace, opts) } do |namespace, _|
namespace.users_with_descendants.count
end
def expose_members_count_with_descendants?(namespace, opts)
namespace.kind == 'group' && Ability.allowed?(opts[:current_user], :admin_group, namespace)
end
end
end
end
# frozen_string_literal: true
module API
module Entities
class NotificationSetting < Grape::Entity
expose :level
expose :events, if: ->(notification_setting, _) { notification_setting.custom? } do
::NotificationSetting.email_events.each do |event|
expose event
end
end
end
end
end
# frozen_string_literal: true
module API
module Entities
class ProjectAccess < Entities::MemberAccess
end
end
end
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