Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/serializers')
-rw-r--r--app/serializers/access_token_entity_base.rb8
-rw-r--r--app/serializers/environment_serializer.rb3
-rw-r--r--app/serializers/group_access_token_entity.rb6
-rw-r--r--app/serializers/impersonation_access_token_entity.rb11
-rw-r--r--app/serializers/impersonation_access_token_serializer.rb7
-rw-r--r--app/serializers/import/provider_repo_serializer.rb2
-rw-r--r--app/serializers/member_user_entity.rb4
-rw-r--r--app/serializers/merge_request_noteable_entity.rb15
-rw-r--r--app/serializers/merge_request_user_entity.rb12
-rw-r--r--app/serializers/personal_access_token_entity.rb2
-rw-r--r--app/serializers/project_access_token_entity.rb6
-rw-r--r--app/serializers/request_aware_entity.rb2
12 files changed, 57 insertions, 21 deletions
diff --git a/app/serializers/access_token_entity_base.rb b/app/serializers/access_token_entity_base.rb
new file mode 100644
index 00000000000..db22dbf1302
--- /dev/null
+++ b/app/serializers/access_token_entity_base.rb
@@ -0,0 +1,8 @@
+# frozen_string_literal: true
+
+# rubocop: disable Gitlab/NamespacedClass
+class AccessTokenEntityBase < API::Entities::PersonalAccessToken
+ expose :expired?, as: :expired
+ expose :expires_soon?, as: :expires_soon
+end
+# rubocop: enable Gitlab/NamespacedClass
diff --git a/app/serializers/environment_serializer.rb b/app/serializers/environment_serializer.rb
index 6363d6276a7..22839ba3099 100644
--- a/app/serializers/environment_serializer.rb
+++ b/app/serializers/environment_serializer.rb
@@ -96,8 +96,7 @@ class EnvironmentSerializer < BaseSerializer
scheduled_actions: [:metadata],
latest_successful_builds: []
},
- project: project_associations,
- deployment: []
+ project: project_associations
}
}
end
diff --git a/app/serializers/group_access_token_entity.rb b/app/serializers/group_access_token_entity.rb
index e832eef1188..ab1fbb8ab46 100644
--- a/app/serializers/group_access_token_entity.rb
+++ b/app/serializers/group_access_token_entity.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# rubocop: disable Gitlab/NamespacedClass
-class GroupAccessTokenEntity < API::Entities::PersonalAccessToken
+class GroupAccessTokenEntity < AccessTokenEntityBase
include Gitlab::Routing
expose :revoke_path do |token, options|
@@ -14,13 +14,13 @@ class GroupAccessTokenEntity < API::Entities::PersonalAccessToken
group_id: group.path)
end
- expose :access_level do |token, options|
+ expose :role do |token, options|
group = options.fetch(:group)
next unless group
next unless token.user
- group.member(token.user)&.access_level
+ group.member(token.user)&.human_access
end
end
# rubocop: enable Gitlab/NamespacedClass
diff --git a/app/serializers/impersonation_access_token_entity.rb b/app/serializers/impersonation_access_token_entity.rb
new file mode 100644
index 00000000000..b4ed62a890d
--- /dev/null
+++ b/app/serializers/impersonation_access_token_entity.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+# rubocop: disable Gitlab/NamespacedClass
+class ImpersonationAccessTokenEntity < AccessTokenEntityBase
+ include Gitlab::Routing
+
+ expose :revoke_path do |token, _options|
+ revoke_admin_user_impersonation_token_path(token.user, token)
+ end
+end
+# rubocop: enable Gitlab/NamespacedClass
diff --git a/app/serializers/impersonation_access_token_serializer.rb b/app/serializers/impersonation_access_token_serializer.rb
new file mode 100644
index 00000000000..d3ea5ceb305
--- /dev/null
+++ b/app/serializers/impersonation_access_token_serializer.rb
@@ -0,0 +1,7 @@
+# frozen_string_literal: true
+
+# rubocop: disable Gitlab/NamespacedClass
+class ImpersonationAccessTokenSerializer < BaseSerializer
+ entity ImpersonationAccessTokenEntity
+end
+# rubocop: enable Gitlab/NamespacedClass
diff --git a/app/serializers/import/provider_repo_serializer.rb b/app/serializers/import/provider_repo_serializer.rb
index edd1a260146..d5d29603989 100644
--- a/app/serializers/import/provider_repo_serializer.rb
+++ b/app/serializers/import/provider_repo_serializer.rb
@@ -23,3 +23,5 @@ class Import::ProviderRepoSerializer < BaseSerializer
super(repo, opts, entity)
end
end
+
+Import::ProviderRepoSerializer.prepend_mod
diff --git a/app/serializers/member_user_entity.rb b/app/serializers/member_user_entity.rb
index 6a01c5bb297..73cb9a4a798 100644
--- a/app/serializers/member_user_entity.rb
+++ b/app/serializers/member_user_entity.rb
@@ -16,6 +16,10 @@ class MemberUserEntity < UserEntity
user.blocked?
end
+ expose :is_bot do |user|
+ user.bot?
+ end
+
expose :two_factor_enabled, if: -> (user) { current_user_can_manage_members? || current_user?(user) } do |user|
user.two_factor_enabled?
end
diff --git a/app/serializers/merge_request_noteable_entity.rb b/app/serializers/merge_request_noteable_entity.rb
index f8c8e3538da..29bd26c3a15 100644
--- a/app/serializers/merge_request_noteable_entity.rb
+++ b/app/serializers/merge_request_noteable_entity.rb
@@ -10,6 +10,15 @@ class MergeRequestNoteableEntity < IssuableEntity
expose :state
expose :source_branch
expose :target_branch
+
+ expose :source_branch_path, if: -> (merge_request) { merge_request.source_project } do |merge_request|
+ project_tree_path(merge_request.source_project, merge_request.source_branch)
+ end
+
+ expose :target_branch_path, if: -> (merge_request) { merge_request.source_project } do |merge_request|
+ project_tree_path(merge_request.source_project, merge_request.target_branch)
+ end
+
expose :diff_head_sha
expose :create_note_path do |merge_request|
@@ -40,6 +49,10 @@ class MergeRequestNoteableEntity < IssuableEntity
expose :can_update do |merge_request|
can?(current_user, :update_merge_request, merge_request)
end
+
+ expose :can_approve do |merge_request|
+ merge_request.can_be_approved_by?(current_user)
+ end
end
expose :locked_discussion_docs_path, if: -> (merge_request) { merge_request.discussion_locked? } do |merge_request|
@@ -65,3 +78,5 @@ class MergeRequestNoteableEntity < IssuableEntity
@presenters[merge_request] ||= MergeRequestPresenter.new(merge_request, current_user: current_user) # rubocop: disable CodeReuse/Presenter
end
end
+
+MergeRequestNoteableEntity.prepend_mod_with('MergeRequestNoteableEntity')
diff --git a/app/serializers/merge_request_user_entity.rb b/app/serializers/merge_request_user_entity.rb
index 2e875af6531..36825d14062 100644
--- a/app/serializers/merge_request_user_entity.rb
+++ b/app/serializers/merge_request_user_entity.rb
@@ -17,7 +17,7 @@ class MergeRequestUserEntity < ::API::Entities::UserBasic
end
expose :reviewed, if: satisfies(:present?, :allows_reviewers?) do |user, options|
- find_reviewer_or_assignee(user, options)&.reviewed?
+ options[:merge_request].find_reviewer(user)&.reviewed?
end
expose :approved, if: satisfies(:present?) do |user, options|
@@ -25,16 +25,6 @@ class MergeRequestUserEntity < ::API::Entities::UserBasic
# makes one query per merge request, whereas #approved_by? makes one per user
options[:merge_request].approvals.any? { |app| app.user_id == user.id }
end
-
- private
-
- def find_reviewer_or_assignee(user, options)
- if options[:type] == :reviewers
- options[:merge_request].find_reviewer(user)
- else
- options[:merge_request].find_assignee(user)
- end
- end
end
MergeRequestUserEntity.prepend_mod_with('MergeRequestUserEntity')
diff --git a/app/serializers/personal_access_token_entity.rb b/app/serializers/personal_access_token_entity.rb
index acd06fecd12..49dcdf12a6f 100644
--- a/app/serializers/personal_access_token_entity.rb
+++ b/app/serializers/personal_access_token_entity.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# rubocop: disable Gitlab/NamespacedClass
-class PersonalAccessTokenEntity < API::Entities::PersonalAccessToken
+class PersonalAccessTokenEntity < AccessTokenEntityBase
include Gitlab::Routing
expose :revoke_path do |token, options|
diff --git a/app/serializers/project_access_token_entity.rb b/app/serializers/project_access_token_entity.rb
index b317057c952..52bb7b05d4e 100644
--- a/app/serializers/project_access_token_entity.rb
+++ b/app/serializers/project_access_token_entity.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# rubocop: disable Gitlab/NamespacedClass
-class ProjectAccessTokenEntity < API::Entities::PersonalAccessToken
+class ProjectAccessTokenEntity < AccessTokenEntityBase
include Gitlab::Routing
expose :revoke_path do |token, options|
@@ -15,13 +15,13 @@ class ProjectAccessTokenEntity < API::Entities::PersonalAccessToken
project_id: project.path)
end
- expose :access_level do |token, options|
+ expose :role do |token, options|
project = options.fetch(:project)
next unless project
next unless token.user
- project.member(token.user)&.access_level
+ project.member(token.user)&.human_access
end
end
# rubocop: enable Gitlab/NamespacedClass
diff --git a/app/serializers/request_aware_entity.rb b/app/serializers/request_aware_entity.rb
index 1524c1291d8..04caba43cf4 100644
--- a/app/serializers/request_aware_entity.rb
+++ b/app/serializers/request_aware_entity.rb
@@ -10,6 +10,6 @@ module RequestAwareEntity
end
def request
- options.fetch(:request)
+ options.fetch(:request, nil)
end
end