Commit fbf5cf2f authored by Saikat Sarkar's avatar Saikat Sarkar

Merge branch 'registration-features' into 'master'

Enable EE registration features for UsagePing

See merge request gitlab-org/gitlab!64003
parents 10175423 045cd563
......@@ -5,7 +5,7 @@ module Admin
include Gitlab::Utils::StrongMemoize
def send_emails_from_admin_area_feature_available?
License.feature_available?(:send_emails_from_admin_area)
License.feature_available?(:send_emails_from_admin_area) || License.features_with_usage_ping.include?(:send_emails_from_admin_area)
end
def admin_emails_are_currently_rate_limited?
......
......@@ -13,6 +13,10 @@ class License < ApplicationRecord
EE_ALL_PLANS = [STARTER_PLAN, PREMIUM_PLAN, ULTIMATE_PLAN].freeze
EES_FEATURES_WITH_USAGE_PING = %i[
send_emails_from_admin_area
].freeze
EES_FEATURES = %i[
audit_events
blocked_issues
......@@ -44,12 +48,11 @@ class License < ApplicationRecord
repository_size_limit
resource_access_token
seat_link
send_emails_from_admin_area
scoped_issue_board
usage_quotas
visual_review_app
wip_limits
].freeze
].freeze + EES_FEATURES_WITH_USAGE_PING
EEP_FEATURES = EES_FEATURES + %i[
adjourned_deletion_for_projects_and_groups
......@@ -199,6 +202,8 @@ class License < ApplicationRecord
end
end.freeze
FEATURES_WITH_USAGE_PING = EES_FEATURES_WITH_USAGE_PING
# Add on codes that may occur in legacy licenses that don't have a plan yet.
FEATURES_FOR_ADD_ONS = {
'GitLab_Auditor_User' => :auditor_user,
......@@ -275,6 +280,12 @@ class License < ApplicationRecord
PLANS_BY_FEATURE.fetch(feature, [])
end
def features_with_usage_ping
return FEATURES_WITH_USAGE_PING if Gitlab::CurrentSettings.usage_ping_enabled?
[]
end
def plan_includes_feature?(plan, feature)
plans_with_feature(feature).include?(plan)
end
......
......@@ -31,6 +31,7 @@ RSpec.describe Admin::EmailsController, :clean_gitlab_redis_shared_state do
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(false)
end
it 'returns 404' do
......@@ -39,6 +40,19 @@ RSpec.describe Admin::EmailsController, :clean_gitlab_redis_shared_state do
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when usage ping is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(true)
end
it 'responds with 200' do
subject
expect(response).to have_gitlab_http_status(:ok)
end
end
end
context 'non-admin user' do
......@@ -122,6 +136,7 @@ RSpec.describe Admin::EmailsController, :clean_gitlab_redis_shared_state do
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(false)
end
it 'does not trigger the service to send emails' do
......@@ -136,6 +151,29 @@ RSpec.describe Admin::EmailsController, :clean_gitlab_redis_shared_state do
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'when usage ping is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(true)
end
it 'triggers the service to send emails' do
expect_next_instance_of(Admin::EmailService, recipients, email_subject, body) do |email_service|
expect(email_service).to receive(:execute)
end
subject
end
it 'redirects to `admin_email_path` with success notice' 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
end
context 'non-admin user' do
......
......@@ -14,6 +14,7 @@ RSpec.describe 'Admin::Emails', :clean_gitlab_redis_shared_state do
context 'when `send_emails_from_admin_area` feature is not licensed' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(false)
end
it 'returns 404' do
......@@ -23,6 +24,19 @@ RSpec.describe 'Admin::Emails', :clean_gitlab_redis_shared_state do
end
end
context 'when usage ping is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(true)
end
it 'returns 200' do
visit admin_email_path
expect(page.status_code).to eq(200)
end
end
context 'when `send_emails_from_admin_area` feature is licensed' do
let(:rate_limited_alert) do
'An email notification was recently sent from the admin panel. '\
......
......@@ -28,6 +28,7 @@ RSpec.describe "Admin::Users", :js do
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(false)
end
it "does not show the 'Send email to users' link" do
......@@ -36,6 +37,19 @@ RSpec.describe "Admin::Users", :js do
expect(page).not_to have_link(href: admin_email_path)
end
end
context 'when usage ping is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(true)
end
it "shows the 'Send email to users' link" do
visit admin_users_path
expect(page).to have_link(href: admin_email_path)
end
end
end
describe 'user permission export' do
......
......@@ -22,10 +22,22 @@ RSpec.describe Admin::EmailsHelper, :clean_gitlab_redis_shared_state do
context 'when `send_emails_from_admin_area` feature is disabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(false)
end
it { is_expected.to be_falsey }
end
context 'when usage ping is enabled' do
before do
stub_licensed_features(send_emails_from_admin_area: false)
allow(Gitlab::CurrentSettings).to receive(:usage_ping_enabled?).and_return(true)
end
it 'returns true' do
expect(subject).to eq(true)
end
end
end
describe '#admin_emails_are_currently_rate_limited?' 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