Display list of recipientgroups properly

- Use html5 validation
- initiate create action
parent 859aa33a
class Admin::EmailsController < Admin::ApplicationController class Admin::EmailsController < Admin::ApplicationController
def show def show
end end
def create
AdminEmailsWorker.perform_async(params[:recipients], params[:subject], params[:body])
redirect_to admin_email_path, notice: 'Email send'
end
protected
end end
...@@ -2,7 +2,7 @@ module AdminEmailHelper ...@@ -2,7 +2,7 @@ module AdminEmailHelper
def admin_email_grouped_recipient_options def admin_email_grouped_recipient_options
options_for_select([['Everyone', 'all']]) + options_for_select([['Everyone', 'all']]) +
grouped_options_for_select( grouped_options_for_select(
'Groups' => Group.pluck(:name, :id).map{ |name, id| [name, "group_#{id}"] }, 'Groups' => Group.pluck(:name, :id).map{ |name, id| [name, "group-#{id}"] },
'Projects' => grouped_project_list 'Projects' => grouped_project_list
) )
end end
...@@ -12,7 +12,7 @@ module AdminEmailHelper ...@@ -12,7 +12,7 @@ module AdminEmailHelper
Group.includes(:projects).flat_map do |group| Group.includes(:projects).flat_map do |group|
group.human_name group.human_name
group.projects.map do |project| group.projects.map do |project|
["#{group.human_name} / #{project.name}", "project_#{project.id}"] ["#{group.human_name} / #{project.name}", "project-#{project.id}"]
end end
end end
end end
......
...@@ -7,17 +7,16 @@ ...@@ -7,17 +7,16 @@
.form-group .form-group
%label.control-label{for: :subject} Subject %label.control-label{for: :subject} Subject
.col-sm-10 .col-sm-10
= text_field_tag :subject, '', class: 'form-control' = text_field_tag :subject, '', class: 'form-control', required: true
.form-group .form-group
%label.control-label{for: :body} Body %label.control-label{for: :body} Body
.col-sm-10 .col-sm-10
= text_area_tag :body, '', class: 'form-control', rows: 15 = text_area_tag :body, '', class: 'form-control', rows: 15, required: true
.form-group .form-group
%label.control-label{for: :recipients} Recipients %label.control-label{for: :recipients} Recipient group
.col-sm-10 .col-sm-10
= select_tag :recipients, admin_email_grouped_recipient_options, class: :select2 = select_tag :recipients, admin_email_grouped_recipient_options, class: :select2, required: true
.form-actions .form-actions
= submit_tag 'Send message', class: 'btn btn-create' = submit_tag 'Send message', class: 'btn btn-create'
...@@ -86,7 +86,7 @@ Gitlab::Application.routes.draw do ...@@ -86,7 +86,7 @@ Gitlab::Application.routes.draw do
resources :broadcast_messages, only: [:index, :create, :destroy] resources :broadcast_messages, only: [:index, :create, :destroy]
resource :logs, only: [:show] resource :logs, only: [:show]
resource :background_jobs, controller: 'background_jobs', only: [:show] resource :background_jobs, controller: 'background_jobs', only: [:show]
resource :email, only: [:show] resource :email, only: [:show, :create]
resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, only: [:index, :show] do resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, only: [:index, :show] do
member do member do
......
...@@ -123,4 +123,8 @@ describe Admin::EmailsController, "routing" do ...@@ -123,4 +123,8 @@ describe Admin::EmailsController, "routing" do
it "to #show" do it "to #show" do
get("/admin/email").should route_to('admin/emails#show') get("/admin/email").should route_to('admin/emails#show')
end end
it "to #create" do
post("/admin/email").should route_to('admin/emails#create')
end
end end
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