Commit 0b90507d authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'user-lists-controller-plus-fix' into 'master'

Add Feature Flag User Lists Controller With IidRoute

See merge request gitlab-org/gitlab!31392
parents 886a718d eda65cfc
# frozen_string_literal: true
class Projects::FeatureFlagsUserListsController < Projects::ApplicationController
before_action :check_feature_flag!
before_action :authorize_admin_feature_flags_user_lists!
before_action :user_list, only: [:edit, :show]
def new
end
def edit
end
def show
end
private
def check_feature_flag!
not_found unless Feature.enabled?(:feature_flag_user_lists, project)
end
def user_list
@user_list = project.operations_feature_flags_user_lists.find_by_iid!(params[:iid])
end
end
......@@ -4,6 +4,7 @@ module Operations
module FeatureFlags
class UserList < ApplicationRecord
include AtomicInternalId
include IidRoutes
self.table_name = 'operations_user_lists'
......
- add_to_breadcrumbs s_('FeatureFlags|Feature Flags'), project_feature_flags_path(@project)
- breadcrumb_title s_('FeatureFlags|Edit list')
- page_title s_('FeatureFlags|Edit Feature Flag User List')
Edit list
%label{ for: 'name' }= s_('FeatureFlags|Name')
%input{ id: 'name', value: @user_list.name }
- add_to_breadcrumbs s_('FeatureFlags|Feature Flags'), project_feature_flags_path(@project)
- breadcrumb_title s_('FeatureFlags|New list')
- page_title s_('FeatureFlags|New Feature Flag User List')
New list
- add_to_breadcrumbs s_('FeatureFlags|Feature Flags'), project_feature_flags_path(@project)
- breadcrumb_title s_('FeatureFlags|List details')
- page_title s_('FeatureFlags|Feature Flag User List Details')
List details
%p= @user_list.name
......@@ -33,6 +33,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
resource :feature_flags_client, only: [] do
post :reset_token
end
resources :feature_flags_user_lists, param: :iid, only: [:new, :edit, :show]
resources :autocomplete_sources, only: [] do
collection do
......
# frozen_string_literal: true
require 'spec_helper'
describe Projects::FeatureFlagsUserListsController do
let_it_be(:project) { create(:project) }
let_it_be(:reporter) { create(:user) }
let_it_be(:developer) { create(:user) }
before_all do
project.add_reporter(reporter)
project.add_developer(developer)
end
before do
stub_licensed_features(feature_flags: true)
end
def request_params(extra_params = {})
{ namespace_id: project.namespace, project_id: project }.merge(extra_params)
end
describe 'GET #new' do
it 'redirects when the user is unauthenticated' do
get(:new, params: request_params)
expect(response).to redirect_to(new_user_session_path)
end
it 'returns not found if the user does not belong to the project' do
user = create(:user)
sign_in(user)
get(:new, params: request_params)
expect(response).to have_gitlab_http_status(:not_found)
end
it 'returns not found for a reporter' do
sign_in(reporter)
get(:new, params: request_params)
expect(response).to have_gitlab_http_status(:not_found)
end
it 'returns not found when feature flags are not licensed' do
stub_licensed_features(feature_flags: false)
sign_in(developer)
get(:new, params: request_params)
expect(response).to have_gitlab_http_status(:not_found)
end
it 'renders the new page for a developer' do
sign_in(developer)
get(:new, params: request_params)
expect(response).to have_gitlab_http_status(:ok)
end
it 'returns not found when the feature flag is off' do
stub_feature_flags(feature_flag_user_lists: false)
sign_in(developer)
get(:new, params: request_params)
expect(response).to have_gitlab_http_status(:not_found)
end
end
describe 'GET #edit' do
before do
sign_in(developer)
end
it 'renders the edit page for a developer' do
list = create(:operations_feature_flag_user_list, project: project)
get(:edit, params: request_params(iid: list.iid))
expect(response).to have_gitlab_http_status(:ok)
end
it 'returns not found with an iid that does not exist' do
list = create(:operations_feature_flag_user_list, project: project)
get(:edit, params: request_params(iid: list.iid + 1))
expect(response).to have_gitlab_http_status(:not_found)
end
it 'returns not found for a list belonging to a another project' do
other_project = create(:project)
list = create(:operations_feature_flag_user_list, project: other_project)
get(:edit, params: request_params(iid: list.iid))
expect(response).to have_gitlab_http_status(:not_found)
end
it 'returns not found when the feature flag is off' do
stub_feature_flags(feature_flag_user_lists: false)
list = create(:operations_feature_flag_user_list, project: project)
get(:edit, params: request_params(iid: list.iid))
expect(response).to have_gitlab_http_status(:not_found)
end
end
describe 'GET #show' do
before do
sign_in(developer)
end
it 'renders the page for a developer' do
list = create(:operations_feature_flag_user_list, project: project)
get(:show, params: request_params(iid: list.iid))
expect(response).to have_gitlab_http_status(:ok)
end
it 'returns not found with an iid that does not exist' do
list = create(:operations_feature_flag_user_list, project: project)
get(:show, params: request_params(iid: list.iid + 1))
expect(response).to have_gitlab_http_status(:not_found)
end
it 'returns not found for a list belonging to a another project' do
other_project = create(:project)
list = create(:operations_feature_flag_user_list, project: other_project)
get(:show, params: request_params(iid: list.iid))
expect(response).to have_gitlab_http_status(:not_found)
end
it 'returns not found when the feature flag is off' do
stub_feature_flags(feature_flag_user_lists: false)
list = create(:operations_feature_flag_user_list, project: project)
get(:show, params: request_params(iid: list.iid))
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe 'User edits feature flag user list', :js do
let_it_be(:project) { create(:project) }
let_it_be(:developer) { create(:user) }
before do
project.add_developer(developer)
stub_licensed_features(feature_flags: true)
sign_in(developer)
end
it 'prefills the edit form with the list name' do
list = create(:operations_feature_flag_user_list, project: project, name: 'My List Name')
visit(edit_project_feature_flags_user_list_path(project, list))
expect(page).to have_field 'Name', with: 'My List Name'
end
end
# frozen_string_literal: true
require 'spec_helper'
describe 'User sees feature flag user list details', :js do
let_it_be(:project) { create(:project) }
let_it_be(:developer) { create(:user) }
before do
project.add_developer(developer)
stub_licensed_features(feature_flags: true)
sign_in(developer)
end
it 'displays the list name' do
list = create(:operations_feature_flag_user_list, project: project, name: 'My List')
visit(project_feature_flags_user_list_path(project, list))
expect(page).to have_text('My List')
end
end
......@@ -55,6 +55,18 @@ describe Operations::FeatureFlags::UserList do
end
end
describe 'url_helpers' do
it 'generates paths based on the internal id' do
create(:operations_feature_flag_user_list)
project_b = create(:project)
list_b = create(:operations_feature_flag_user_list, project: project_b)
path = ::Gitlab::Routing.url_helpers.project_feature_flags_user_list_path(project_b, list_b)
expect(path).to eq("/#{project_b.full_path}/-/feature_flags_user_lists/#{list_b.iid}")
end
end
it_behaves_like 'AtomicInternalId' do
let(:internal_id_attribute) { :iid }
let(:instance) { build(:operations_feature_flag_user_list) }
......
......@@ -9142,6 +9142,12 @@ msgstr ""
msgid "FeatureFlags|Edit Feature Flag"
msgstr ""
msgid "FeatureFlags|Edit Feature Flag User List"
msgstr ""
msgid "FeatureFlags|Edit list"
msgstr ""
msgid "FeatureFlags|Enable features for specific users and specific environments by defining feature flag strategies. By default, features are available to all users in all environments."
msgstr ""
......@@ -9154,6 +9160,9 @@ msgstr ""
msgid "FeatureFlags|Feature Flag"
msgstr ""
msgid "FeatureFlags|Feature Flag User List Details"
msgstr ""
msgid "FeatureFlags|Feature Flag behavior is built up by creating a set of rules to define the status of target environments. A default wildcard rule %{codeStart}*%{codeEnd} for %{boldStart}All Environments%{boldEnd} is set, and you are able to add as many rules as you need by choosing environment specs below. You can toggle the behavior for each of your rules to set them %{boldStart}Active%{boldEnd} or %{boldStart}Inactive%{boldEnd}."
msgstr ""
......@@ -9196,6 +9205,9 @@ msgstr ""
msgid "FeatureFlags|Instance ID"
msgstr ""
msgid "FeatureFlags|List details"
msgstr ""
msgid "FeatureFlags|Loading feature flags"
msgstr ""
......@@ -9211,9 +9223,15 @@ msgstr ""
msgid "FeatureFlags|New Feature Flag"
msgstr ""
msgid "FeatureFlags|New Feature Flag User List"
msgstr ""
msgid "FeatureFlags|New feature flag"
msgstr ""
msgid "FeatureFlags|New list"
msgstr ""
msgid "FeatureFlags|Percent rollout (logged in users)"
msgstr ""
......
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