fix(fe/state_updater): initAll always returns error for unauthed users

This commit is contained in:
hexxa 2021-12-21 11:10:24 +08:00 committed by Hexxa
parent df801a9397
commit 87832ee1b2
2 changed files with 22 additions and 9 deletions

View file

@ -541,7 +541,7 @@ export class FilesPanel extends React.Component<Props, State, {}> {
<span onClick={() => this.select(item.name)} className="float-l"> <span onClick={() => this.select(item.name)} className="float-l">
{isSelected {isSelected
? getIcon("RiCheckboxFill", "1.8rem", "cyan0") ? getIcon("RiCheckboxFill", "1.8rem", "cyan0")
: getIcon("RiCheckboxBlankFill", "1.8rem", "grey1")} : getIcon("RiCheckboxBlankFill", "1.8rem", "black1")}
</span> </span>
</div> </div>
) : ( ) : (
@ -550,13 +550,13 @@ export class FilesPanel extends React.Component<Props, State, {}> {
onClick={() => this.toggleDetail(item.name)} onClick={() => this.toggleDetail(item.name)}
className="float-l" className="float-l"
> >
{getIcon("RiInformationFill", "1.8rem", "grey1")} {getIcon("RiInformationFill", "1.8rem", "black1")}
</span> </span>
<span onClick={() => this.select(item.name)} className="float-l"> <span onClick={() => this.select(item.name)} className="float-l">
{isSelected {isSelected
? getIcon("RiCheckboxFill", "1.8rem", "cyan0") ? getIcon("RiCheckboxFill", "1.8rem", "cyan0")
: getIcon("RiCheckboxBlankFill", "1.8rem", "grey1")} : getIcon("RiCheckboxBlankFill", "1.8rem", "black1")}
</span> </span>
</div> </div>
); );

View file

@ -413,8 +413,11 @@ export class Updater {
syncCwd = async (): Promise<string> => { syncCwd = async (): Promise<string> => {
if (this.props.filesInfo.dirPath.size !== 0) { if (this.props.filesInfo.dirPath.size !== 0) {
return this.setItems(this.props.filesInfo.dirPath); return this.setItems(this.props.filesInfo.dirPath);
} else if (this.props.login.authed) {
return this.setHomeItems();
} }
return this.setHomeItems(); // cwd will not be synced if the user is not authned and without sharing mode
return "";
}; };
initCwd = async (params: URLSearchParams): Promise<string> => { initCwd = async (params: URLSearchParams): Promise<string> => {
@ -445,18 +448,26 @@ export class Updater {
return isAuthedStatus; return isAuthedStatus;
} }
const getCapStatus = await this.getCaptchaID();
if (getCapStatus !== "") {
return getCapStatus;
}
const selfStatuses = await Promise.all([this.self(), this.initCwd(params)]); const selfStatuses = await Promise.all([this.self(), this.initCwd(params)]);
if (selfStatuses.join("") !== "") { if (selfStatuses.join("") !== "") {
return selfStatuses.join(";"); return selfStatuses.join(";");
} }
const getCapStatus = await this.getCaptchaID();
if (getCapStatus !== "") {
return getCapStatus;
}
this.initUITree(); this.initUITree();
const isInSharingMode = this.props.ui.control.controls.get(sharingCtrl);
if (
this.props.login.userRole === roleVisitor &&
isInSharingMode !== ctrlOn
) {
return this.initStateForVisitor();
}
const cwdStatus = await this.syncCwd(); const cwdStatus = await this.syncCwd();
if (cwdStatus !== "") { if (cwdStatus !== "") {
return cwdStatus; return cwdStatus;
@ -472,6 +483,7 @@ export class Updater {
if (this.props.login.userRole === roleAdmin) { if (this.props.login.userRole === roleAdmin) {
return this.initStateForAdmin(); return this.initStateForAdmin();
} else if (this.props.login.userRole === roleVisitor) { } else if (this.props.login.userRole === roleVisitor) {
// visitor under sharing mode
return this.initStateForVisitor(); return this.initStateForVisitor();
} }
return this.initStateForAuthedUser(); return this.initStateForAuthedUser();
@ -514,6 +526,7 @@ export class Updater {
this.props.login.preferences = resp.data.preferences; this.props.login.preferences = resp.data.preferences;
return ""; return "";
} else if (resp.status === 401) { } else if (resp.status === 401) {
this.resetUser();
return ""; return "";
} }