From 71f7675cd9309cf4ee9ef74f4af8341e918509d8 Mon Sep 17 00:00:00 2001 From: Jan-Willem van der Meer Date: Fri, 8 Aug 2014 20:47:08 +0200 Subject: [PATCH] Display list of recipientgroups properly - Use html5 validation - initiate create action --- app/controllers/admin/emails_controller.rb | 7 +++++++ app/helpers/admin_email_helper.rb | 4 ++-- app/views/admin/emails/show.html.haml | 9 ++++----- config/routes.rb | 2 +- spec/routing/admin_routing_spec.rb | 4 ++++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/emails_controller.rb b/app/controllers/admin/emails_controller.rb index 8c88263a48..49f4f4670f 100644 --- a/app/controllers/admin/emails_controller.rb +++ b/app/controllers/admin/emails_controller.rb @@ -1,4 +1,11 @@ class Admin::EmailsController < Admin::ApplicationController def show end + + def create + AdminEmailsWorker.perform_async(params[:recipients], params[:subject], params[:body]) + redirect_to admin_email_path, notice: 'Email send' + end + + protected end diff --git a/app/helpers/admin_email_helper.rb b/app/helpers/admin_email_helper.rb index 6d72c0d592..1769339941 100644 --- a/app/helpers/admin_email_helper.rb +++ b/app/helpers/admin_email_helper.rb @@ -2,7 +2,7 @@ module AdminEmailHelper def admin_email_grouped_recipient_options options_for_select([['Everyone', 'all']]) + 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 ) end @@ -12,7 +12,7 @@ module AdminEmailHelper Group.includes(:projects).flat_map do |group| group.human_name group.projects.map do |project| - ["#{group.human_name} / #{project.name}", "project_#{project.id}"] + ["#{group.human_name} / #{project.name}", "project-#{project.id}"] end end end diff --git a/app/views/admin/emails/show.html.haml b/app/views/admin/emails/show.html.haml index 037cba7017..36da8fc137 100644 --- a/app/views/admin/emails/show.html.haml +++ b/app/views/admin/emails/show.html.haml @@ -7,17 +7,16 @@ .form-group %label.control-label{for: :subject} Subject .col-sm-10 - = text_field_tag :subject, '', class: 'form-control' + = text_field_tag :subject, '', class: 'form-control', required: true .form-group %label.control-label{for: :body} Body .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 - %label.control-label{for: :recipients} Recipients + %label.control-label{for: :recipients} Recipient group .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 = submit_tag 'Send message', class: 'btn btn-create' diff --git a/config/routes.rb b/config/routes.rb index 718abfb20d..c1fafde18d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -86,7 +86,7 @@ Gitlab::Application.routes.draw do resources :broadcast_messages, only: [:index, :create, :destroy] resource :logs, 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 member do diff --git a/spec/routing/admin_routing_spec.rb b/spec/routing/admin_routing_spec.rb index c0e1c2b2c4..bb48f89288 100644 --- a/spec/routing/admin_routing_spec.rb +++ b/spec/routing/admin_routing_spec.rb @@ -123,4 +123,8 @@ describe Admin::EmailsController, "routing" do it "to #show" do get("/admin/email").should route_to('admin/emails#show') end + + it "to #create" do + post("/admin/email").should route_to('admin/emails#create') + end end