entities.rb 4.28 KB
Newer Older
1
module API
Nihad Abbasov's avatar
Nihad Abbasov committed
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
Nihad Abbasov's avatar
Nihad Abbasov committed
6
    end
Nihad Abbasov's avatar
Nihad Abbasov committed
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

Alex Denisov's avatar
Alex Denisov committed
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

miks's avatar
miks committed
24
    class Hook < Grape::Entity
25
      expose :id, :url, :created_at
miks's avatar
miks committed
26 27
    end

28 29 30 31 32 33
    class ForkedFromProject < Grape::Entity
      expose :id
      expose :name, :name_with_namespace
      expose :path, :path_with_namespace
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
34
    class Project < Grape::Entity
35
      expose :id, :description, :default_branch, :public, :ssh_url_to_repo, :http_url_to_repo, :web_url
36
      expose :owner, using: Entities::UserBasic
37
      expose :name, :name_with_namespace
38
      expose :path, :path_with_namespace
39
      expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at, :public
40
      expose :namespace
41
      expose :forked_from_project, using: Entities::ForkedFromProject, :if => lambda{ | project, options | project.forked? }
Nihad Abbasov's avatar
Nihad Abbasov committed
42 43
    end

44
    class ProjectMember < UserBasic
45
      expose :project_access, as: :access_level do |user, options|
46 47
        options[:project].users_projects.find_by_user_id(user.id).project_access
      end
miks's avatar
miks committed
48 49
    end

50 51 52 53 54 55 56 57 58 59 60 61
    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

62
    class Group < Grape::Entity
63
      expose :id, :name, :path, :owner_id
64
    end
Andrew8xx8's avatar
Andrew8xx8 committed
65

66
    class GroupDetail < Group
67 68 69
      expose :projects, using: Entities::Project
    end

Izaak Alpert's avatar
Izaak Alpert committed
70 71 72 73 74 75
    class GroupMember < UserBasic
      expose :group_access, as: :access_level do |user, options|
        options[:group].users_groups.find_by_user_id(user.id).group_access
      end
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
76
    class RepoObject < Grape::Entity
Nihad Abbasov's avatar
Nihad Abbasov committed
77
      expose :name, :commit
78 79 80 81 82
      expose :protected do |repo, options|
        if options[:project]
          options[:project].protected_branch? repo.name
        end
      end
Nihad Abbasov's avatar
Nihad Abbasov committed
83
    end
Nihad Abbasov's avatar
Nihad Abbasov committed
84

85 86 87 88
    class RepoCommit < Grape::Entity
      expose :id, :short_id, :title, :author_name, :author_email, :created_at
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
89 90
    class ProjectSnippet < Grape::Entity
      expose :id, :title, :file_name
91
      expose :author, using: Entities::UserBasic
Nihad Abbasov's avatar
Nihad Abbasov committed
92 93
      expose :expires_at, :updated_at, :created_at
    end
Nihad Abbasov's avatar
Nihad Abbasov committed
94 95

    class Milestone < Grape::Entity
96 97
      expose :id
      expose (:project_id) {|milestone| milestone.project.id}
Andrew8xx8's avatar
Andrew8xx8 committed
98
      expose :title, :description, :due_date, :state, :updated_at, :created_at
Nihad Abbasov's avatar
Nihad Abbasov committed
99 100 101
    end

    class Issue < Grape::Entity
102 103 104
      expose :id
      expose (:project_id) {|issue| issue.project.id}
      expose :title, :description
105 106 107
      expose :label_list, as: :labels
      expose :milestone, using: Entities::Milestone
      expose :assignee, :author, using: Entities::UserBasic
Andrew8xx8's avatar
Andrew8xx8 committed
108
      expose :state, :updated_at, :created_at
Nihad Abbasov's avatar
Nihad Abbasov committed
109
    end
Alex Denisov's avatar
Alex Denisov committed
110

111
    class SSHKey < Grape::Entity
112
      expose :id, :title, :key, :created_at
Alex Denisov's avatar
Alex Denisov committed
113
    end
114 115

    class MergeRequest < Grape::Entity
116 117
      expose :id, :target_branch, :source_branch, :title, :state
      expose :target_project_id, as: :project_id
118 119
      expose :author, :assignee, using: Entities::UserBasic
    end
120 121

    class Note < Grape::Entity
122 123
      expose :id
      expose :note, as: :body
124
      expose :attachment_identifier, as: :attachment
125
      expose :author, using: Entities::UserBasic
126
      expose :created_at
127
    end
128 129 130 131 132

    class MRNote < Grape::Entity
      expose :note
      expose :author, using: Entities::UserBasic
    end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
133 134 135 136 137 138

    class Event < Grape::Entity
      expose :title, :project_id, :action_name
      expose :target_id, :target_type, :author_id
      expose :data, :target_title
    end
Nihad Abbasov's avatar
Nihad Abbasov committed
139 140
  end
end