summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-07-28 15:49:44 +0200
committerDouwe Maan <douwe@gitlab.com>2015-07-28 15:49:44 +0200
commita784b996b3071cfe1807b1108316143dbc64492f (patch)
treee7f538d5837c8e2eac4c1b342ad3e154e594406a
parent43d118803133558209973464b1c16fd4c7ba446c (diff)
downloadgitlab-ce-a784b996b3071cfe1807b1108316143dbc64492f.tar.gz
Add project star and fork count, group avatar URL and user/group web URL attributes to API
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/group.rb11
-rw-r--r--app/models/user.rb4
-rw-r--r--lib/api/entities.rb4
4 files changed, 19 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index cf0fa36bd47..eef3c3e7c01 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -16,6 +16,7 @@ v 7.14.0 (unreleased)
- Expire Rails cache entries after two weeks to prevent endless Redis growth
- Add support for destroying project milestones (Stan Hu)
- Add fetch command to the MR page
+ - Add project star and fork count, group avatar URL and user/group web URL attributes to API
v 7.13.1
- Fix: Label modifications are not reflected in existing notes and in the issue list
diff --git a/app/models/group.rb b/app/models/group.rb
index 051c672cb33..adcbbec465e 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -17,6 +17,7 @@ require 'carrierwave/orm/activerecord'
require 'file_size_validator'
class Group < Namespace
+ include Gitlab::ConfigHelper
include Referable
has_many :group_members, dependent: :destroy, as: :source, class_name: 'GroupMember'
@@ -56,6 +57,16 @@ class Group < Namespace
name
end
+ def avatar_url(size = nil)
+ if avatar.present?
+ [gitlab_config.url, avatar.url].join
+ end
+ end
+
+ def web_url
+ [gitlab_config.url, "groups", self.path].join('/')
+ end
+
def owners
@owners ||= group_members.owners.map(&:user)
end
diff --git a/app/models/user.rb b/app/models/user.rb
index 4a10520b209..00a37cd9135 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -637,6 +637,10 @@ class User < ActiveRecord::Base
end
end
+ def web_url
+ [gitlab_config.url, "u", self.username].join('/')
+ end
+
def all_emails
[self.email, *self.emails.map(&:email)]
end
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index ecf1412dee5..c1b0cece344 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -5,7 +5,7 @@ module API
end
class UserBasic < UserSafe
- expose :id, :state, :avatar_url
+ expose :id, :state, :avatar_url, :web_url
end
class User < UserBasic
@@ -59,6 +59,7 @@ module API
expose :namespace
expose :forked_from_project, using: Entities::ForkedFromProject, if: lambda{ | project, options | project.forked? }
expose :avatar_url
+ expose :star_count, :forks_count
end
class ProjectMember < UserBasic
@@ -69,6 +70,7 @@ module API
class Group < Grape::Entity
expose :id, :name, :path, :description
+ expose :avatar_url, :web_url
end
class GroupDetail < Group