entities.rb 3.7 KB
Newer Older
1
module API
N
Nihad Abbasov 已提交
2 3
  module Entities
    class User < Grape::Entity
4
      expose :id, :username, :email, :name, :bio, :skype, :linkedin, :twitter,
5
             :theme_id, :color_scheme_id, :state, :created_at, :extern_uid, :provider
N
Nihad Abbasov 已提交
6
    end
N
Nihad Abbasov 已提交
7

8 9 10 11
    class UserSafe < Grape::Entity
      expose :name
    end

12
    class UserBasic < Grape::Entity
13
      expose :id, :username, :email, :name, :state, :created_at
14 15
    end

A
Alex Denisov 已提交
16
    class UserLogin < User
17
      expose :private_token
18 19 20 21
      expose :is_admin?, as: :is_admin
      expose :can_create_group?, as: :can_create_group
      expose :can_create_project?, as: :can_create_project
      expose :can_create_team?, as: :can_create_team
22 23
    end

M
miks 已提交
24
    class Hook < Grape::Entity
25
      expose :id, :url, :created_at
M
miks 已提交
26 27
    end

N
Nihad Abbasov 已提交
28
    class Project < Grape::Entity
29
      expose :id, :description, :default_branch, :public, :ssh_url_to_repo, :http_url_to_repo, :web_url
30
      expose :owner, using: Entities::UserBasic
31
      expose :name, :name_with_namespace
32
      expose :path, :path_with_namespace
N
Nihad Abbasov 已提交
33
      expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :created_at
34
      expose :namespace
N
Nihad Abbasov 已提交
35 36
    end

N
Nihad Abbasov 已提交
37
    class ProjectMember < UserBasic
38
      expose :project_access, as: :access_level do |user, options|
N
Nihad Abbasov 已提交
39 40
        options[:project].users_projects.find_by_user_id(user.id).project_access
      end
M
miks 已提交
41 42
    end

C
Christian Simon 已提交
43 44 45 46 47 48 49 50 51 52 53 54
    class TeamMember < UserBasic
      expose :permission, as: :access_level do |user, options|
        options[:user_team].user_team_user_relationships.find_by_user_id(user.id).permission
      end
    end

    class TeamProject < Project
      expose :greatest_access, as: :greatest_access_level do |project, options|
        options[:user_team].user_team_project_relationships.find_by_project_id(project.id).greatest_access
      end
    end

55
    class Group < Grape::Entity
56
      expose :id, :name, :path, :owner_id
57
    end
A
Andrew8xx8 已提交
58

59
    class GroupDetail < Group
60 61 62
      expose :projects, using: Entities::Project
    end

N
Nihad Abbasov 已提交
63
    class RepoObject < Grape::Entity
N
Nihad Abbasov 已提交
64
      expose :name, :commit
65 66 67 68 69
      expose :protected do |repo, options|
        if options[:project]
          options[:project].protected_branch? repo.name
        end
      end
N
Nihad Abbasov 已提交
70
    end
N
Nihad Abbasov 已提交
71

72 73 74 75
    class RepoCommit < Grape::Entity
      expose :id, :short_id, :title, :author_name, :author_email, :created_at
    end

N
Nihad Abbasov 已提交
76 77
    class ProjectSnippet < Grape::Entity
      expose :id, :title, :file_name
78
      expose :author, using: Entities::UserBasic
N
Nihad Abbasov 已提交
79 80
      expose :expires_at, :updated_at, :created_at
    end
N
Nihad Abbasov 已提交
81 82

    class Milestone < Grape::Entity
83 84
      expose :id
      expose (:project_id) {|milestone| milestone.project.id}
A
Andrew8xx8 已提交
85
      expose :title, :description, :due_date, :state, :updated_at, :created_at
N
Nihad Abbasov 已提交
86 87 88
    end

    class Issue < Grape::Entity
N
Nihad Abbasov 已提交
89 90 91
      expose :id
      expose (:project_id) {|issue| issue.project.id}
      expose :title, :description
92 93 94
      expose :label_list, as: :labels
      expose :milestone, using: Entities::Milestone
      expose :assignee, :author, using: Entities::UserBasic
A
Andrew8xx8 已提交
95
      expose :state, :updated_at, :created_at
N
Nihad Abbasov 已提交
96
    end
A
Alex Denisov 已提交
97

98
    class SSHKey < Grape::Entity
99
      expose :id, :title, :key, :created_at
A
Alex Denisov 已提交
100
    end
V
Valeriy Sizov 已提交
101

C
Christian Simon 已提交
102 103 104 105
    class UserTeam < Grape::Entity
      expose :id, :name, :path, :owner_id
    end

V
Valeriy Sizov 已提交
106
    class MergeRequest < Grape::Entity
A
Andrew8xx8 已提交
107
      expose :id, :target_branch, :source_branch, :project_id, :title, :state
V
Valeriy Sizov 已提交
108 109
      expose :author, :assignee, using: Entities::UserBasic
    end
110 111

    class Note < Grape::Entity
112 113
      expose :id
      expose :note, as: :body
114
      expose :attachment_identifier, as: :attachment
115
      expose :author, using: Entities::UserBasic
116
      expose :created_at
117
    end
118 119 120 121 122

    class MRNote < Grape::Entity
      expose :note
      expose :author, using: Entities::UserBasic
    end
N
Nihad Abbasov 已提交
123 124
  end
end