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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
35ced4da
Commit
35ced4da
authored
Sep 01, 2016
by
barthc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix group links 404
parent
4dc61dc7
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
77 additions
and
21 deletions
+77
-21
app/assets/javascripts/api.js
app/assets/javascripts/api.js
+2
-1
app/assets/javascripts/groups_select.js
app/assets/javascripts/groups_select.js
+3
-2
app/assets/javascripts/project_select.js
app/assets/javascripts/project_select.js
+2
-2
app/assets/javascripts/search.js
app/assets/javascripts/search.js
+1
-1
app/controllers/projects/group_links_controller.rb
app/controllers/projects/group_links_controller.rb
+16
-8
app/helpers/selects_helper.rb
app/helpers/selects_helper.rb
+2
-4
app/views/projects/group_links/index.html.haml
app/views/projects/group_links/index.html.haml
+2
-2
lib/api/groups.rb
lib/api/groups.rb
+3
-0
spec/controllers/projects/group_links_controller_spec.rb
spec/controllers/projects/group_links_controller_spec.rb
+36
-1
spec/requests/api/groups_spec.rb
spec/requests/api/groups_spec.rb
+10
-0
No files found.
app/assets/javascripts/api.js
View file @
35ced4da
...
...
@@ -23,12 +23,13 @@
},
// Return groups list. Filtered by query
// Only active groups retrieved
groups
:
function
(
query
,
skip_ldap
,
callback
)
{
groups
:
function
(
query
,
skip_ldap
,
skip_groups
,
callback
)
{
var
url
=
Api
.
buildUrl
(
Api
.
groupsPath
);
return
$
.
ajax
({
url
:
url
,
data
:
{
search
:
query
,
skip_groups
:
skip_groups
,
per_page
:
20
},
dataType
:
"
json
"
...
...
app/assets/javascripts/groups_select.js
View file @
35ced4da
...
...
@@ -5,14 +5,15 @@
function
GroupsSelect
()
{
$
(
'
.ajax-groups-select
'
).
each
((
function
(
_this
)
{
return
function
(
i
,
select
)
{
var
skip_ldap
;
var
skip_ldap
,
skip_groups
;
skip_ldap
=
$
(
select
).
hasClass
(
'
skip_ldap
'
);
skip_groups
=
$
(
select
).
data
(
'
skip-groups
'
)
||
[];
return
$
(
select
).
select2
({
placeholder
:
"
Search for a group
"
,
multiple
:
$
(
select
).
hasClass
(
'
multiselect
'
),
minimumInputLength
:
0
,
query
:
function
(
query
)
{
return
Api
.
groups
(
query
.
term
,
skip_ldap
,
function
(
groups
)
{
return
Api
.
groups
(
query
.
term
,
skip_ldap
,
skip_groups
,
function
(
groups
)
{
var
data
;
data
=
{
results
:
groups
...
...
app/assets/javascripts/project_select.js
View file @
35ced4da
...
...
@@ -23,7 +23,7 @@
data
=
groups
.
concat
(
projects
);
return
finalCallback
(
data
);
};
return
Api
.
groups
(
term
,
false
,
groupsCallback
);
return
Api
.
groups
(
term
,
false
,
false
,
groupsCallback
);
};
}
else
{
projectsCallback
=
finalCallback
;
...
...
@@ -72,7 +72,7 @@
data
=
groups
.
concat
(
projects
);
return
finalCallback
(
data
);
};
return
Api
.
groups
(
query
.
term
,
false
,
groupsCallback
);
return
Api
.
groups
(
query
.
term
,
false
,
false
,
groupsCallback
);
};
}
else
{
projectsCallback
=
finalCallback
;
...
...
app/assets/javascripts/search.js
View file @
35ced4da
...
...
@@ -10,7 +10,7 @@
filterable
:
true
,
fieldName
:
'
group_id
'
,
data
:
function
(
term
,
callback
)
{
return
Api
.
groups
(
term
,
null
,
function
(
data
)
{
return
Api
.
groups
(
term
,
false
,
false
,
function
(
data
)
{
data
.
unshift
({
name
:
'
Any
'
});
...
...
app/controllers/projects/group_links_controller.rb
View file @
35ced4da
...
...
@@ -4,10 +4,15 @@ class Projects::GroupLinksController < Projects::ApplicationController
def
index
@group_links
=
project
.
project_group_links
.
all
@skip_groups
=
@group_links
.
pluck
(
:group_id
)
@skip_groups
<<
project
.
group
.
try
(
:id
)
end
def
create
group
=
Group
.
find
(
params
[
:link_group_id
])
group
=
Group
.
find
(
params
[
:link_group_id
])
if
params
[
:link_group_id
].
present?
if
group
return
render_404
unless
can?
(
current_user
,
:read_group
,
group
)
project
.
project_group_links
.
create
(
...
...
@@ -15,6 +20,9 @@ class Projects::GroupLinksController < Projects::ApplicationController
group_access:
params
[
:link_group_access
],
expires_at:
params
[
:expires_at
]
)
else
flash
[
:alert
]
=
'Please select a group.'
end
redirect_to
namespace_project_group_links_path
(
project
.
namespace
,
project
)
end
...
...
app/helpers/selects_helper.rb
View file @
35ced4da
...
...
@@ -49,12 +49,10 @@ module SelectsHelper
end
def
select2_tag
(
id
,
opts
=
{})
css_class
=
''
css_class
<<
'multiselect '
if
opts
[
:multiple
]
css_class
<<
(
opts
[
:class
]
||
''
)
opts
[
:class
]
<<
' multiselect'
if
opts
[
:multiple
]
value
=
opts
[
:selected
]
||
''
hidden_field_tag
(
id
,
value
,
class:
css_clas
s
)
hidden_field_tag
(
id
,
value
,
opt
s
)
end
private
...
...
app/views/projects/group_links/index.html.haml
View file @
35ced4da
...
...
@@ -8,10 +8,10 @@
.col-lg-9
%h5
.prepend-top-0
Set a group to share
=
form_tag
namespace_project_group_links_path
(
@project
.
namespace
,
@project
),
method: :post
do
=
form_tag
namespace_project_group_links_path
(
@project
.
namespace
,
@project
),
class:
'js-requires-input'
,
method: :post
do
.form-group
=
label_tag
:link_group_id
,
"Group"
,
class:
"label-light"
=
groups_select_tag
(
:link_group_id
,
skip_group:
@project
.
group
.
try
(
:path
)
)
=
groups_select_tag
(
:link_group_id
,
data:
{
skip_groups:
@skip_groups
},
required:
true
)
.form-group
=
label_tag
:link_group_access
,
"Max access level"
,
class:
"label-light"
.select-wrapper
...
...
lib/api/groups.rb
View file @
35ced4da
...
...
@@ -6,6 +6,8 @@ module API
resource
:groups
do
# Get a groups list
#
# Parameters:
# skip_groups (optional) - Array of group ids to exclude from list
# Example Request:
# GET /groups
get
do
...
...
@@ -16,6 +18,7 @@ module API
end
@groups
=
@groups
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@groups
=
@groups
.
where
.
not
(
id:
params
[
:skip_groups
])
if
params
[
:skip_groups
].
present?
@groups
=
paginate
@groups
present
@groups
,
with:
Entities
::
Group
end
...
...
spec/controllers/projects/group_links_controller_spec.rb
View file @
35ced4da
require
'spec_helper'
describe
Projects
::
GroupLinksController
do
let
(
:project
)
{
create
(
:project
,
:private
)
}
let
(
:group
)
{
create
(
:group
,
:private
)
}
let
(
:group2
)
{
create
(
:group
,
:private
)
}
let
(
:project
)
{
create
(
:project
,
:private
,
group:
group2
)
}
let
(
:user
)
{
create
(
:user
)
}
before
do
...
...
@@ -46,5 +47,39 @@ describe Projects::GroupLinksController do
expect
(
group
.
shared_projects
).
not_to
include
project
end
end
context
'when project group id equal link group id'
do
before
do
post
(
:create
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
link_group_id:
group2
.
id
,
link_group_access:
ProjectGroupLink
.
default_access
)
end
it
'does not share project with selected group'
do
expect
(
group2
.
shared_projects
).
not_to
include
project
end
it
'redirects to project group links page'
do
expect
(
response
).
to
redirect_to
(
namespace_project_group_links_path
(
project
.
namespace
,
project
)
)
end
end
context
'when link group id is not present'
do
before
do
post
(
:create
,
namespace_id:
project
.
namespace
.
to_param
,
project_id:
project
.
to_param
,
link_group_access:
ProjectGroupLink
.
default_access
)
end
it
'redirects to project group links page'
do
expect
(
response
).
to
redirect_to
(
namespace_project_group_links_path
(
project
.
namespace
,
project
)
)
expect
(
flash
[
:alert
]).
to
eq
(
'Please select a group.'
)
end
end
end
end
spec/requests/api/groups_spec.rb
View file @
35ced4da
...
...
@@ -45,6 +45,16 @@ describe API::API, api: true do
expect
(
json_response
.
length
).
to
eq
(
2
)
end
end
context
"when using skip_groups in request"
do
it
"returns all groups excluding skipped groups"
do
get
api
(
"/groups"
,
admin
),
skip_groups:
[
group2
.
id
]
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
length
).
to
eq
(
1
)
end
end
end
describe
"GET /groups/:id"
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