[FIX] Split get settings into two requests (#2017)

* [FIX] Split get settings into two requests

* [FIX] Clear settings only when change server

* [IMPROVEMENT] Move the way to clear settings

* [REVERT] Revert some changes

* [FIX] Server Icon

Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
Djorkaeff Alexandre 2020-04-09 02:26:28 -03:00 committed by GitHub
parent 2e65a795df
commit 00a21808ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View File

@ -13,6 +13,22 @@ import fetch from '../../utils/fetch';
const serverInfoKeys = ['Site_Name', 'UI_Use_Real_Name', 'FileUpload_MediaTypeWhiteList', 'FileUpload_MaxFileSize'];
// these settings are used only on onboarding process
const loginSettings = [
'API_Gitlab_URL',
'CAS_enabled',
'CAS_login_url',
'Accounts_EmailVerification',
'Accounts_ManuallyApproveNewUsers',
'Accounts_ShowFormLogin',
'Site_Url',
'Accounts_RegistrationForm',
'Accounts_RegistrationForm_LinkReplacementText',
'Accounts_EmailOrUsernamePlaceholder',
'Accounts_PasswordPlaceholder',
'Accounts_PasswordReset'
];
const serverInfoUpdate = async(serverInfo, iconSetting) => {
const serversDB = database.servers;
const serverId = reduxStore.getState().server.server;
@ -54,7 +70,7 @@ const serverInfoUpdate = async(serverInfo, iconSetting) => {
export async function getLoginSettings({ server }) {
try {
const settingsParams = JSON.stringify(['Accounts_ShowFormLogin', 'Accounts_RegistrationForm']);
const settingsParams = JSON.stringify(loginSettings);
const result = await fetch(`${ server }/api/v1/settings.public?query={"_id":{"$in":${ settingsParams }}}`).then(response => response.json());
if (result.success && result.settings.length) {
@ -84,7 +100,7 @@ export async function setSettings() {
export default async function() {
try {
const db = database.active;
const settingsParams = JSON.stringify(Object.keys(settings));
const settingsParams = JSON.stringify(Object.keys(settings).filter(key => !loginSettings.includes(key)));
// RC 0.60.0
const result = await fetch(`${ this.sdk.client.host }/api/v1/settings.public?query={"_id":{"$in":${ settingsParams }}}`).then(response => response.json());

View File

@ -12,8 +12,8 @@ import * as actions from '../actions';
import {
serverFailure, selectServerRequest, selectServerSuccess, selectServerFailure
} from '../actions/server';
import { setUser } from '../actions/login';
import { clearSettings } from '../actions/settings';
import { setUser } from '../actions/login';
import RocketChat from '../lib/rocketchat';
import database from '../lib/database';
import log, { logServerVersion } from '../utils/log';
@ -98,9 +98,8 @@ const handleSelectServer = function* handleSelectServer({ server, version, fetch
const basicAuth = yield RNUserDefaults.get(`${ BASIC_AUTH_KEY }-${ server }`);
setBasicAuth(basicAuth);
yield put(clearSettings());
if (user) {
yield put(clearSettings());
yield RocketChat.connect({ server, user, logoutOnError: true });
yield put(setUser(user));
yield put(actions.appStart('inside'));