Commit 2a9c6d04 authored by James Lopez's avatar James Lopez

Merge branch 'license-check-for-admin-email-blast' into 'master'

Add License check for the 'send emails from Admin area' feature.

See merge request gitlab-org/gitlab!31434
parents 4510938a 462a51b9
# frozen_string_literal: true
class Admin::EmailsController < Admin::ApplicationController
include Admin::EmailsHelper
before_action :check_license_send_emails_from_admin_area_available!
def show
end
......@@ -8,4 +12,10 @@ class Admin::EmailsController < Admin::ApplicationController
AdminEmailsWorker.perform_async(params[:recipients], params[:subject], params[:body]) # rubocop:disable CodeReuse/Worker
redirect_to admin_email_path, notice: 'Email sent'
end
private
def check_license_send_emails_from_admin_area_available!
render_404 unless send_emails_from_admin_area_feature_available?
end
end
# frozen_string_literal: true
module Admin
module EmailsHelper
def send_emails_from_admin_area_feature_available?
License.feature_available?(:send_emails_from_admin_area)
end
end
end
......@@ -36,6 +36,7 @@ class License < ApplicationRecord
repository_mirrors
repository_size_limit
seat_link
send_emails_from_admin_area
service_desk
scoped_issue_board
usage_quotas
......
- return unless send_emails_from_admin_area_feature_available?
= link_to s_('AdminUsers|Send email to users'), admin_email_path, class: 'btn'
---
title: Add license check for the 'send emails from Admin area' feature
merge_request: 31434
author:
type: fixed
# frozen_string_literal: true
require 'spec_helper'
describe Admin::EmailsController do
let_it_be(:admin) { create(:admin) }
let_it_be(:user) { create(:user) }
describe 'GET #show' do
subject { get :show }
context 'admin user' do
before do
sign_in(admin)
end
context 'when `send_emails_from_admin_area` feature is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: true)
end
it 'responds with 200' do
subject
expect(response).to have_gitlab_http_status(:ok)
end
end
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
context 'non-admin user' do
before do
sign_in(user)
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
describe 'POST #create' do
subject do
post :create, params: {
recipients: 'all',
subject: 'subject',
body: 'body'
}
end
context 'admin user' do
before do
sign_in(admin)
end
context 'when `send_emails_from_admin_area` feature is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: true)
end
it 'trigger the background job to send emails' do
expect(AdminEmailsWorker).to receive(:perform_async).with('all', 'subject', 'body')
subject
end
it 'redirects to `admin_email_path`' do
subject
expect(response).to have_gitlab_http_status(:found)
expect(response).to redirect_to(admin_email_path)
expect(flash[:notice]).to eq('Email sent')
end
end
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
end
it 'does not trigger the background job to send emails' do
expect(AdminEmailsWorker).not_to receive(:perform_async)
subject
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
context 'non-admin user' do
before do
sign_in(user)
end
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
end
......@@ -15,6 +15,34 @@ describe "Admin::Users" do
sign_in(current_user)
end
describe 'GET /admin/users' do
describe 'send emails to users' do
context 'when `send_emails_from_admin_area` feature is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: true)
end
it "shows the 'Send email to users' link" do
visit admin_users_path
expect(page).to have_link('Send email to users', href: admin_email_path)
end
end
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
end
it "does not show the 'Send email to users' link" do
visit admin_users_path
expect(page).not_to have_link('Send email to users', href: admin_email_path)
end
end
end
end
describe "GET /admin/users/:id" do
describe 'Shared runners quota status' do
before do
......
# frozen_string_literal: true
require 'spec_helper'
describe Admin::EmailsHelper do
describe '#send_emails_from_admin_area_feature_available?' do
subject { helper.send_emails_from_admin_area_feature_available? }
context 'when `send_emails_from_admin_area` feature is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: true)
end
it { is_expected.to be_truthy }
end
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
end
it { is_expected.to be_falsey }
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