Commit 2c40533d authored by Jason Goodman's avatar Jason Goodman Committed by Shinya Maeda

Create feature flag user lists controller

Add skeleton templates for new, edit, and show actions
parent 877b8f2c
# 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
- 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
...@@ -30,6 +30,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -30,6 +30,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
resource :feature_flags_client, only: [] do resource :feature_flags_client, only: [] do
post :reset_token post :reset_token
end end
resources :feature_flags_user_lists, param: :iid, only: [:new, :edit, :show]
resources :autocomplete_sources, only: [] do resources :autocomplete_sources, only: [] do
collection 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 do
project.add_reporter(reporter)
project.add_developer(developer)
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
...@@ -9100,6 +9100,12 @@ msgstr "" ...@@ -9100,6 +9100,12 @@ msgstr ""
msgid "FeatureFlags|Edit Feature Flag" msgid "FeatureFlags|Edit Feature Flag"
msgstr "" 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." 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 "" msgstr ""
...@@ -9112,6 +9118,9 @@ msgstr "" ...@@ -9112,6 +9118,9 @@ msgstr ""
msgid "FeatureFlags|Feature Flag" msgid "FeatureFlags|Feature Flag"
msgstr "" 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}." 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 "" msgstr ""
...@@ -9148,6 +9157,9 @@ msgstr "" ...@@ -9148,6 +9157,9 @@ msgstr ""
msgid "FeatureFlags|Instance ID" msgid "FeatureFlags|Instance ID"
msgstr "" msgstr ""
msgid "FeatureFlags|List details"
msgstr ""
msgid "FeatureFlags|Loading feature flags" msgid "FeatureFlags|Loading feature flags"
msgstr "" msgstr ""
...@@ -9163,9 +9175,15 @@ msgstr "" ...@@ -9163,9 +9175,15 @@ msgstr ""
msgid "FeatureFlags|New Feature Flag" msgid "FeatureFlags|New Feature Flag"
msgstr "" msgstr ""
msgid "FeatureFlags|New Feature Flag User List"
msgstr ""
msgid "FeatureFlags|New feature flag" msgid "FeatureFlags|New feature flag"
msgstr "" msgstr ""
msgid "FeatureFlags|New list"
msgstr ""
msgid "FeatureFlags|Percent rollout (logged in users)" msgid "FeatureFlags|Percent rollout (logged in users)"
msgstr "" 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