Commit 33416a7e authored by Valery Sizov's avatar Valery Sizov

Show all available groups in approvers groups dropdown

parent e8b6300c
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
minimumInputLength: 0, minimumInputLength: 0,
query: function(query) { query: function(query) {
var group_result, project_result; var group_result, project_result;
group_result = Api.groups(query.term, skip_ldap, function(groups) { group_result = Api.groups(query.term, { skip_ldap: skip_ldap }, function(groups) {
return groups; return groups;
}); });
project_result = Api.projects(query.term, 'id', function(projects) { project_result = Api.projects(query.term, 'id', function(projects) {
......
...@@ -23,16 +23,14 @@ ...@@ -23,16 +23,14 @@
}); });
}, },
// Return groups list. Filtered by query // Return groups list. Filtered by query
// Only active groups retrieved groups: function(query, options, callback) {
groups: function(query, skip_ldap, skip_groups, callback) {
var url = Api.buildUrl(Api.groupsPath); var url = Api.buildUrl(Api.groupsPath);
return $.ajax({ return $.ajax({
url: url, url: url,
data: { data: $.extend({
search: query, search: query,
skip_groups: skip_groups,
per_page: 20 per_page: 20
}, }, options),
dataType: "json" dataType: "json"
}).done(function(groups) { }).done(function(groups) {
return callback(groups); return callback(groups);
......
...@@ -5,15 +5,17 @@ ...@@ -5,15 +5,17 @@
function GroupsSelect() { function GroupsSelect() {
$('.ajax-groups-select').each((function(_this) { $('.ajax-groups-select').each((function(_this) {
return function(i, select) { return function(i, select) {
var skip_ldap, skip_groups; var skip_ldap, all_available, skip_groups;
skip_ldap = $(select).hasClass('skip_ldap'); skip_ldap = $(select).hasClass('skip_ldap');
all_available = $(select).data('all-available');
skip_groups = $(select).data('skip-groups') || []; skip_groups = $(select).data('skip-groups') || [];
return $(select).select2({ return $(select).select2({
placeholder: "Search for a group", placeholder: "Search for a group",
multiple: $(select).hasClass('multiselect'), multiple: $(select).hasClass('multiselect'),
minimumInputLength: 0, minimumInputLength: 0,
query: function(query) { query: function(query) {
return Api.groups(query.term, skip_ldap, skip_groups, function(groups) { options = { all_available: all_available, skip_groups: skip_groups }
return Api.groups(query.term, options, function(groups) {
var data; var data;
data = { data = {
results: groups results: groups
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
data = groups.concat(projects); data = groups.concat(projects);
return finalCallback(data); return finalCallback(data);
}; };
return Api.groups(term, false, false, groupsCallback); return Api.groups(term, {}, groupsCallback);
}; };
} else { } else {
projectsCallback = finalCallback; projectsCallback = finalCallback;
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
data = groups.concat(projects); data = groups.concat(projects);
return finalCallback(data); return finalCallback(data);
}; };
return Api.groups(query.term, false, false, groupsCallback); return Api.groups(query.term, {}, groupsCallback);
}; };
} else { } else {
projectsCallback = finalCallback; projectsCallback = finalCallback;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
filterable: true, filterable: true,
fieldName: 'group_id', fieldName: 'group_id',
data: function(term, callback) { data: function(term, callback) {
return Api.groups(term, false, false, function(data) { return Api.groups(term, {}, function(data) {
data.unshift({ data.unshift({
name: 'Any' name: 'Any'
}); });
......
...@@ -60,9 +60,7 @@ module SelectsHelper ...@@ -60,9 +60,7 @@ module SelectsHelper
def select2_tag(id, opts = {}) def select2_tag(id, opts = {})
opts[:class] << ' multiselect' if opts[:multiple] opts[:class] << ' multiselect' if opts[:multiple]
value = opts[:selected] || '' value = opts[:selected] || ''
css_class = opts[:class] hidden_field_tag(id, value, opts)
hidden_field_tag(id, value, class: css_class, data: { skip_groups: opts[:skip_groups], url: autocomplete_groups_path })
end end
def admin_email_select_tag(id, opts = {}) def admin_email_select_tag(id, opts = {})
......
...@@ -63,8 +63,8 @@ ...@@ -63,8 +63,8 @@
Add an approver suggestion for each merge request Add an approver suggestion for each merge request
= f.label :approver_group_ids, class: 'label-light' do = f.label :approver_group_ids, class: 'label-light' do
Approver groups Approver groups
- project_approver_group_paths = @project.approver_groups.includes(:group).map { |ag| ag.group.path } - skip_groups = @project.approver_groups.includes(:group).map { |ag| ag.group.id }
= groups_select_tag('project[approver_group_ids]', multiple: true, skip_groups: project_approver_group_paths, class: 'input-large') = groups_select_tag('project[approver_group_ids]', multiple: true, data: { skip_groups: skip_groups, all_available: true }, class: 'input-large')
.help-block .help-block
Add a group as an approver suggestion for each merge request Add a group as an approver suggestion for each merge request
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
This merge request must be approved by these users. This merge request must be approved by these users.
You can override the project settings by setting your own list of approvers. You can override the project settings by setting your own list of approvers.
- approver_group_ids = issuable.overall_approver_groups.includes(:group).map { |ag| ag.group.id } - skip_groups = issuable.overall_approver_groups.includes(:group).map { |ag| ag.group.id }
= groups_select_tag('merge_request[approver_group_ids]', multiple: true, skip_groups: approver_group_ids, class: 'input-large') = groups_select_tag('merge_request[approver_group_ids]', multiple: true, data: { skip_groups: skip_groups, all_available: true }, class: 'input-large')
.help-block .help-block
This merge request must be approved by members of these groups. This merge request must be approved by members of these groups.
You can override the project settings by setting your own list of approvers. You can override the project settings by setting your own list of approvers.
......
...@@ -2,7 +2,12 @@ ...@@ -2,7 +2,12 @@
## List groups ## List groups
Get a list of groups. (As user: my groups, as admin: all groups) Get a list of groups. (As user: my groups or all available, as admin: all groups).
Parameters:
- `all_available` (optional) - if passed, show all groups you have access to
- `skip_groups` (optional)(array of group paths) - if passed, skip groups
``` ```
GET /groups GET /groups
......
...@@ -8,11 +8,14 @@ module API ...@@ -8,11 +8,14 @@ module API
# #
# Parameters: # Parameters:
# skip_groups (optional) - Array of group ids to exclude from list # skip_groups (optional) - Array of group ids to exclude from list
# all_available (optional, boolean) - Show all group that you have access to
# Example Request: # Example Request:
# GET /groups # GET /groups
get do get do
@groups = if current_user.admin @groups = if current_user.admin
Group.all Group.all
elsif params[:all_available]
GroupsFinder.new.execute(current_user)
else else
current_user.groups current_user.groups
end end
......
...@@ -65,6 +65,17 @@ describe API::API, api: true do ...@@ -65,6 +65,17 @@ describe API::API, api: true do
expect(json_response.length).to eq(1) expect(json_response.length).to eq(1)
end end
end end
context "when using all_available in request" do
it "returns all groups you have access to" do
public_group = create :group, :public
get api("/groups", user1), all_available: true
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.first['name']).to eq(public_group.name)
end
end
end end
describe "GET /groups/:id" do describe "GET /groups/:id" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment