summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-01-26 18:08:47 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-01-26 18:08:47 +0000
commit3cf907da69b58dd56121b44fc2a95bd0ce197ea2 (patch)
tree1a6e8d0f3163b4844fd992d0bb41acc93bf7d66e
parent1a18b430890a59ad846deed3a8e88f54e9db4c35 (diff)
downloadgitlab-ce-3cf907da69b58dd56121b44fc2a95bd0ce197ea2.tar.gz
Add latest changes from gitlab-org/gitlab@master
-rw-r--r--changelogs/unreleased/refactoring-entities-file-2.yml5
-rw-r--r--lib/api/entities.rb59
-rw-r--r--lib/api/entities/user.rb10
-rw-r--r--lib/api/entities/user_activity.rb11
-rw-r--r--lib/api/entities/user_basic.rb20
-rw-r--r--lib/api/entities/user_details_with_admin.rb11
-rw-r--r--lib/api/entities/user_public.rb19
-rw-r--r--lib/api/entities/user_safe.rb9
-rw-r--r--lib/api/entities/user_stars_project.rb10
-rw-r--r--lib/api/entities/user_with_admin.rb9
10 files changed, 104 insertions, 59 deletions
diff --git a/changelogs/unreleased/refactoring-entities-file-2.yml b/changelogs/unreleased/refactoring-entities-file-2.yml
new file mode 100644
index 00000000000..f3c2eda70b2
--- /dev/null
+++ b/changelogs/unreleased/refactoring-entities-file-2.yml
@@ -0,0 +1,5 @@
+---
+title: Refactor user entities into own class files
+merge_request: 23730
+author: Rajendra Kadam
+type: added
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 872432f0cd7..62eb30f2edf 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -11,69 +11,10 @@ module API
expose :access_level
end
- class UserSafe < Grape::Entity
- expose :id, :name, :username
- end
-
- class UserBasic < UserSafe
- expose :state
-
- expose :avatar_url do |user, options|
- user.avatar_url(only_path: false)
- end
-
- expose :avatar_path, if: ->(user, options) { options.fetch(:only_path, false) && user.avatar_path }
- expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes
-
- expose :web_url do |user, options|
- Gitlab::Routing.url_helpers.user_url(user)
- end
- end
-
- class User < UserBasic
- expose :created_at, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) }
- expose :bio, :location, :public_email, :skype, :linkedin, :twitter, :website_url, :organization
- end
-
- class UserActivity < Grape::Entity
- expose :username
- expose :last_activity_on
- expose :last_activity_on, as: :last_activity_at # Back-compat
- end
-
- class UserStarsProject < Grape::Entity
- expose :starred_since
- expose :user, using: Entities::UserBasic
- end
-
class Identity < Grape::Entity
expose :provider, :extern_uid
end
- class UserPublic < User
- expose :last_sign_in_at
- expose :confirmed_at
- expose :last_activity_on
- expose :email
- expose :theme_id, :color_scheme_id, :projects_limit, :current_sign_in_at
- expose :identities, using: Entities::Identity
- expose :can_create_group?, as: :can_create_group
- expose :can_create_project?, as: :can_create_project
- expose :two_factor_enabled?, as: :two_factor_enabled
- expose :external
- expose :private_profile
- end
-
- class UserWithAdmin < UserPublic
- expose :admin?, as: :is_admin
- end
-
- class UserDetailsWithAdmin < UserWithAdmin
- expose :highest_role
- expose :current_sign_in_ip
- expose :last_sign_in_ip
- end
-
class UserStatus < Grape::Entity
expose :emoji
expose :message
diff --git a/lib/api/entities/user.rb b/lib/api/entities/user.rb
new file mode 100644
index 00000000000..15e4619cdb8
--- /dev/null
+++ b/lib/api/entities/user.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class User < UserBasic
+ expose :created_at, if: ->(user, opts) { Ability.allowed?(opts[:current_user], :read_user_profile, user) }
+ expose :bio, :location, :public_email, :skype, :linkedin, :twitter, :website_url, :organization
+ end
+ end
+end
diff --git a/lib/api/entities/user_activity.rb b/lib/api/entities/user_activity.rb
new file mode 100644
index 00000000000..30c23cc7a67
--- /dev/null
+++ b/lib/api/entities/user_activity.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class UserActivity < Grape::Entity
+ expose :username
+ expose :last_activity_on
+ expose :last_activity_on, as: :last_activity_at # Back-compat
+ end
+ end
+end
diff --git a/lib/api/entities/user_basic.rb b/lib/api/entities/user_basic.rb
new file mode 100644
index 00000000000..e063aa42855
--- /dev/null
+++ b/lib/api/entities/user_basic.rb
@@ -0,0 +1,20 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class UserBasic < UserSafe
+ expose :state
+
+ expose :avatar_url do |user, options|
+ user.avatar_url(only_path: false)
+ end
+
+ expose :avatar_path, if: ->(user, options) { options.fetch(:only_path, false) && user.avatar_path }
+ expose :custom_attributes, using: 'API::Entities::CustomAttribute', if: :with_custom_attributes
+
+ expose :web_url do |user, options|
+ Gitlab::Routing.url_helpers.user_url(user)
+ end
+ end
+ end
+end
diff --git a/lib/api/entities/user_details_with_admin.rb b/lib/api/entities/user_details_with_admin.rb
new file mode 100644
index 00000000000..9ea5c583437
--- /dev/null
+++ b/lib/api/entities/user_details_with_admin.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class UserDetailsWithAdmin < UserWithAdmin
+ expose :highest_role
+ expose :current_sign_in_ip
+ expose :last_sign_in_ip
+ end
+ end
+end
diff --git a/lib/api/entities/user_public.rb b/lib/api/entities/user_public.rb
new file mode 100644
index 00000000000..100f73760ca
--- /dev/null
+++ b/lib/api/entities/user_public.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class UserPublic < Entities::User
+ expose :last_sign_in_at
+ expose :confirmed_at
+ expose :last_activity_on
+ expose :email
+ expose :theme_id, :color_scheme_id, :projects_limit, :current_sign_in_at
+ expose :identities, using: Entities::Identity
+ expose :can_create_group?, as: :can_create_group
+ expose :can_create_project?, as: :can_create_project
+ expose :two_factor_enabled?, as: :two_factor_enabled
+ expose :external
+ expose :private_profile
+ end
+ end
+end
diff --git a/lib/api/entities/user_safe.rb b/lib/api/entities/user_safe.rb
new file mode 100644
index 00000000000..feb01767fd6
--- /dev/null
+++ b/lib/api/entities/user_safe.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class UserSafe < Grape::Entity
+ expose :id, :name, :username
+ end
+ end
+end
diff --git a/lib/api/entities/user_stars_project.rb b/lib/api/entities/user_stars_project.rb
new file mode 100644
index 00000000000..3e087c17c2d
--- /dev/null
+++ b/lib/api/entities/user_stars_project.rb
@@ -0,0 +1,10 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class UserStarsProject < Grape::Entity
+ expose :starred_since
+ expose :user, using: Entities::UserBasic
+ end
+ end
+end
diff --git a/lib/api/entities/user_with_admin.rb b/lib/api/entities/user_with_admin.rb
new file mode 100644
index 00000000000..c2f873ae802
--- /dev/null
+++ b/lib/api/entities/user_with_admin.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+module API
+ module Entities
+ class UserWithAdmin < UserPublic
+ expose :admin?, as: :is_admin
+ end
+ end
+end