entities.rb 28.3 KB
Newer Older
1
module API
N
Nihad Abbasov 已提交
2
  module Entities
3 4 5
    class UserSafe < Grape::Entity
      expose :name, :username
    end
6

7
    class UserBasic < UserSafe
8 9 10 11
      expose :id, :state
      expose :avatar_url do |user, options|
        user.avatar_url(only_path: false)
      end
D
Douwe Maan 已提交
12 13

      expose :web_url do |user, options|
14
        Gitlab::Routing.url_helpers.user_url(user)
D
Douwe Maan 已提交
15
      end
N
Nihad Abbasov 已提交
16
    end
N
Nihad Abbasov 已提交
17

18 19
    class User < UserBasic
      expose :created_at
20
      expose :bio, :location, :skype, :linkedin, :twitter, :website_url, :organization
21 22
    end

23 24
    class UserActivity < Grape::Entity
      expose :username
25 26
      expose :last_activity_on
      expose :last_activity_on, as: :last_activity_at # Back-compat
27 28
    end

29 30 31 32
    class Identity < Grape::Entity
      expose :provider, :extern_uid
    end

33
    class UserPublic < User
34 35
      expose :last_sign_in_at
      expose :confirmed_at
36
      expose :last_activity_on
37
      expose :email
38
      expose :color_scheme_id, :projects_limit, :current_sign_in_at
39
      expose :identities, using: Entities::Identity
40 41
      expose :can_create_group?, as: :can_create_group
      expose :can_create_project?, as: :can_create_project
42
      expose :two_factor_enabled?, as: :two_factor_enabled
43
      expose :external
44 45
    end

46
    class UserWithAdmin < UserPublic
47
      expose :admin?, as: :is_admin
48 49
    end

50 51 52 53
    class UserWithPrivateDetails < UserWithAdmin
      expose :private_token
    end

54 55 56 57
    class Email < Grape::Entity
      expose :id, :email
    end

M
miks 已提交
58
    class Hook < Grape::Entity
59
      expose :id, :url, :created_at, :push_events, :tag_push_events, :repository_update_events
60
      expose :enable_ssl_verification
M
miks 已提交
61 62
    end

63
    class ProjectHook < Hook
64
      expose :project_id, :issues_events, :merge_requests_events
65
      expose :note_events, :pipeline_events, :wiki_page_events
66
      expose :job_events
67 68
    end

69
    class BasicProjectDetails < Grape::Entity
70
      expose :id
71
      expose :http_url_to_repo, :web_url
72 73 74 75
      expose :name, :name_with_namespace
      expose :path, :path_with_namespace
    end

76 77 78 79 80 81 82 83
    class SharedGroup < Grape::Entity
      expose :group_id
      expose :group_name do |group_link, options|
        group_link.group.name
      end
      expose :group_access, as: :group_access_level
    end

N
Nihad Abbasov 已提交
84
    class Project < Grape::Entity
85
      expose :id, :description, :default_branch, :tag_list
86
      expose :archived?, as: :archived
87
      expose :visibility, :ssh_url_to_repo, :http_url_to_repo, :web_url
88
      expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group }
89
      expose :name, :name_with_namespace
90
      expose :path, :path_with_namespace
F
Felipe Artur 已提交
91 92 93
      expose :container_registry_enabled

      # Expose old field names with the new permissions methods to keep API compatible
94 95 96
      expose(:issues_enabled) { |project, options| project.feature_available?(:issues, options[:current_user]) }
      expose(:merge_requests_enabled) { |project, options| project.feature_available?(:merge_requests, options[:current_user]) }
      expose(:wiki_enabled) { |project, options| project.feature_available?(:wiki, options[:current_user]) }
97
      expose(:jobs_enabled) { |project, options| project.feature_available?(:builds, options[:current_user]) }
98
      expose(:snippets_enabled) { |project, options| project.feature_available?(:snippets, options[:current_user]) }
F
Felipe Artur 已提交
99

100
      expose :created_at, :last_activity_at
101 102
      expose :shared_runners_enabled
      expose :lfs_enabled?, as: :lfs_enabled
103
      expose :creator_id
104
      expose :namespace, using: 'API::Entities::Namespace'
105
      expose :forked_from_project, using: Entities::BasicProjectDetails, if: lambda{ |project, options| project.forked? }
106 107
      expose :import_status
      expose :import_error, if: lambda { |_project, options| options[:user_can_admin_project] }
108 109 110
      expose :avatar_url do |user, options|
        user.avatar_url(only_path: false)
      end
111
      expose :star_count, :forks_count
112
      expose :open_issues_count, if: lambda { |project, options| project.feature_available?(:issues, options[:current_user]) }
113
      expose :runners_token, if: lambda { |_project, options| options[:user_can_admin_project] }
114
      expose :public_builds, as: :public_jobs
115
      expose :ci_config_path
116 117 118
      expose :shared_with_groups do |project, options|
        SharedGroup.represent(project.project_group_links.all, options)
      end
J
James Lopez 已提交
119
      expose :only_allow_merge_if_pipeline_succeeds
120
      expose :request_access_enabled
121
      expose :only_allow_merge_if_all_discussions_are_resolved
122
      expose :printing_merge_request_link_enabled
M
Markus Koller 已提交
123 124 125 126 127 128 129 130 131

      expose :statistics, using: 'API::Entities::ProjectStatistics', if: :statistics
    end

    class ProjectStatistics < Grape::Entity
      expose :commit_count
      expose :storage_size
      expose :repository_size
      expose :lfs_objects_size
132
      expose :build_artifacts_size, as: :job_artifacts_size
N
Nihad Abbasov 已提交
133 134
    end

135
    class Member < UserBasic
D
Dmitriy Zaporozhets 已提交
136
      expose :access_level do |user, options|
137
        member = options[:member] || options[:source].members.find_by(user_id: user.id)
138 139
        member.access_level
      end
140
      expose :expires_at do |user, options|
141
        member = options[:member] || options[:source].members.find_by(user_id: user.id)
142 143
        member.expires_at
      end
144 145 146 147
    end

    class AccessRequester < UserBasic
      expose :requested_at do |user, options|
148
        access_requester = options[:access_requester] || options[:source].requesters.find_by(user_id: user.id)
149
        access_requester.requested_at
N
Nihad Abbasov 已提交
150
      end
M
miks 已提交
151 152
    end

153
    class Group < Grape::Entity
154
      expose :id, :name, :path, :description, :visibility
155
      expose :lfs_enabled?, as: :lfs_enabled
156 157 158
      expose :avatar_url do |user, options|
        user.avatar_url(only_path: false)
      end
R
Rémy Coutable 已提交
159
      expose :web_url
160
      expose :request_access_enabled
161
      expose :full_name, :full_path
162 163 164 165

      if ::Group.supports_nested_groups?
        expose :parent_id
      end
M
Markus Koller 已提交
166 167 168 169 170 171

      expose :statistics, if: :statistics do
        with_options format_with: -> (value) { value.to_i } do
          expose :storage_size
          expose :repository_size
          expose :lfs_objects_size
172
          expose :build_artifacts_size, as: :job_artifacts_size
M
Markus Koller 已提交
173 174
        end
      end
175
    end
A
Andrew8xx8 已提交
176

177
    class GroupDetail < Group
178
      expose :projects, using: Entities::Project
179
      expose :shared_projects, using: Entities::Project
180 181
    end

182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
    class RepoCommit < Grape::Entity
      expose :id, :short_id, :title, :created_at
      expose :parent_ids
      expose :safe_message, as: :message
      expose :author_name, :author_email, :authored_date
      expose :committer_name, :committer_email, :committed_date
    end

    class RepoCommitStats < Grape::Entity
      expose :additions, :deletions, :total
    end

    class RepoCommitDetail < RepoCommit
      expose :stats, using: Entities::RepoCommitStats
      expose :status
    end

199
    class RepoBranch < Grape::Entity
200 201
      expose :name

202
      expose :commit, using: Entities::RepoCommit do |repo_branch, options|
203
        options[:project].repository.commit(repo_branch.dereferenced_target)
204 205
      end

R
Robert Schilling 已提交
206 207 208 209
      expose :merged do |repo_branch, options|
        options[:project].repository.merged_to_root_ref?(repo_branch.name)
      end

210
      expose :protected do |repo_branch, options|
211
        ProtectedBranch.protected?(options[:project], repo_branch.name)
212 213
      end

214
      expose :developers_can_push do |repo_branch, options|
215
        options[:project].protected_branches.developers_can?(:push, repo_branch.name)
216
      end
217

218
      expose :developers_can_merge do |repo_branch, options|
219
        options[:project].protected_branches.developers_can?(:merge, repo_branch.name)
220
      end
N
Nihad Abbasov 已提交
221
    end
N
Nihad Abbasov 已提交
222

223
    class RepoTreeObject < Grape::Entity
224
      expose :id, :name, :type, :path
225 226

      expose :mode do |obj, options|
M
mhasbini 已提交
227
        filemode = obj.mode
228 229 230 231 232
        filemode = "0" + filemode if filemode.length < 6
        filemode
      end
    end

N
Nihad Abbasov 已提交
233
    class ProjectSnippet < Grape::Entity
234
      expose :id, :title, :file_name, :description
235
      expose :author, using: Entities::UserBasic
R
Robert Speicher 已提交
236
      expose :updated_at, :created_at
237

238 239 240
      expose :web_url do |snippet, options|
        Gitlab::UrlBuilder.build(snippet)
      end
N
Nihad Abbasov 已提交
241
    end
N
Nihad Abbasov 已提交
242

243
    class PersonalSnippet < Grape::Entity
244
      expose :id, :title, :file_name, :description
245 246 247 248 249 250 251 252 253 254 255
      expose :author, using: Entities::UserBasic
      expose :updated_at, :created_at

      expose :web_url do |snippet|
        Gitlab::UrlBuilder.build(snippet)
      end
      expose :raw_url do |snippet|
        Gitlab::UrlBuilder.build(snippet) + "/raw"
      end
    end

256 257
    class ProjectEntity < Grape::Entity
      expose :id, :iid
F
Felipe Artur 已提交
258
      expose(:project_id) { |entity| entity&.project.try(:id) }
259 260
      expose :title, :description
      expose :state, :created_at, :updated_at
261 262
    end

263 264
    class RepoDiff < Grape::Entity
      expose :old_path, :new_path, :a_mode, :b_mode, :diff
265 266 267
      expose :new_file?, as: :new_file
      expose :renamed_file?, as: :renamed_file
      expose :deleted_file?, as: :deleted_file
268 269
    end

F
Felipe Artur 已提交
270 271 272 273 274 275
    class Milestone < Grape::Entity
      expose :id, :iid
      expose(:project_id) { |entity| entity&.project_id }
      expose(:group_id) { |entity| entity&.group_id }
      expose :title, :description
      expose :state, :created_at, :updated_at
276
      expose :due_date
V
Valery Sizov 已提交
277
      expose :start_date
N
Nihad Abbasov 已提交
278 279
    end

280
    class IssueBasic < ProjectEntity
281
      expose :label_names, as: :labels
282
      expose :milestone, using: Entities::Milestone
283 284 285 286 287
      expose :assignees, :author, using: Entities::UserBasic

      expose :assignee, using: ::API::Entities::UserBasic do |issue, options|
        issue.assignees.first
      end
288

Z
Z.J. van de Weg 已提交
289
      expose :user_notes_count
Z
Zeger-Jan van de Weg 已提交
290
      expose :upvotes, :downvotes
291
      expose :due_date
292
      expose :confidential
293 294 295 296

      expose :web_url do |issue, options|
        Gitlab::UrlBuilder.build(issue)
      end
N
Nihad Abbasov 已提交
297
    end
A
Alex Denisov 已提交
298

299 300 301 302 303 304
    class Issue < IssueBasic
      expose :subscribed do |issue, options|
        issue.subscribed?(options[:current_user], options[:project] || issue.project)
      end
    end

305 306 307 308 309 310 311
    class IssuableTimeStats < Grape::Entity
      expose :time_estimate
      expose :total_time_spent
      expose :human_time_estimate
      expose :human_total_time_spent
    end

312 313 314 315 316
    class ExternalIssue < Grape::Entity
      expose :title
      expose :id
    end

S
Stan Hu 已提交
317 318 319 320 321 322 323
    class MergeRequestSimple < ProjectEntity
      expose :title
      expose :web_url do |merge_request, options|
        Gitlab::UrlBuilder.build(merge_request)
      end
    end

324
    class MergeRequestBasic < ProjectEntity
V
Valery Sizov 已提交
325
      expose :target_branch, :source_branch
326 327 328 329 330 331 332 333 334 335 336 337 338 339
      expose :upvotes do |merge_request, options|
        if options[:issuable_metadata]
          options[:issuable_metadata][merge_request.id].upvotes
        else
          merge_request.upvotes
        end
      end
      expose :downvotes do |merge_request, options|
        if options[:issuable_metadata]
          options[:issuable_metadata][merge_request.id].downvotes
        else
          merge_request.downvotes
        end
      end
340 341
      expose :author, :assignee, using: Entities::UserBasic
      expose :source_project_id, :target_project_id
342 343 344 345
      expose :labels do |merge_request, options|
        # Avoids an N+1 query since labels are preloaded
        merge_request.labels.map(&:title).sort
      end
B
Ben Boeckel 已提交
346
      expose :work_in_progress?, as: :work_in_progress
347
      expose :milestone, using: Entities::Milestone
J
James Lopez 已提交
348
      expose :merge_when_pipeline_succeeds
349
      expose :merge_status
350 351
      expose :diff_head_sha, as: :sha
      expose :merge_commit_sha
Z
Z.J. van de Weg 已提交
352
      expose :user_notes_count
353 354
      expose :should_remove_source_branch?, as: :should_remove_source_branch
      expose :force_remove_source_branch?, as: :force_remove_source_branch
355 356 357 358

      expose :web_url do |merge_request, options|
        Gitlab::UrlBuilder.build(merge_request)
      end
A
Alex Denisov 已提交
359
    end
V
Valeriy Sizov 已提交
360

361 362 363 364 365 366
    class MergeRequest < MergeRequestBasic
      expose :subscribed do |merge_request, options|
        merge_request.subscribed?(options[:current_user], options[:project])
      end
    end

367 368
    class MergeRequestChanges < MergeRequest
      expose :diffs, as: :changes, using: Entities::RepoDiff do |compare, _|
D
Douwe Maan 已提交
369
        compare.raw_diffs(limits: false).to_a
370 371 372
      end
    end

373 374 375
    class MergeRequestDiff < Grape::Entity
      expose :id, :head_commit_sha, :base_commit_sha, :start_commit_sha,
        :created_at, :merge_request_id, :state, :real_size
376
    end
377

378
    class MergeRequestDiffFull < MergeRequestDiff
379 380 381
      expose :commits, using: Entities::RepoCommit

      expose :diffs, using: Entities::RepoDiff do |compare, _|
D
Douwe Maan 已提交
382
        compare.raw_diffs(limits: false).to_a
383 384 385
      end
    end

386
    class SSHKey < Grape::Entity
387
      expose :id, :title, :key, :created_at, :can_push
V
Valeriy Sizov 已提交
388
    end
389

390
    class SSHKeyWithUser < SSHKey
391
      expose :user, using: Entities::UserPublic
392 393
    end

394
    class Note < Grape::Entity
395 396
      expose :id
      expose :note, as: :body
397
      expose :attachment_identifier, as: :attachment
398
      expose :author, using: Entities::UserBasic
399
      expose :created_at, :updated_at
400
      expose :system?, as: :system
D
Dmitriy Zaporozhets 已提交
401
      expose :noteable_id, :noteable_type
402
    end
403

Z
Z.J. van de Weg 已提交
404 405 406 407 408 409 410 411
    class AwardEmoji < Grape::Entity
      expose :id
      expose :name
      expose :user, using: Entities::UserBasic
      expose :created_at, :updated_at
      expose :awardable_id, :awardable_type
    end

412 413 414 415
    class MRNote < Grape::Entity
      expose :note
      expose :author, using: Entities::UserBasic
    end
D
Dmitriy Zaporozhets 已提交
416

417 418
    class CommitNote < Grape::Entity
      expose :note
419 420 421
      expose(:path) { |note| note.diff_file.try(:file_path) if note.diff_note? }
      expose(:line) { |note| note.diff_line.try(:new_line) if note.diff_note? }
      expose(:line_type) { |note| note.diff_line.try(:type) if note.diff_note? }
422
      expose :author, using: Entities::UserBasic
423
      expose :created_at
424 425
    end

K
Kamil Trzcinski 已提交
426 427
    class CommitStatus < Grape::Entity
      expose :id, :sha, :ref, :status, :name, :target_url, :description,
428
             :created_at, :started_at, :finished_at, :allow_failure, :coverage
K
Kamil Trzcinski 已提交
429
      expose :author, using: Entities::UserBasic
K
Kamil Trzcinski 已提交
430 431
    end

D
Dmitriy Zaporozhets 已提交
432 433 434 435
    class Event < Grape::Entity
      expose :title, :project_id, :action_name
      expose :target_id, :target_type, :author_id
      expose :data, :target_title
436
      expose :created_at
D
Dmitriy Zaporozhets 已提交
437 438
      expose :note, using: Entities::Note, if: ->(event, options) { event.note? }
      expose :author, using: Entities::UserBasic, if: ->(event, options) { event.author }
439 440

      expose :author_username do |event, options|
Z
Z.J. van de Weg 已提交
441
        event.author&.username
442
      end
D
Dmitriy Zaporozhets 已提交
443
    end
444

445
    class ProjectGroupLink < Grape::Entity
446
      expose :id, :project_id, :group_id, :group_access, :expires_at
447 448
    end

D
Douglas Barbosa Alexandre 已提交
449 450 451 452
    class Todo < Grape::Entity
      expose :id
      expose :project, using: Entities::BasicProjectDetails
      expose :author, using: Entities::UserBasic
R
Robert Schilling 已提交
453
      expose :action_name
D
Douglas Barbosa Alexandre 已提交
454
      expose :target_type
455 456

      expose :target do |todo, options|
457 458
        target = todo.target_type == 'Commit' ? 'RepoCommit' : todo.target_type
        Entities.const_get(target).represent(todo.target, options)
D
Douglas Barbosa Alexandre 已提交
459 460 461 462 463
      end

      expose :target_url do |todo, options|
        target_type   = todo.target_type.underscore
        target_url    = "namespace_project_#{target_type}_url"
464
        target_anchor = "note_#{todo.note_id}" if todo.note_id?
D
Douglas Barbosa Alexandre 已提交
465

466
        Gitlab::Routing.url_helpers.public_send(target_url,
D
Douglas Barbosa Alexandre 已提交
467 468 469 470 471 472 473 474
          todo.project.namespace, todo.project, todo.target, anchor: target_anchor)
      end

      expose :body
      expose :state
      expose :created_at
    end

475
    class Namespace < Grape::Entity
476 477
      expose :id, :name, :path, :kind, :full_path, :parent_id

478 479 480 481 482 483
      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)
484
      end
485
    end
486

487
    class MemberAccess < Grape::Entity
D
Dmitriy Zaporozhets 已提交
488
      expose :access_level
489 490
      expose :notification_level do |member, options|
        if member.notification_setting
491
          ::NotificationSetting.levels[member.notification_setting.level]
492 493
        end
      end
494 495
    end

496
    class ProjectAccess < MemberAccess
497 498
    end

499
    class GroupAccess < MemberAccess
500 501
    end

502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
    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 GlobalNotificationSetting < NotificationSetting
      expose :notification_email do |notification_setting, options|
        notification_setting.user.notification_email
      end
    end

517 518
    class ProjectService < Grape::Entity
      expose :id, :title, :created_at, :updated_at, :active
519
      expose :push_events, :issues_events, :merge_requests_events
520
      expose :tag_push_events, :note_events, :pipeline_events
521
      expose :job_events
522 523
      # Expose serialized properties
      expose :properties do |service, options|
524 525 526
        field_names = service.fields
          .select { |field| options[:include_passwords] || field[:type] != 'password' }
          .map { |field| field[:name] }
527 528 529 530
        service.properties.slice(*field_names)
      end
    end

531 532 533
    class ProjectWithAccess < Project
      expose :permissions do
        expose :project_access, using: Entities::ProjectAccess do |project, options|
534 535 536 537 538
          if options.key?(:project_members)
            (options[:project_members] || []).find { |member| member.source_id == project.id }
          else
            project.project_members.find_by(user_id: options[:current_user].id)
          end
539 540 541
        end

        expose :group_access, using: Entities::GroupAccess do |project, options|
542
          if project.group
543 544 545 546 547
            if options.key?(:group_members)
              (options[:group_members] || []).find { |member| member.source_id == project.namespace_id }
            else
              project.group.group_members.find_by(user_id: options[:current_user].id)
            end
548
          end
549 550 551
        end
      end
    end
552

A
Andre Guedes 已提交
553
    class LabelBasic < Grape::Entity
R
Rares Sfirlogea 已提交
554
      expose :id, :name, :color, :description
A
Andre Guedes 已提交
555 556 557
    end

    class Label < LabelBasic
558
      expose :open_issues_count do |label, options|
F
Francesco Coda Zabetta 已提交
559 560
        label.open_issues_count(options[:current_user])
      end
561

F
Francesco Coda Zabetta 已提交
562 563 564
      expose :closed_issues_count do |label, options|
        label.closed_issues_count(options[:current_user])
      end
565

F
Francesco Coda Zabetta 已提交
566 567
      expose :open_merge_requests_count do |label, options|
        label.open_merge_requests_count(options[:current_user])
568 569
      end

570 571 572
      expose :priority do |label, options|
        label.priority(options[:project])
      end
573 574

      expose :subscribed do |label, options|
575
        label.subscribed?(options[:current_user], options[:project])
576
      end
577
    end
578

A
Andre Guedes 已提交
579 580 581 582 583 584 585 586 587 588 589 590 591
    class List < Grape::Entity
      expose :id
      expose :label, using: Entities::LabelBasic
      expose :position
    end

    class Board < Grape::Entity
      expose :id
      expose :lists, using: Entities::List do |board|
        board.lists.destroyable
      end
    end

592 593
    class Compare < Grape::Entity
      expose :commit, using: Entities::RepoCommit do |compare, options|
594
        Commit.decorate(compare.commits, nil).last
595
      end
596

597
      expose :commits, using: Entities::RepoCommit do |compare, options|
598
        Commit.decorate(compare.commits, nil)
599
      end
600

601
      expose :diffs, using: Entities::RepoDiff do |compare, options|
D
Douwe Maan 已提交
602
        compare.diffs(limits: false).to_a
603
      end
604 605

      expose :compare_timeout do |compare, options|
J
Jacob Vosmaer 已提交
606
        compare.diffs.overflow?
607 608 609
      end

      expose :same, as: :compare_same_ref
610
    end
611 612 613 614

    class Contributor < Grape::Entity
      expose :name, :email, :commits, :additions, :deletions
    end
D
Douwe Maan 已提交
615 616 617 618

    class BroadcastMessage < Grape::Entity
      expose :message, :starts_at, :ends_at, :color, :font
    end
619 620 621 622 623

    class ApplicationSetting < Grape::Entity
      expose :id
      expose :default_projects_limit
      expose :signup_enabled
624 625
      expose :password_authentication_enabled
      expose :password_authentication_enabled, as: :signin_enabled
626 627
      expose :gravatar_enabled
      expose :sign_in_text
628
      expose :after_sign_up_text
629 630 631 632
      expose :created_at
      expose :updated_at
      expose :home_page_url
      expose :default_branch_protection
633 634 635
      expose(:restricted_visibility_levels) do |setting, _options|
        setting.restricted_visibility_levels.map { |level| Gitlab::VisibilityLevel.string_level(level) }
      end
636 637
      expose :max_attachment_size
      expose :session_expire_delay
638 639 640
      expose(:default_project_visibility) { |setting, _options| Gitlab::VisibilityLevel.string_level(setting.default_project_visibility) }
      expose(:default_snippet_visibility) { |setting, _options| Gitlab::VisibilityLevel.string_level(setting.default_snippet_visibility) }
      expose(:default_group_visibility) { |setting, _options| Gitlab::VisibilityLevel.string_level(setting.default_group_visibility) }
641
      expose :default_artifacts_expire_in
642
      expose :domain_whitelist
643 644
      expose :domain_blacklist_enabled
      expose :domain_blacklist
645 646
      expose :user_oauth_applications
      expose :after_sign_out_path
647
      expose :container_registry_token_expire_delay
648
      expose :repository_storage
649
      expose :repository_storages
650 651
      expose :koding_enabled
      expose :koding_url
652 653
      expose :plantuml_enabled
      expose :plantuml_url
654
      expose :terminal_max_session_time
655
      expose :polling_interval_multiplier
R
Robin Bobbitt 已提交
656 657 658
      expose :help_page_hide_commercial_content
      expose :help_page_text
      expose :help_page_support_url
659
    end
D
Dmitriy Zaporozhets 已提交
660 661

    class Release < Grape::Entity
662 663
      expose :tag, as: :tag_name
      expose :description
D
Dmitriy Zaporozhets 已提交
664
    end
665 666

    class RepoTag < Grape::Entity
667
      expose :name, :message
668

669
      expose :commit do |repo_tag, options|
670
        options[:project].repository.commit(repo_tag.dereferenced_target)
671 672
      end

673 674
      expose :release, using: Entities::Release do |repo_tag, options|
        options[:project].releases.find_by(tag: repo_tag.name)
675 676
      end
    end
K
Kamil Trzcinski 已提交
677

T
Tomasz Maczukin 已提交
678
    class Runner < Grape::Entity
T
Tomasz Maczukin 已提交
679 680 681 682 683 684 685
      expose :id
      expose :description
      expose :active
      expose :is_shared
      expose :name
    end

686 687
    class RunnerDetails < Runner
      expose :tag_list
688
      expose :run_untagged
689
      expose :locked
690
      expose :version, :revision, :platform, :architecture
691
      expose :contacted_at
B
blackst0ne 已提交
692
      expose :token, if: lambda { |runner, options| options[:current_user].admin? || !runner.is_shared? }
693
      expose :projects, with: Entities::BasicProjectDetails do |runner, options|
B
blackst0ne 已提交
694
        if options[:current_user].admin?
695 696
          runner.projects
        else
697
          options[:current_user].authorized_projects.where(id: runner.projects)
698 699
        end
      end
700 701
    end

702 703 704 705
    class RunnerRegistrationDetails < Grape::Entity
      expose :id, :token
    end

706
    class JobArtifactFile < Grape::Entity
707 708 709
      expose :filename, :size
    end

710 711 712 713
    class PipelineBasic < Grape::Entity
      expose :id, :sha, :ref, :status
    end

714
    class Job < Grape::Entity
T
Tomasz Maczukin 已提交
715
      expose :id, :status, :stage, :name, :ref, :tag, :coverage
T
Tomasz Maczukin 已提交
716
      expose :created_at, :started_at, :finished_at
T
Tomasz Maczukin 已提交
717
      expose :user, with: User
Z
Z.J. van de Weg 已提交
718
      expose :artifacts_file, using: JobArtifactFile, if: -> (job, opts) { job.artifacts? }
719
      expose :commit, with: RepoCommit
T
Tomasz Maczukin 已提交
720
      expose :runner, with: Runner
721
      expose :pipeline, with: PipelineBasic
722
    end
723

T
Tomasz Maczukin 已提交
724
    class Trigger < Grape::Entity
725
      expose :id
726 727 728
      expose :token, :description
      expose :created_at, :updated_at, :deleted_at, :last_used
      expose :owner, using: Entities::UserBasic
T
Tomasz Maczukin 已提交
729
    end
730

731
    class Variable < Grape::Entity
T
Tomasz Maczukin 已提交
732
      expose :key, :value
733
      expose :protected?, as: :protected
734
    end
735

736 737
    class Pipeline < PipelineBasic
      expose :before_sha, :tag, :yaml_errors
Z
Z.J. van de Weg 已提交
738 739 740 741

      expose :user, with: Entities::UserBasic
      expose :created_at, :updated_at, :started_at, :finished_at, :committed_at
      expose :duration
742
      expose :coverage
Z
Z.J. van de Weg 已提交
743 744
    end

745 746 747
    class PipelineSchedule < Grape::Entity
      expose :id
      expose :description, :ref, :cron, :cron_timezone, :next_run_at, :active
748
      expose :created_at, :updated_at
749 750 751
      expose :owner, using: Entities::UserBasic
    end

S
Shinya Maeda 已提交
752 753 754 755
    class PipelineScheduleDetails < PipelineSchedule
      expose :last_pipeline, using: Entities::PipelineBasic
    end

756
    class EnvironmentBasic < Grape::Entity
N
Nick Thomas 已提交
757
      expose :id, :name, :slug, :external_url
758 759
    end

760
    class Environment < EnvironmentBasic
761
      expose :project, using: Entities::BasicProjectDetails
Z
Z.J. van de Weg 已提交
762 763 764 765
    end

    class Deployment < Grape::Entity
      expose :id, :iid, :ref, :sha, :created_at
766 767
      expose :user,        using: Entities::UserBasic
      expose :environment, using: Entities::EnvironmentBasic
768
      expose :deployable,  using: Entities::Job
769 770
    end

771
    class RepoLicense < Grape::Entity
772 773
      expose :key, :name, :nickname
      expose :featured, as: :popular
774 775 776
      expose :url, as: :html_url
      expose(:source_url) { |license| license.meta['source'] }
      expose(:description) { |license| license.meta['description'] }
777 778 779
      expose(:conditions) { |license| license.meta['conditions'] }
      expose(:permissions) { |license| license.meta['permissions'] }
      expose(:limitations) { |license| license.meta['limitations'] }
780 781
      expose :content
    end
782

Z
ZJ van de Weg 已提交
783
    class TemplatesList < Grape::Entity
784 785 786
      expose :name
    end

Z
ZJ van de Weg 已提交
787
    class Template < Grape::Entity
788 789
      expose :name, :content
    end
790 791 792 793 794

    class BroadcastMessage < Grape::Entity
      expose :id, :message, :starts_at, :ends_at, :color, :font
      expose :active?, as: :active
    end
T
Tomasz Maczukin 已提交
795

796
    class PersonalAccessToken < Grape::Entity
797 798 799 800 801 802 803
      expose :id, :name, :revoked, :created_at, :scopes
      expose :active?, as: :active
      expose :expires_at do |personal_access_token|
        personal_access_token.expires_at ? personal_access_token.expires_at.strftime("%Y-%m-%d") : nil
      end
    end

804
    class PersonalAccessTokenWithToken < PersonalAccessToken
805 806
      expose :token
    end
807 808 809 810

    class ImpersonationToken < PersonalAccessTokenWithToken
      expose :impersonation
    end
811

812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
    class FeatureGate < Grape::Entity
      expose :key
      expose :value
    end

    class Feature < Grape::Entity
      expose :name
      expose :state
      expose :gates, using: FeatureGate do |model|
        model.gates.map do |gate|
          value = model.gate_values[gate.key]

          # By default all gate values are populated. Only show relevant ones.
          if (value.is_a?(Integer) && value.zero?) || (value.is_a?(Set) && value.empty?)
            next
          end

          { key: gate.key, value: value }
        end.compact
      end
    end

834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849
    module JobRequest
      class JobInfo < Grape::Entity
        expose :name, :stage
        expose :project_id, :project_name
      end

      class GitInfo < Grape::Entity
        expose :repo_url, :ref, :sha, :before_sha
        expose :ref_type do |model|
          if model.tag
            'tag'
          else
            'branch'
          end
        end
      end
T
Tomasz Maczukin 已提交
850

851 852 853
      class RunnerInfo < Grape::Entity
        expose :timeout
      end
T
Tomasz Maczukin 已提交
854

855
      class Step < Grape::Entity
T
Tomasz Maczukin 已提交
856
        expose :name, :script, :timeout, :when, :allow_failure
857
      end
T
Tomasz Maczukin 已提交
858

859
      class Image < Grape::Entity
860 861 862
        expose :name, :entrypoint
      end

863
      class Service < Image
864
        expose :alias, :command
865
      end
T
Tomasz Maczukin 已提交
866

867 868
      class Artifacts < Grape::Entity
        expose :name, :untracked, :paths, :when, :expire_in
T
Tomasz Maczukin 已提交
869 870
      end

871
      class Cache < Grape::Entity
872
        expose :key, :untracked, :paths, :policy
T
Tomasz Maczukin 已提交
873 874
      end

875 876 877
      class Credentials < Grape::Entity
        expose :type, :url, :username, :password
      end
T
Tomasz Maczukin 已提交
878

879 880 881 882 883
      class ArtifactFile < Grape::Entity
        expose :filename, :size
      end

      class Dependency < Grape::Entity
T
Tomasz Maczukin 已提交
884
        expose :id, :name, :token
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907
        expose :artifacts_file, using: ArtifactFile, if: ->(job, _) { job.artifacts? }
      end

      class Response < Grape::Entity
        expose :id
        expose :token
        expose :allow_git_fetch

        expose :job_info, using: JobInfo do |model|
          model
        end

        expose :git_info, using: GitInfo do |model|
          model
        end

        expose :runner_info, using: RunnerInfo do |model|
          model
        end

        expose :variables
        expose :steps, using: Step
        expose :image, using: Image
908
        expose :services, using: Service
909 910 911
        expose :artifacts, using: Artifacts
        expose :cache, using: Cache
        expose :credentials, using: Credentials
T
Tomasz Maczukin 已提交
912
        expose :dependencies, using: Dependency
913
      end
T
Tomasz Maczukin 已提交
914
    end
915 916 917 918

    class UserAgentDetail < Grape::Entity
      expose :user_agent
      expose :ip_address
J
James Lopez 已提交
919
      expose :submitted, as: :akismet_submitted
920
    end
N
Nihad Abbasov 已提交
921 922
  end
end