Skip to content
Snippets Groups Projects
Commit fc63690d authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Merge branch 'admin_email_groups_and_projects_select' into 'master'

Admin email groups and projects select box

Fixes #219

See merge request !288
parents 30920cc4 562857d6
No related branches found
No related tags found
3 merge requests!8889WIP: Port of 25624-anticipate-obstacles-to-removing-turbolinks to EE.,!7795Asciidoctor plantuml,!7793Add support for PlantUML diagrams in Asciidoc.
class @AdminEmailSelect
constructor: ->
$('.ajax-admin-email-select').each (i, select) =>
skip_ldap = $(select).hasClass('skip_ldap')
$(select).select2
placeholder: "Select group or project"
multiple: $(select).hasClass('multiselect')
minimumInputLength: 0
query: (query) ->
group_result = Api.groups query.term, skip_ldap, (groups) ->
groups
project_result = Api.projects query.term, (projects) ->
projects
$.when(project_result, group_result).done (projects, groups) ->
all = {id: "all"}
data = $.merge([all], groups[0], projects[0])
query.callback({ results: data})
id: (object) ->
if object.path_with_namespace
"project-#{object.id}"
else if object.path
"group-#{object.id}"
else
"all"
formatResult: (args...) =>
@formatResult(args...)
formatSelection: (args...) =>
@formatSelection(args...)
dropdownCssClass: "ajax-admin-email-dropdown"
escapeMarkup: (m) -> # we do not want to escape markup since we are displaying html in results
m
formatResult: (object) ->
if object.path_with_namespace
"<div class='project-result'>
<div class='project-name'>#{object.name}</div>
<div class='project-path'>#{object.path_with_namespace}</div>
</div>"
else if object.path
"<div class='group-result'>
<div class='group-name'>#{object.name}</div>
<div class='group-path'>#{object.path}</div>
</div>"
else
"<div class='group-result'>
<div class='group-name'>All</div>
<div class='group-path'>All groups and projects</div>
</div>"
formatSelection: (object) ->
if object.path_with_namespace
"Project: #{object.name}"
else if object.path
"Group: #{object.name}"
else
"All groups and projects"
Loading
Loading
@@ -7,6 +7,7 @@
ldap_groups_path: "/api/:version/ldap/:provider/groups.json"
namespaces_path: "/api/:version/namespaces.json"
project_users_path: "/api/:version/projects/:id/users.json"
projects_path: "/api/:version/projects.json"
 
# Get 20 (depends on api) recent notes
# and sort the ascending from oldest to newest
Loading
Loading
@@ -132,3 +133,17 @@
dataType: "json"
).done (groups) ->
callback(groups)
# Return projects list. Filtered by query
projects: (query, callback) ->
project_url = Api.buildUrl(Api.projects_path)
project_query = $.ajax(
url: project_url
data:
private_token: gon.api_token
search: query
per_page: 20
dataType: "json"
).done (projects) ->
callback(projects)
Loading
Loading
@@ -81,6 +81,8 @@ class Dispatcher
new User()
when 'projects:group_links:index'
new GroupsSelect()
when 'admin:emails:show'
new AdminEmailSelect()
 
switch path.first()
when 'admin'
Loading
Loading
Loading
Loading
@@ -128,6 +128,15 @@ select {
}
}
 
.project-result {
.project-name {
font-weight: bold;
}
.project-path {
color: #999;
}
}
.user-result {
.user-image {
float: left;
Loading
Loading
module AdminEmailHelper
def admin_email_grouped_recipient_options
options_for_select([['All GitLab users', 'all']]) +
grouped_options_for_select(
'Groups' => Group.pluck(:name, :id).map{ |name, id| [name, "group-#{id}"] },
'Projects' => grouped_project_list
)
end
protected
def grouped_project_list
Group.includes(:projects).flat_map do |group|
group.human_name
group.projects.map do |project|
["#{group.human_name} / #{project.name}", "project-#{project.id}"]
end
end
end
end
\ No newline at end of file
Loading
Loading
@@ -35,4 +35,13 @@ module SelectsHelper
 
hidden_field_tag(id, value, class: css_class)
end
def admin_email_select_tag(id, opts = {})
css_class = "ajax-admin-email-select "
css_class << "multiselect " if opts[:multiple]
css_class << (opts[:class] || '')
value = opts[:selected] || ''
hidden_field_tag(id, value, class: css_class)
end
end
Loading
Loading
@@ -17,6 +17,6 @@
.form-group
%label.control-label{for: :recipients} Recipient group
.col-sm-10
= select_tag :recipients, admin_email_grouped_recipient_options, class: :select2, required: true
= admin_email_select_tag(:recipients)
.form-actions
= submit_tag 'Send message', class: 'btn btn-create'
Loading
Loading
@@ -8,6 +8,7 @@ class AdminEmailsWorker
end
 
private
def recipient_list(recipient_id)
case recipient_id
when 'all'
Loading
Loading
@@ -18,4 +19,4 @@ class AdminEmailsWorker
Project.find($1).team.users.subscribed_for_admin_email
end
end
end
\ No newline at end of file
end
@admin
Feature: Admin email
Background:
Given I sign in as an admin
And there are groups with projects
 
@javascript
Scenario: Create a new email notification
Given I visit admin email page
When I submit form with email notification info
Loading
Loading
Loading
Loading
@@ -15,7 +15,16 @@ class Spinach::Features::AdminEmail < Spinach::FeatureSteps
within('form#new-admin-email') do
fill_in :subject, with: 'my subject'
fill_in :body, with: @email_text
select @selected_group.name, from: :recipients
# Note: Unable to use select2 helper because
# the helper uses select2 method "val" to select the group from the dropdown
# and the method "val" requires "initSelection" to be used in the select2 call
select2_container = first("#s2id_recipients")
select2_container.find(".select2-choice").click
find(:xpath, "//body").find("input.select2-input").set(@selected_group.name)
page.execute_script(%|$("input.select2-input:visible").keyup();|)
find(:xpath, "//body").find(".group-name", text: @selected_group.name).click
find('.btn-create').click
end
end
Loading
Loading
Loading
Loading
@@ -37,6 +37,10 @@ module API
@projects = @projects.where(archived: parse_boolean(params[:archived]))
end
 
if params[:search].present?
@projects = @projects.search(params[:search])
end
@projects = paginate @projects
present @projects, with: Entities::Project
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment