Support empty application in page

This commit is contained in:
Yang Luo 2023-05-16 22:17:39 +08:00
parent 3d9b305bbb
commit 0b5ecca5c8
6 changed files with 21 additions and 11 deletions

View File

@ -326,6 +326,12 @@ func UpdateApplication(id string, application *Application) bool {
}
func AddApplication(application *Application) bool {
if application.Owner == "" {
application.Owner = "admin"
}
if application.Organization == "" {
application.Organization = "built-in"
}
if application.ClientId == "" {
application.ClientId = util.GenerateClientId()
}

View File

@ -790,7 +790,7 @@ class ApplicationEditPage extends React.Component {
let signUpUrl = `/signup/${this.state.application.name}`;
let redirectUri;
if (this.state.application.redirectUris.length !== 0) {
if (this.state.application.redirectUris?.length > 0) {
redirectUri = this.state.application.redirectUris[0];
} else {
redirectUri = "\"ERROR: You must specify at least one Redirect URL in 'Redirect URLs'\"";

View File

@ -175,7 +175,7 @@ class ApplicationListPage extends BaseListPage {
// width: '600px',
render: (text, record, index) => {
const providers = text;
if (providers.length === 0) {
if (providers === null || providers.length === 0) {
return `(${i18next.t("general:empty")})`;
}

View File

@ -325,19 +325,19 @@ export function isSignupItemPrompted(signupItem) {
}
export function getAllPromptedProviderItems(application) {
return application.providers.filter(providerItem => isProviderPrompted(providerItem));
return application.providers?.filter(providerItem => isProviderPrompted(providerItem));
}
export function getAllPromptedSignupItems(application) {
return application.signupItems.filter(signupItem => isSignupItemPrompted(signupItem));
return application.signupItems?.filter(signupItem => isSignupItemPrompted(signupItem));
}
export function getSignupItem(application, itemName) {
const signupItems = application.signupItems?.filter(signupItem => signupItem.name === itemName);
if (signupItems.length === 0) {
return null;
if (signupItems?.length > 0) {
return signupItems[0];
}
return signupItems[0];
return null;
}
export function isValidPersonName(personName) {
@ -409,12 +409,12 @@ export function isAffiliationPrompted(application) {
export function hasPromptPage(application) {
const providerItems = getAllPromptedProviderItems(application);
if (providerItems.length !== 0) {
if (providerItems?.length > 0) {
return true;
}
const signupItems = getAllPromptedSignupItems(application);
if (signupItems.length !== 0) {
if (signupItems?.length > 0) {
return true;
}

View File

@ -559,7 +559,7 @@ class LoginPage extends React.Component {
</div>
<br />
{
application.providers.filter(providerItem => this.isProviderVisible(providerItem)).map(providerItem => {
application.providers?.filter(providerItem => this.isProviderVisible(providerItem)).map(providerItem => {
return ProviderButton.renderProviderLogo(providerItem.provider, application, 40, 10, "big", this.props.location);
})
}
@ -818,7 +818,7 @@ class LoginPage extends React.Component {
);
}
const visibleOAuthProviderItems = application.providers.filter(providerItem => this.isProviderVisible(providerItem));
const visibleOAuthProviderItems = (application.providers === null) ? [] : application.providers.filter(providerItem => this.isProviderVisible(providerItem));
if (this.props.preview !== "auto" && !application.enablePassword && visibleOAuthProviderItems.length === 1) {
Setting.goToLink(Provider.getAuthUrl(application, visibleOAuthProviderItems[0].provider, "signup"));
return (

View File

@ -60,6 +60,10 @@ class UrlTable extends React.Component {
}
renderTable(table) {
if (table === null) {
return null;
}
const columns = [
{
title: i18next.t("application:Redirect URL"),