Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c9d9818b
Commit
c9d9818b
authored
Apr 19, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
6108ae3a
6376f784
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
76 additions
and
4 deletions
+76
-4
app/models/namespace.rb
app/models/namespace.rb
+5
-0
doc/api/projects.md
doc/api/projects.md
+6
-1
lib/api/entities.rb
lib/api/entities.rb
+9
-1
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+22
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+34
-2
No files found.
app/models/namespace.rb
View file @
c9d9818b
...
...
@@ -51,6 +51,7 @@ class Namespace < ApplicationRecord
validate
:nesting_level_allowed
delegate
:name
,
to: :owner
,
allow_nil:
true
,
prefix:
true
delegate
:avatar_url
,
to: :owner
,
allow_nil:
true
after_commit
:refresh_access_of_projects_invited_groups
,
on: :update
,
if:
->
{
previous_changes
.
key?
(
'share_with_group_lock'
)
}
...
...
@@ -149,6 +150,10 @@ class Namespace < ApplicationRecord
type
==
'Group'
?
'group'
:
'user'
end
def
user?
kind
==
'user'
end
def
find_fork_of
(
project
)
return
unless
project
.
fork_network
...
...
doc/api/projects.md
View file @
c9d9818b
...
...
@@ -496,7 +496,9 @@ GET /projects/:id
"name"
:
"Diaspora"
,
"path"
:
"diaspora"
,
"kind"
:
"group"
,
"full_path"
:
"diaspora"
"full_path"
:
"diaspora"
,
"avatar_url"
:
"http://localhost:3000/uploads/group/avatar/3/foo.jpg"
,
"web_url"
:
"http://localhost:3000/groups/diaspora"
},
"import_status"
:
"none"
,
"import_error"
:
null
,
...
...
@@ -565,6 +567,8 @@ GET /projects/:id
}
```
**Note**
: The
`web_url`
and
`avatar_url`
attributes on
`namespace`
were
[
introduced
][
ce-27427
]
in GitLab 11.11.
If the project is a fork, and you provide a valid token to authenticate, the
`forked_from_project`
field will appear in the response.
...
...
@@ -1724,3 +1728,4 @@ GET /projects/:id/snapshot
[
eep
]:
https://about.gitlab.com/pricing/
"Available only in GitLab Premium"
[
ee-6137
]:
https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/6137
[
ce-27427
]:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/27427
lib/api/entities.rb
View file @
c9d9818b
...
...
@@ -922,7 +922,15 @@ module API
end
class
NamespaceBasic
<
Grape
::
Entity
expose
:id
,
:name
,
:path
,
:kind
,
:full_path
,
:parent_id
expose
:id
,
:name
,
:path
,
:kind
,
:full_path
,
:parent_id
,
:avatar_url
expose
:web_url
do
|
namespace
|
if
namespace
.
user?
Gitlab
::
Routing
.
url_helpers
.
user_url
(
namespace
.
owner
)
else
namespace
.
web_url
end
end
end
class
Namespace
<
NamespaceBasic
...
...
spec/models/namespace_spec.rb
View file @
c9d9818b
...
...
@@ -63,6 +63,11 @@ describe Namespace do
end
end
describe
'delegate'
do
it
{
is_expected
.
to
delegate_method
(
:name
).
to
(
:owner
).
with_prefix
.
with_arguments
(
allow_nil:
true
)
}
it
{
is_expected
.
to
delegate_method
(
:avatar_url
).
to
(
:owner
).
with_arguments
(
allow_nil:
true
)
}
end
describe
"Respond to"
do
it
{
is_expected
.
to
respond_to
(
:human_name
)
}
it
{
is_expected
.
to
respond_to
(
:to_param
)
}
...
...
@@ -801,4 +806,21 @@ describe Namespace do
end
end
end
describe
'#user?'
do
subject
{
namespace
.
user?
}
context
'when type is a user'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:namespace
)
{
user
.
namespace
}
it
{
is_expected
.
to
be_truthy
}
end
context
'when type is a group'
do
let
(
:namespace
)
{
create
(
:group
)
}
it
{
is_expected
.
to
be_falsy
}
end
end
end
spec/requests/api/projects_spec.rb
View file @
c9d9818b
...
...
@@ -1096,7 +1096,6 @@ describe API::Projects do
expect
(
json_response
[
'http_url_to_repo'
]).
to
be_present
expect
(
json_response
[
'web_url'
]).
to
be_present
expect
(
json_response
[
'owner'
]).
to
be_a
Hash
expect
(
json_response
[
'owner'
]).
to
be_a
Hash
expect
(
json_response
[
'name'
]).
to
eq
(
project
.
name
)
expect
(
json_response
[
'path'
]).
to
be_present
expect
(
json_response
[
'issues_enabled'
]).
to
be_present
...
...
@@ -1185,7 +1184,9 @@ describe API::Projects do
'path'
=>
user
.
namespace
.
path
,
'kind'
=>
user
.
namespace
.
kind
,
'full_path'
=>
user
.
namespace
.
full_path
,
'parent_id'
=>
nil
'parent_id'
=>
nil
,
'avatar_url'
=>
user
.
avatar_url
,
'web_url'
=>
Gitlab
::
Routing
.
url_helpers
.
user_url
(
user
)
})
end
...
...
@@ -1387,6 +1388,37 @@ describe API::Projects do
end
end
end
context
'when project belongs to a group namespace'
do
let
(
:group
)
{
create
(
:group
,
:with_avatar
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
let!
(
:project_member
)
{
create
(
:project_member
,
:developer
,
user:
user
,
project:
project
)
}
it
'returns group web_url and avatar_url'
do
get
api
(
"/projects/
#{
project
.
id
}
"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
group_data
=
json_response
[
'namespace'
]
expect
(
group_data
[
'web_url'
]).
to
eq
(
group
.
web_url
)
expect
(
group_data
[
'avatar_url'
]).
to
eq
(
group
.
avatar_url
)
end
end
context
'when project belongs to a user namespace'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
it
'returns user web_url and avatar_url'
do
get
api
(
"/projects/
#{
project
.
id
}
"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
user_data
=
json_response
[
'namespace'
]
expect
(
user_data
[
'web_url'
]).
to
eq
(
"http://localhost/
#{
user
.
username
}
"
)
expect
(
user_data
[
'avatar_url'
]).
to
eq
(
user
.
avatar_url
)
end
end
end
context
'with external authorization'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment