chore: Cleanup feature flags (#6096)

- Add more feature flags for CRM, auto_resolution, and reports
- Add a SuperAdmin link in the sidebar if the user is a super-admin
- SuperAdmin could view all the features on an account irrespective of whether the feature is enabled.
This commit is contained in:
Pranav Raj S 2022-12-19 09:08:30 -08:00 committed by GitHub
parent ca88eb55f4
commit 2dfe38ae4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 99 additions and 15 deletions

View file

@ -1,3 +1,4 @@
import { FEATURE_FLAGS } from '../../../../featureFlags';
import { frontendURL } from '../../../../helper/URLHelper';
const primaryMenuItems = accountId => [
@ -13,6 +14,7 @@ const primaryMenuItems = accountId => [
icon: 'book-contacts',
key: 'contacts',
label: 'CONTACTS',
featureFlag: FEATURE_FLAGS.CRM,
toState: frontendURL(`accounts/${accountId}/contacts`),
toStateName: 'contacts_dashboard',
roles: ['administrator', 'agent'],
@ -21,6 +23,7 @@ const primaryMenuItems = accountId => [
icon: 'arrow-trending-lines',
key: 'reports',
label: 'REPORTS',
featureFlag: FEATURE_FLAGS.REPORTS,
toState: frontendURL(`accounts/${accountId}/reports`),
toStateName: 'settings_account_reports',
roles: ['administrator'],
@ -29,7 +32,7 @@ const primaryMenuItems = accountId => [
icon: 'megaphone',
key: 'campaigns',
label: 'CAMPAIGNS',
featureFlag: 'campaigns',
featureFlag: FEATURE_FLAGS.CAMPAIGNS,
toState: frontendURL(`accounts/${accountId}/campaigns`),
toStateName: 'settings_account_campaigns',
roles: ['administrator'],
@ -38,7 +41,7 @@ const primaryMenuItems = accountId => [
icon: 'library',
key: 'helpcenter',
label: 'HELP_CENTER.TITLE',
featureFlag: 'help_center',
featureFlag: FEATURE_FLAGS.HELP_CENTER,
toState: frontendURL(`accounts/${accountId}/portals`),
toStateName: 'default_portal_articles',
roles: ['administrator'],

View file

@ -102,6 +102,7 @@ const settings = accountId => ({
label: 'AGENT_BOTS',
beta: true,
hasSubMenu: false,
globalConfigFlag: 'csmlEditorHost',
toState: frontendURL(`accounts/${accountId}/settings/agent-bots`),
toStateName: 'agent_bots',
featureFlag: FEATURE_FLAGS.AGENT_BOTS,

View file

@ -61,6 +61,24 @@
</a>
</router-link>
</woot-dropdown-item>
<woot-dropdown-item v-if="currentUser.type === 'SuperAdmin'">
<a
href="/super_admin"
class="button small clear secondary"
target="_blank"
rel="noopener nofollow noreferrer"
@click="$emit('close')"
>
<fluent-icon
icon="content-settings"
size="14"
class="icon icon--font"
/>
<span class="button__content">
{{ $t('SIDEBAR_ITEMS.SUPER_ADMIN_CONSOLE') }}
</span>
</a>
</woot-dropdown-item>
<woot-dropdown-item>
<woot-button
variant="clear"

View file

@ -106,18 +106,22 @@ export default {
activeInbox: 'getSelectedInbox',
accountId: 'getCurrentAccountId',
isFeatureEnabledonAccount: 'accounts/isFeatureEnabledonAccount',
globalConfig: 'globalConfig/get',
}),
hasSubMenu() {
return !!this.menuItem.children;
},
isMenuItemVisible() {
if (!this.menuItem.featureFlag) {
return true;
if (this.menuItem.globalConfigFlag) {
return !!this.globalConfig[this.menuItem.globalConfigFlag];
}
return this.isFeatureEnabledonAccount(
this.accountId,
this.menuItem.featureFlag
);
if (this.menuItem.featureFlag) {
return this.isFeatureEnabledonAccount(
this.accountId,
this.menuItem.featureFlag
);
}
return true;
},
isAllConversations() {
return (

View file

@ -1,13 +1,18 @@
export const FEATURE_FLAGS = {
AGENT_BOTS: 'agent_bots',
AGENT_MANAGEMENT: 'agent_management',
AUTO_RESOLVE_CONVERSATIONS: 'auto_resolve_conversations',
AUTOMATIONS: 'automations',
CAMPAIGNS: 'campaigns',
CANNED_RESPONSES: 'canned_responses',
CRM: 'crm',
CUSTOM_ATTRIBUTES: 'custom_attributes',
INBOX_MANAGEMENT: 'inbox_management',
INTEGRATIONS: 'integrations',
LABELS: 'labels',
MACROS: 'macros',
HELP_CENTER: 'help_center',
REPORTS: 'reports',
TEAM_MANAGEMENT: 'team_management',
VOICE_RECORDER: 'voice_recorder',
};

View file

@ -132,6 +132,7 @@
"SELECTOR_SUBTITLE": "Select an account from the following list",
"PROFILE_SETTINGS": "Profile Settings",
"KEYBOARD_SHORTCUTS": "Keyboard Shortcuts",
"SUPER_ADMIN_CONSOLE": "Super Admin Console",
"LOGOUT": "Logout"
},
"APP_GLOBAL": {

View file

@ -32,6 +32,7 @@ const GO_TO_COMMANDS = [
id: 'goto_contacts_dashboard',
title: 'COMMAND_BAR.COMMANDS.GO_TO_CONTACTS_DASHBOARD',
section: 'COMMAND_BAR.SECTIONS.GENERAL',
featureFlag: FEATURE_FLAGS.CRM,
icon: ICON_CONTACT_DASHBOARD,
path: accountId => `accounts/${accountId}/contacts`,
role: ['administrator', 'agent'],
@ -40,6 +41,7 @@ const GO_TO_COMMANDS = [
id: 'open_reports_overview',
section: 'COMMAND_BAR.SECTIONS.REPORTS',
title: 'COMMAND_BAR.COMMANDS.GO_TO_REPORTS_OVERVIEW',
featureFlag: FEATURE_FLAGS.REPORTS,
icon: ICON_REPORTS_OVERVIEW,
path: accountId => `accounts/${accountId}/reports/overview`,
role: ['administrator'],
@ -48,6 +50,7 @@ const GO_TO_COMMANDS = [
id: 'open_conversation_reports',
section: 'COMMAND_BAR.SECTIONS.REPORTS',
title: 'COMMAND_BAR.COMMANDS.GO_TO_CONVERSATION_REPORTS',
featureFlag: FEATURE_FLAGS.REPORTS,
icon: ICON_CONVERSATION_REPORTS,
path: accountId => `accounts/${accountId}/reports/conversation`,
role: ['administrator'],
@ -56,6 +59,7 @@ const GO_TO_COMMANDS = [
id: 'open_agent_reports',
section: 'COMMAND_BAR.SECTIONS.REPORTS',
title: 'COMMAND_BAR.COMMANDS.GO_TO_AGENT_REPORTS',
featureFlag: FEATURE_FLAGS.REPORTS,
icon: ICON_AGENT_REPORTS,
path: accountId => `accounts/${accountId}/reports/agent`,
role: ['administrator'],
@ -64,6 +68,7 @@ const GO_TO_COMMANDS = [
id: 'open_label_reports',
section: 'COMMAND_BAR.SECTIONS.REPORTS',
title: 'COMMAND_BAR.COMMANDS.GO_TO_LABEL_REPORTS',
featureFlag: FEATURE_FLAGS.REPORTS,
icon: ICON_LABEL_REPORTS,
path: accountId => `accounts/${accountId}/reports/label`,
role: ['administrator'],
@ -72,6 +77,7 @@ const GO_TO_COMMANDS = [
id: 'open_inbox_reports',
section: 'COMMAND_BAR.SECTIONS.REPORTS',
title: 'COMMAND_BAR.COMMANDS.GO_TO_INBOX_REPORTS',
featureFlag: FEATURE_FLAGS.REPORTS,
icon: ICON_INBOX_REPORTS,
path: accountId => `accounts/${accountId}/reports/inboxes`,
role: ['administrator'],
@ -80,6 +86,7 @@ const GO_TO_COMMANDS = [
id: 'open_team_reports',
section: 'COMMAND_BAR.SECTIONS.REPORTS',
title: 'COMMAND_BAR.COMMANDS.GO_TO_TEAM_REPORTS',
featureFlag: FEATURE_FLAGS.REPORTS,
icon: ICON_TEAM_REPORTS,
path: accountId => `accounts/${accountId}/reports/teams`,
role: ['administrator'],

View file

@ -62,7 +62,10 @@
"
/>
</label>
<label :class="{ error: $v.autoResolveDuration.$error }">
<label
v-if="showAutoResolutionConfig"
:class="{ error: $v.autoResolveDuration.$error }"
>
{{ $t('GENERAL_SETTINGS.FORM.AUTO_RESOLVE_DURATION.LABEL') }}
<input
v-model="autoResolveDuration"
@ -120,6 +123,7 @@ import { mapGetters } from 'vuex';
import alertMixin from 'shared/mixins/alertMixin';
import configMixin from 'shared/mixins/configMixin';
import accountMixin from '../../../../mixins/account';
import { FEATURE_FLAGS } from '../../../../featureFlags';
const semver = require('semver');
export default {
@ -153,7 +157,15 @@ export default {
globalConfig: 'globalConfig/get',
getAccount: 'accounts/getAccount',
uiFlags: 'accounts/getUIFlags',
accountId: 'getCurrentAccountId',
isFeatureEnabledonAccount: 'accounts/isFeatureEnabledonAccount',
}),
showAutoResolutionConfig() {
return this.isFeatureEnabledonAccount(
this.accountId,
FEATURE_FLAGS.AUTO_RESOLVE_CONVERSATIONS
);
},
hasAnUpdateAvailable() {
if (!semver.valid(this.latestChatwootVersion)) {
return false;

View file

@ -21,7 +21,16 @@ export const getters = {
getUIFlags($state) {
return $state.uiFlags;
},
isFeatureEnabledonAccount: $state => (id, featureName) => {
isFeatureEnabledonAccount: ($state, _, __, rootGetters) => (
id,
featureName
) => {
// If a user is SuperAdmin and has access to the account, then they would see all the available features
const isUserASuperAdmin = rootGetters.getCurrentUser?.type === 'SuperAdmin';
if (isUserASuperAdmin) {
return true;
}
const { features = {} } =
$state.records.find(record => record.id === Number(id)) || {};
return features[featureName] || false;

View file

@ -57,6 +57,7 @@
"contact-card-group-outline": "M18.75 4A3.25 3.25 0 0 1 22 7.25v9.505a3.25 3.25 0 0 1-3.25 3.25H5.25A3.25 3.25 0 0 1 2 16.755V7.25a3.25 3.25 0 0 1 3.066-3.245L5.25 4h13.5Zm0 1.5H5.25l-.144.006A1.75 1.75 0 0 0 3.5 7.25v9.505c0 .966.784 1.75 1.75 1.75h13.5a1.75 1.75 0 0 0 1.75-1.75V7.25a1.75 1.75 0 0 0-1.75-1.75Zm-9.497 7a.75.75 0 0 1 .75.75v.582c0 1.272-.969 1.918-2.502 1.918S5 15.104 5 13.831v-.581a.75.75 0 0 1 .75-.75h3.503Zm1.58-.001 1.417.001a.75.75 0 0 1 .75.75v.333c0 .963-.765 1.417-1.875 1.417-.116 0-.229-.005-.337-.015a2.85 2.85 0 0 0 .206-.9l.009-.253v-.582c0-.269-.061-.524-.17-.751Zm4.417.001h3a.75.75 0 0 1 .102 1.493L18.25 14h-3a.75.75 0 0 1-.102-1.493l.102-.007h3-3Zm-7.75-4a1.5 1.5 0 1 1 0 3.001 1.5 1.5 0 0 1 0-3.001Zm3.87.502a1.248 1.248 0 1 1 0 2.496 1.248 1.248 0 0 1 0-2.496Zm3.88.498h3a.75.75 0 0 1 .102 1.493L18.25 11h-3a.75.75 0 0 1-.102-1.493l.102-.007h3-3Z",
"contact-card-outline": "M19.75 4A2.25 2.25 0 0 1 22 6.25v11.505a2.25 2.25 0 0 1-2.25 2.25H4.25A2.25 2.25 0 0 1 2 17.755V6.25A2.25 2.25 0 0 1 4.25 4h15.5Zm0 1.5H4.25a.75.75 0 0 0-.75.75v11.505c0 .414.336.75.75.75h15.5a.75.75 0 0 0 .75-.75V6.25a.75.75 0 0 0-.75-.75Zm-10 7a.75.75 0 0 1 .75.75v.493l-.008.108c-.163 1.113-1.094 1.65-2.492 1.65s-2.33-.537-2.492-1.65l-.008-.11v-.491a.75.75 0 0 1 .75-.75h3.5Zm3.502.496h4.498a.75.75 0 0 1 .102 1.493l-.102.007h-4.498a.75.75 0 0 1-.102-1.493l.102-.007h4.498-4.498ZM8 8.502a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3Zm5.252.998h4.498a.75.75 0 0 1 .102 1.493L17.75 11h-4.498a.75.75 0 0 1-.102-1.493l.102-.007h4.498-4.498Z",
"contact-identify-outline": "m11.91 13.998 7.843.002a2.25 2.25 0 0 1 2.25 2.25v.905A3.75 3.75 0 0 1 20.696 20C19.13 21.344 16.89 22 14 22h-.179c.234-.47.242-1.025.026-1.502l.153.003c2.56 0 4.458-.557 5.719-1.64a2.25 2.25 0 0 0 .784-1.706v-.905a.75.75 0 0 0-.75-.75h-7.776a5.565 5.565 0 0 0-.068-1.502ZM6.5 10.5a4.5 4.5 0 0 1 3.46 7.376l2.823 2.814a.75.75 0 0 1-.975 1.135l-.085-.073-2.903-2.896A4.5 4.5 0 1 1 6.5 10.5Zm0 1.5a3 3 0 1 0 0 6 3 3 0 0 0 0-6ZM14 2.004a5 5 0 1 1 0 10 5 5 0 0 1 0-10Zm0 1.5a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7Z",
"content-settings-outline": "m17.751 3 .185.005a3.25 3.25 0 0 1 3.06 3.06l.005.185v5.772a6.468 6.468 0 0 0-1.5-.709L19.5 8H4.501L4.5 17.75a1.75 1.75 0 0 0 1.606 1.744l.144.006h5.064c.172.534.412 1.037.708 1.5H6.25a3.25 3.25 0 0 1-3.245-3.066L3 17.75V6.25a3.25 3.25 0 0 1 3.066-3.245L6.25 3h11.501Zm0 1.5h-11.5a1.75 1.75 0 0 0-1.75 1.75v.25h15v-.25a1.75 1.75 0 0 0-1.75-1.75Zm-7.501 5a.75.75 0 0 1 .743.648l.007.102v7a.75.75 0 0 1-.648.743L10.25 18h-3.5a.75.75 0 0 1-.743-.648L6 17.25v-7a.75.75 0 0 1 .648-.743L6.75 9.5h3.5ZM9.5 11h-2v5.5h2V11Zm8.5-.75a.75.75 0 0 0-.75-.75h-4.496l-.101.007A.75.75 0 0 0 12.754 11h4.496l.102-.007A.75.75 0 0 0 18 10.25Zm-3.72 3.725a2 2 0 0 1-1.442 2.497l-.584.144a5.729 5.729 0 0 0 .006 1.807l.54.13a2 2 0 0 1 1.45 2.51l-.187.632c.44.386.94.699 1.484.921l.494-.518a2 2 0 0 1 2.899 0l.498.525a5.28 5.28 0 0 0 1.483-.913l-.198-.686a2 2 0 0 1 1.442-2.496l.583-.144a5.729 5.729 0 0 0-.006-1.808l-.54-.13a2 2 0 0 1-1.45-2.51l.187-.63a5.28 5.28 0 0 0-1.484-.923l-.493.519a2 2 0 0 1-2.9 0l-.498-.525c-.544.22-1.044.53-1.483.912l.198.686ZM17.5 19c-.8 0-1.45-.672-1.45-1.5 0-.829.65-1.5 1.45-1.5.8 0 1.45.671 1.45 1.5 0 .828-.65 1.5-1.45 1.5Z",
"copy-outline": [
"M8 3a1 1 0 0 0-1 1v.5a.5.5 0 0 1-1 0V4a2 2 0 0 1 2-2h.5a.5.5 0 0 1 0 1H8z",
"M7 12a1 1 0 0 0 1 1h.5a.5.5 0 0 1 0 1H8a2 2 0 0 1-2-2v-.5a.5.5 0 0 1 1 0v.5z",

View file

@ -16,6 +16,7 @@ json.custom_attributes resource.custom_attributes if resource.custom_attributes.
json.role resource.active_account_user&.role
json.ui_settings resource.ui_settings
json.uid resource.uid
json.type resource.type
json.accounts do
json.array! resource.account_users do |account_user|
json.id account_user.account_id

View file

@ -1,8 +1,6 @@
# DO NOT change the order of features EVER
- name: inbound_emails
enabled: true
- name: channel_website
enabled: true
- name: channel_email
enabled: true
- name: channel_facebook
@ -15,8 +13,6 @@
enabled: false
- name: email_continuity_on_api_channel
enabled: false
- name: campaigns
enabled: true
- name: help_center
enabled: true
- name: agent_bots
@ -43,3 +39,13 @@
enabled: true
- name: mobile_v2
enabled: false
- name: channel_website
enabled: true
- name: campaigns
enabled: true
- name: reports
enabled: true
- name: crm
enabled: true
- name: auto_resolve_conversations
enabled: true

View file

@ -0,0 +1,16 @@
class EnabledNewFeatures < ActiveRecord::Migration[6.1]
def change
Account.find_in_batches do |account_batch|
account_batch.each do |account|
account.enable_features(
'channel_website',
'campaigns',
'reports',
'crm',
'auto_resolve_conversations'
)
account.save!
end
end
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_11_16_000514) do
ActiveRecord::Schema.define(version: 2022_12_19_162759) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"