gitlab-org--gitlab-foss/lib/api/entities.rb

199 lines
5.6 KiB
Ruby
Raw Normal View History

module API
2012-06-27 07:32:56 -04:00
module Entities
class User < Grape::Entity
2014-01-18 14:07:00 -05:00
expose :id, :username, :email, :name, :bio, :skype, :linkedin, :twitter, :website_url,
:theme_id, :color_scheme_id, :state, :created_at, :extern_uid, :provider
expose :is_admin?, as: :is_admin
expose :can_create_group?, as: :can_create_group
expose :can_create_project?, as: :can_create_project
expose :avatar_url do |user, options|
if user.avatar.present?
user.avatar.url
end
end
2012-06-27 07:32:56 -04:00
end
2012-06-27 08:51:39 -04:00
class UserSafe < Grape::Entity
expose :name, :username
end
class UserBasic < Grape::Entity
expose :id, :username, :email, :name, :state, :created_at
end
2013-03-18 17:06:24 -04:00
class UserLogin < User
expose :private_token
end
2012-09-08 13:51:12 -04:00
class Hook < Grape::Entity
expose :id, :url, :created_at
2012-09-08 13:51:12 -04:00
end
class ProjectHook < Hook
expose :project_id, :push_events, :issues_events, :merge_requests_events
end
class ForkedFromProject < Grape::Entity
expose :id
expose :name, :name_with_namespace
expose :path, :path_with_namespace
end
2012-06-27 08:51:39 -04:00
class Project < Grape::Entity
expose :id, :description, :default_branch
expose :public?, as: :public
expose :archived?, as: :archived
expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url
expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group }
expose :name, :name_with_namespace
expose :path, :path_with_namespace
expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at
expose :namespace
expose :forked_from_project, using: Entities::ForkedFromProject, :if => lambda{ | project, options | project.forked? }
2012-06-27 08:51:39 -04:00
end
2012-09-21 06:23:17 -04:00
class ProjectMember < UserBasic
expose :project_access, as: :access_level do |user, options|
2014-01-19 13:55:59 -05:00
options[:project].users_projects.find_by(user_id: user.id).project_access
2012-09-21 06:23:17 -04:00
end
2012-09-06 16:49:29 -04:00
end
class Group < Grape::Entity
expose :id, :name, :path, :owner_id
end
2013-02-18 04:10:58 -05:00
class GroupDetail < Group
expose :projects, using: Entities::Project
end
class GroupMember < UserBasic
expose :group_access, as: :access_level do |user, options|
2014-01-19 13:55:59 -05:00
options[:group].users_groups.find_by(user_id: user.id).group_access
end
end
2012-07-06 09:08:17 -04:00
class RepoObject < Grape::Entity
expose :name
expose :commit do |repo_obj, options|
if repo_obj.respond_to?(:commit)
repo_obj.commit
elsif options[:project]
options[:project].repository.commit(repo_obj.target)
end
end
expose :protected do |repo, options|
if options[:project]
options[:project].protected_branch? repo.name
end
end
2012-06-27 08:51:39 -04:00
end
2012-06-29 09:34:08 -04:00
class RepoTreeObject < Grape::Entity
expose :id, :name, :type
expose :mode do |obj, options|
filemode = obj.mode.to_s(8)
filemode = "0" + filemode if filemode.length < 6
filemode
end
end
class RepoCommit < Grape::Entity
expose :id, :short_id, :title, :author_name, :author_email, :created_at
end
class RepoCommitDetail < RepoCommit
expose :parent_ids, :committed_date, :authored_date
end
2012-06-29 09:34:08 -04:00
class ProjectSnippet < Grape::Entity
expose :id, :title, :file_name
expose :author, using: Entities::UserBasic
2012-06-29 09:34:08 -04:00
expose :expires_at, :updated_at, :created_at
end
2012-07-24 08:19:51 -04:00
class ProjectEntity < Grape::Entity
expose :id, :iid
expose (:project_id) { |entity| entity.project.id }
expose :title, :description
expose :state, :created_at, :updated_at
end
class Milestone < ProjectEntity
expose :due_date
2012-07-24 08:19:51 -04:00
end
class Issue < ProjectEntity
expose :label_list, as: :labels
expose :milestone, using: Entities::Milestone
expose :assignee, :author, using: Entities::UserBasic
2012-07-24 08:19:51 -04:00
end
2012-09-16 10:52:06 -04:00
class MergeRequest < ProjectEntity
expose :target_branch, :source_branch, :upvotes, :downvotes
expose :author, :assignee, using: Entities::UserBasic
expose :source_project_id, :target_project_id
2014-04-14 21:12:07 -04:00
expose :label_list, as: :labels
2012-09-16 10:52:06 -04:00
end
2012-10-21 07:00:27 -04:00
class SSHKey < Grape::Entity
expose :id, :title, :key, :created_at
2012-10-21 07:00:27 -04:00
end
2012-10-21 12:48:56 -04:00
class Note < Grape::Entity
expose :id
expose :note, as: :body
2013-03-19 07:28:29 -04:00
expose :attachment_identifier, as: :attachment
2012-10-21 12:48:56 -04:00
expose :author, using: Entities::UserBasic
expose :created_at
2012-10-21 12:48:56 -04:00
end
class MRNote < Grape::Entity
expose :note
expose :author, using: Entities::UserBasic
end
2013-06-06 12:19:17 -04:00
class Event < Grape::Entity
expose :title, :project_id, :action_name
expose :target_id, :target_type, :author_id
expose :data, :target_title
expose :created_at
2013-06-06 12:19:17 -04:00
end
class Namespace < Grape::Entity
expose :id, :path, :kind
end
class ProjectAccess < Grape::Entity
expose :project_access, as: :access_level
expose :notification_level
end
class GroupAccess < Grape::Entity
expose :group_access, as: :access_level
expose :notification_level
end
class ProjectWithAccess < Project
expose :permissions do
expose :project_access, using: Entities::ProjectAccess do |project, options|
project.users_projects.find_by(user_id: options[:user].id)
end
expose :group_access, using: Entities::GroupAccess do |project, options|
if project.group
project.group.users_groups.find_by(user_id: options[:user].id)
end
end
end
end
class Label < Grape::Entity
expose :name
end
2012-06-27 07:32:56 -04:00
end
end