summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsue445 <sue445@sue445.net>2015-03-01 02:07:53 +0900
committersue445 <sue445@sue445.net>2015-03-01 10:13:01 +0900
commit51abeaa1bc93862a4d15506a590704f9fc56cfd6 (patch)
tree745adc2f9567b8cf22c9b2cbe6f399039abb019e
parent7fef8456e8bc92adb0de3f2bc7192e3bedfce47d (diff)
downloadgitlab-ce-51abeaa1bc93862a4d15506a590704f9fc56cfd6.tar.gz
Expose avatar_url in projects API
* Impl Project#avatar_url * Refactor ApplicationHelper: Use Project#avatar_url * Update changelog
-rw-r--r--CHANGELOG1
-rw-r--r--app/helpers/application_helper.rb6
-rw-r--r--app/models/project.rb10
-rw-r--r--doc/api/projects.md9
-rw-r--r--lib/api/entities.rb1
-rw-r--r--spec/helpers/application_helper_spec.rb6
-rw-r--r--spec/models/project_spec.rb31
7 files changed, 55 insertions, 9 deletions
diff --git a/CHANGELOG b/CHANGELOG
index d5b05125110..f534f50b7aa 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -10,6 +10,7 @@ v 7.9.0 (unreleased)
- Save web edit in new branch
- Fix ordering of imported but unchanged projects (Marco Wessel)
- Mobile UI improvements: make aside content expandable
+ - Expose avatar_url in projects API
- Generalize image upload in drag and drop in markdown to all files (Hannes Rosenögger)
v 7.8.1
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 365de3595cd..a81e41819b7 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -58,10 +58,8 @@ module ApplicationHelper
Project.find_with_namespace(project_id)
end
- if project.avatar.present?
- image_tag project.avatar.url, options
- elsif project.avatar_in_git
- image_tag namespace_project_avatar_path(project.namespace, project), options
+ if project.avatar_url
+ image_tag project.avatar_url, options
else # generated icon
project_identicon(project, options)
end
diff --git a/app/models/project.rb b/app/models/project.rb
index d33b25db201..7f2e0b4c17b 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -37,6 +37,8 @@ class Project < ActiveRecord::Base
include Gitlab::ShellAdapter
include Gitlab::VisibilityLevel
include Gitlab::ConfigHelper
+ include Rails.application.routes.url_helpers
+
extend Gitlab::ConfigHelper
extend Enumerize
@@ -408,6 +410,14 @@ class Project < ActiveRecord::Base
@avatar_file
end
+ def avatar_url
+ if avatar.present?
+ [gitlab_config.url, avatar.url].join
+ elsif avatar_in_git
+ [gitlab_config.url, namespace_project_avatar_path(namespace, self)].join
+ end
+ end
+
# For compatibility with old code
def code
path
diff --git a/doc/api/projects.md b/doc/api/projects.md
index a1a23051d7e..7fe244477db 100644
--- a/doc/api/projects.md
+++ b/doc/api/projects.md
@@ -68,7 +68,8 @@ Parameters:
"path": "diaspora",
"updated_at": "2013-09-30T13: 46: 02Z"
},
- "archived": false
+ "archived": false,
+ "avatar_url": "http://example.com/uploads/project/avatar/4/uploads/avatar.png"
},
{
"id": 6,
@@ -103,7 +104,8 @@ Parameters:
"path": "brightbox",
"updated_at": "2013-09-30T13:46:02Z"
},
- "archived": false
+ "archived": false,
+ "avatar_url": null
}
]
```
@@ -195,7 +197,8 @@ Parameters:
"notification_level": 3
}
},
- "archived": false
+ "archived": false,
+ "avatar_url": "http://example.com/uploads/project/avatar/3/uploads/avatar.png"
}
```
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 7572104fc16..af76f3c439e 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -56,6 +56,7 @@ module API
expose :issues_enabled, :merge_requests_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? }
+ expose :avatar_url
end
class ProjectMember < UserBasic
diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb
index 9d99b6e33cb..de491ce8a58 100644
--- a/spec/helpers/application_helper_spec.rb
+++ b/spec/helpers/application_helper_spec.rb
@@ -64,8 +64,9 @@ describe ApplicationHelper do
project = create(:project)
project.avatar = File.open(avatar_file_path)
project.save!
+ avatar_url = "http://localhost/uploads/project/avatar/#{ project.id }/gitlab_logo.png"
expect(project_icon("#{project.namespace.to_param}/#{project.to_param}").to_s).to eq(
- "<img alt=\"Gitlab logo\" src=\"/uploads/project/avatar/#{ project.id }/gitlab_logo.png\" />"
+ "<img alt=\"Gitlab logo\" src=\"#{avatar_url}\" />"
)
end
@@ -75,8 +76,9 @@ describe ApplicationHelper do
allow_any_instance_of(Project).to receive(:avatar_in_git).and_return(true)
+ avatar_url = 'http://localhost' + namespace_project_avatar_path(project.namespace, project)
expect(project_icon("#{project.namespace.to_param}/#{project.to_param}").to_s).to match(
- image_tag(namespace_project_avatar_path(project.namespace, project)))
+ image_tag(avatar_url))
end
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index a9df6f137b7..879a63dd9f9 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -326,4 +326,35 @@ describe Project do
expect(project.avatar_type).to eq(['only images allowed'])
end
end
+
+ describe :avatar_url do
+ subject { project.avatar_url }
+
+ let(:project) { create(:project) }
+
+ context 'When avatar file is uploaded' do
+ before do
+ project.update_columns(avatar: 'uploads/avatar.png')
+ allow(project.avatar).to receive(:present?) { true }
+ end
+
+ let(:avatar_path) do
+ "/uploads/project/avatar/#{project.id}/uploads/avatar.png"
+ end
+
+ it { should eq "http://localhost#{avatar_path}" }
+ end
+
+ context 'When avatar file in git' do
+ before do
+ allow(project).to receive(:avatar_in_git) { true }
+ end
+
+ let(:avatar_path) do
+ "/#{project.namespace.name}/#{project.path}/avatar"
+ end
+
+ it { should eq "http://localhost#{avatar_path}" }
+ end
+ end
end