feat: refactor code to use responseOK everywhere (#2111)

* refactor: use responseOK return frontend format json data

* revert handle error

* revert handle error
This commit is contained in:
Yaodong Yu 2023-07-23 09:49:16 +08:00 committed by GitHub
parent fc9528be43
commit a6f803aff1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 178 additions and 218 deletions

View File

@ -48,14 +48,11 @@ func (c *ApiController) GetApplications() {
} else { } else {
applications, err = object.GetOrganizationApplications(owner, organization) applications, err = object.GetOrganizationApplications(owner, organization)
} }
if err != nil { if err != nil {
c.ResponseError(err.Error()) c.ResponseError(err.Error())
return return
} }
c.ResponseOk(object.GetMaskedApplications(applications, userId))
c.Data["json"] = object.GetMaskedApplications(applications, userId)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetApplicationCount(owner, field, value) count, err := object.GetApplicationCount(owner, field, value)
@ -86,14 +83,14 @@ func (c *ApiController) GetApplications() {
func (c *ApiController) GetApplication() { func (c *ApiController) GetApplication() {
userId := c.GetSessionUsername() userId := c.GetSessionUsername()
id := c.Input().Get("id") id := c.Input().Get("id")
app, err := object.GetApplication(id) app, err := object.GetApplication(id)
if err != nil { if err != nil {
c.ResponseError(err.Error()) c.ResponseError(err.Error())
return return
} }
c.Data["json"] = object.GetMaskedApplication(app, userId) c.ResponseOk(object.GetMaskedApplication(app, userId))
c.ServeJSON()
} }
// GetUserApplication // GetUserApplication
@ -106,25 +103,24 @@ func (c *ApiController) GetApplication() {
func (c *ApiController) GetUserApplication() { func (c *ApiController) GetUserApplication() {
userId := c.GetSessionUsername() userId := c.GetSessionUsername()
id := c.Input().Get("id") id := c.Input().Get("id")
user, err := object.GetUser(id) user, err := object.GetUser(id)
if err != nil { if err != nil {
c.ResponseError(err.Error()) c.ResponseError(err.Error())
return return
} }
if user == nil { if user == nil {
c.ResponseError(fmt.Sprintf(c.T("general:The user: %s doesn't exist"), id)) c.ResponseError(fmt.Sprintf(c.T("general:The user: %s doesn't exist"), id))
return return
} }
app, err := object.GetApplicationByUser(user) application, err := object.GetApplicationByUser(user)
if err != nil { if err != nil {
c.ResponseError(err.Error()) c.ResponseError(err.Error())
return return
} }
c.Data["json"] = object.GetMaskedApplication(app, userId) c.ResponseOk(object.GetMaskedApplication(application, userId))
c.ServeJSON()
} }
// GetOrganizationApplications // GetOrganizationApplications
@ -157,8 +153,7 @@ func (c *ApiController) GetOrganizationApplications() {
return return
} }
c.Data["json"] = object.GetMaskedApplications(applications, userId) c.ResponseOk(object.GetMaskedApplications(applications, userId))
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)

View File

@ -45,8 +45,7 @@ func (c *ApiController) GetCerts() {
return return
} }
c.Data["json"] = maskedCerts c.ResponseOk(maskedCerts)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetCertCount(owner, field, value) count, err := object.GetCertCount(owner, field, value)
@ -87,8 +86,7 @@ func (c *ApiController) GetGlobleCerts() {
return return
} }
c.Data["json"] = maskedCerts c.ResponseOk(maskedCerts)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetGlobalCertsCount(field, value) count, err := object.GetGlobalCertsCount(field, value)
@ -123,8 +121,7 @@ func (c *ApiController) GetCert() {
return return
} }
c.Data["json"] = object.GetMaskedCert(cert) c.ResponseOk(object.GetMaskedCert(cert))
c.ServeJSON()
} }
// UpdateCert // UpdateCert

View File

@ -45,8 +45,7 @@ func (c *ApiController) GetChats() {
return return
} }
c.Data["json"] = maskedChats c.ResponseOk(maskedChats)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetChatCount(owner, field, value) count, err := object.GetChatCount(owner, field, value)
@ -82,8 +81,7 @@ func (c *ApiController) GetChat() {
return return
} }
c.Data["json"] = maskedChat c.ResponseOk(maskedChat)
c.ServeJSON()
} }
// UpdateChat // UpdateChat

View File

@ -82,9 +82,9 @@ func (c *ApiController) GetGroup() {
group, err := object.GetGroup(id) group, err := object.GetGroup(id)
if err != nil { if err != nil {
c.ResponseError(err.Error()) c.ResponseError(err.Error())
} else { return
c.ResponseOk(group)
} }
c.ResponseOk(group)
} }
// UpdateGroup // UpdateGroup

View File

@ -125,7 +125,12 @@ func (c *ApiController) GetLdap() {
} }
_, name := util.GetOwnerAndNameFromId(id) _, name := util.GetOwnerAndNameFromId(id)
c.ResponseOk(object.GetMaskedLdap(object.GetLdap(name))) ldap, err := object.GetLdap(name)
if err != nil {
c.ResponseError(err.Error())
return
}
c.ResponseOk(object.GetMaskedLdap(ldap))
} }
// AddLdap // AddLdap

View File

@ -57,8 +57,7 @@ func (c *ApiController) GetMessages() {
return return
} }
c.Data["json"] = object.GetMaskedMessages(messages) c.ResponseOk(object.GetMaskedMessages(messages))
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetMessageCount(owner, organization, field, value) count, err := object.GetMessageCount(owner, organization, field, value)
@ -94,8 +93,7 @@ func (c *ApiController) GetMessage() {
return return
} }
c.Data["json"] = object.GetMaskedMessage(message) c.ResponseOk(message)
c.ServeJSON()
} }
func (c *ApiController) ResponseErrorStream(errorText string) { func (c *ApiController) ResponseErrorStream(errorText string) {

View File

@ -45,8 +45,7 @@ func (c *ApiController) GetModels() {
return return
} }
c.Data["json"] = models c.ResponseOk(models)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetModelCount(owner, field, value) count, err := object.GetModelCount(owner, field, value)
@ -82,8 +81,7 @@ func (c *ApiController) GetModel() {
return return
} }
c.Data["json"] = model c.ResponseOk(model)
c.ServeJSON()
} }
// UpdateModel // UpdateModel

View File

@ -55,8 +55,7 @@ func (c *ApiController) GetOrganizations() {
return return
} }
c.Data["json"] = maskedOrganizations c.ResponseOk(maskedOrganizations)
c.ServeJSON()
} else { } else {
if !isGlobalAdmin { if !isGlobalAdmin {
maskedOrganizations, err := object.GetMaskedOrganizations(object.GetOrganizations(owner, c.getCurrentUser().Owner)) maskedOrganizations, err := object.GetMaskedOrganizations(object.GetOrganizations(owner, c.getCurrentUser().Owner))

View File

@ -46,8 +46,7 @@ func (c *ApiController) GetPayments() {
return return
} }
c.Data["json"] = payments c.ResponseOk(payments)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetPaymentCount(owner, organization, field, value) count, err := object.GetPaymentCount(owner, organization, field, value)
@ -106,8 +105,7 @@ func (c *ApiController) GetPayment() {
return return
} }
c.Data["json"] = payment c.ResponseOk(payment)
c.ServeJSON()
} }
// UpdatePayment // UpdatePayment

View File

@ -45,8 +45,7 @@ func (c *ApiController) GetPermissions() {
return return
} }
c.Data["json"] = permissions c.ResponseOk(permissions)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetPermissionCount(owner, field, value) count, err := object.GetPermissionCount(owner, field, value)
@ -85,7 +84,6 @@ func (c *ApiController) GetPermissionsBySubmitter() {
} }
c.ResponseOk(permissions, len(permissions)) c.ResponseOk(permissions, len(permissions))
return
} }
// GetPermissionsByRole // GetPermissionsByRole
@ -104,7 +102,6 @@ func (c *ApiController) GetPermissionsByRole() {
} }
c.ResponseOk(permissions, len(permissions)) c.ResponseOk(permissions, len(permissions))
return
} }
// GetPermission // GetPermission
@ -123,8 +120,7 @@ func (c *ApiController) GetPermission() {
return return
} }
c.Data["json"] = permission c.ResponseOk(permission)
c.ServeJSON()
} }
// UpdatePermission // UpdatePermission

View File

@ -45,8 +45,7 @@ func (c *ApiController) GetPlans() {
return return
} }
c.Data["json"] = plans c.ResponseOk(plans)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetPlanCount(owner, field, value) count, err := object.GetPlanCount(owner, field, value)

View File

@ -45,8 +45,7 @@ func (c *ApiController) GetPricings() {
return return
} }
c.Data["json"] = pricings c.ResponseOk(pricings)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetPricingCount(owner, field, value) count, err := object.GetPricingCount(owner, field, value)
@ -82,8 +81,7 @@ func (c *ApiController) GetPricing() {
return return
} }
c.Data["json"] = pricing c.ResponseOk(pricing)
c.ServeJSON()
} }
// UpdatePricing // UpdatePricing

View File

@ -46,8 +46,7 @@ func (c *ApiController) GetProducts() {
return return
} }
c.Data["json"] = products c.ResponseOk(products)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetProductCount(owner, field, value) count, err := object.GetProductCount(owner, field, value)

View File

@ -51,8 +51,7 @@ func (c *ApiController) GetRecords() {
return return
} }
c.Data["json"] = records c.ResponseOk(records)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
if c.IsGlobalAdmin() && organizationName != "" { if c.IsGlobalAdmin() && organizationName != "" {
@ -99,8 +98,7 @@ func (c *ApiController) GetRecordsByFilter() {
return return
} }
c.Data["json"] = records c.ResponseOk(records)
c.ServeJSON()
} }
// AddRecord // AddRecord

View File

@ -67,8 +67,7 @@ func (c *ApiController) GetResources() {
return return
} }
c.Data["json"] = resources c.ResponseOk(resources)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetResourceCount(owner, user, field, value) count, err := object.GetResourceCount(owner, user, field, value)
@ -104,8 +103,7 @@ func (c *ApiController) GetResource() {
return return
} }
c.Data["json"] = resource c.ResponseOk(resource)
c.ServeJSON()
} }
// UpdateResource // UpdateResource

View File

@ -45,8 +45,7 @@ func (c *ApiController) GetRoles() {
return return
} }
c.Data["json"] = roles c.ResponseOk(roles)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetRoleCount(owner, field, value) count, err := object.GetRoleCount(owner, field, value)
@ -82,8 +81,7 @@ func (c *ApiController) GetRole() {
return return
} }
c.Data["json"] = role c.ResponseOk(role)
c.ServeJSON()
} }
// UpdateRole // UpdateRole

View File

@ -45,8 +45,7 @@ func (c *ApiController) GetSessions() {
return return
} }
c.Data["json"] = sessions c.ResponseOk(sessions)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetSessionCount(owner, field, value) count, err := object.GetSessionCount(owner, field, value)
@ -81,8 +80,7 @@ func (c *ApiController) GetSingleSession() {
return return
} }
c.Data["json"] = session c.ResponseOk(session)
c.ServeJSON()
} }
// UpdateSession // UpdateSession
@ -161,7 +159,5 @@ func (c *ApiController) IsSessionDuplicated() {
return return
} }
c.Data["json"] = &Response{Status: "ok", Msg: "", Data: isUserSessionDuplicated} c.ResponseOk(isUserSessionDuplicated)
c.ServeJSON()
} }

View File

@ -45,8 +45,7 @@ func (c *ApiController) GetSubscriptions() {
return return
} }
c.Data["json"] = subscriptions c.ResponseOk(subscriptions)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetSubscriptionCount(owner, field, value) count, err := object.GetSubscriptionCount(owner, field, value)
@ -82,8 +81,7 @@ func (c *ApiController) GetSubscription() {
return return
} }
c.Data["json"] = subscription c.ResponseOk(subscription)
c.ServeJSON()
} }
// UpdateSubscription // UpdateSubscription

View File

@ -46,8 +46,7 @@ func (c *ApiController) GetSyncers() {
return return
} }
c.Data["json"] = organizationSyncers c.ResponseOk(organizationSyncers)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetSyncerCount(owner, organization, field, value) count, err := object.GetSyncerCount(owner, organization, field, value)
@ -83,8 +82,7 @@ func (c *ApiController) GetSyncer() {
return return
} }
c.Data["json"] = syncer c.ResponseOk(syncer)
c.ServeJSON()
} }
// UpdateSyncer // UpdateSyncer

View File

@ -47,8 +47,7 @@ func (c *ApiController) GetTokens() {
return return
} }
c.Data["json"] = token c.ResponseOk(token)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetTokenCount(owner, organization, field, value) count, err := object.GetTokenCount(owner, organization, field, value)
@ -83,8 +82,7 @@ func (c *ApiController) GetToken() {
return return
} }
c.Data["json"] = token c.ResponseOk(token)
c.ServeJSON()
} }
// UpdateToken // UpdateToken

View File

@ -45,8 +45,7 @@ func (c *ApiController) GetGlobalUsers() {
return return
} }
c.Data["json"] = maskedUsers c.ResponseOk(maskedUsers)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetGlobalUserCount(field, value) count, err := object.GetGlobalUserCount(field, value)
@ -106,8 +105,7 @@ func (c *ApiController) GetUsers() {
return return
} }
c.Data["json"] = maskedUsers c.ResponseOk(maskedUsers)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetUserCount(owner, field, value, groupName) count, err := object.GetUserCount(owner, field, value, groupName)
@ -215,8 +213,7 @@ func (c *ApiController) GetUser() {
return return
} }
c.Data["json"] = maskedUser c.ResponseOk(maskedUser)
c.ServeJSON()
} }
// UpdateUser // UpdateUser

View File

@ -46,8 +46,7 @@ func (c *ApiController) GetWebhooks() {
return return
} }
c.Data["json"] = webhooks c.ResponseOk(webhooks)
c.ServeJSON()
} else { } else {
limit := util.ParseInt(limit) limit := util.ParseInt(limit)
count, err := object.GetWebhookCount(owner, organization, field, value) count, err := object.GetWebhookCount(owner, organization, field, value)
@ -84,8 +83,7 @@ func (c *ApiController) GetWebhook() {
return return
} }
c.Data["json"] = webhook c.ResponseOk(webhook)
c.ServeJSON()
} }
// UpdateWebhook // UpdateWebhook

View File

@ -68,7 +68,7 @@ class AdapterEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }
@ -80,8 +80,9 @@ class AdapterEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
models: res, models: res.data,
}); });
}); });
} }

View File

@ -119,7 +119,7 @@ class ApplicationEditPage extends React.Component {
getApplication() { getApplication() {
ApplicationBackend.getApplication("admin", this.state.applicationName) ApplicationBackend.getApplication("admin", this.state.applicationName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@ -138,7 +138,7 @@ class ApplicationEditPage extends React.Component {
} }
this.setState({ this.setState({
application: res, application: res.data,
}); });
this.getCerts(res.organization); this.getCerts(res.organization);
@ -184,9 +184,9 @@ class ApplicationEditPage extends React.Component {
getSamlMetadata() { getSamlMetadata() {
ApplicationBackend.getSamlMetadata("admin", this.state.applicationName) ApplicationBackend.getSamlMetadata("admin", this.state.applicationName)
.then((res) => { .then((data) => {
this.setState({ this.setState({
samlMetadata: res, samlMetadata: data,
}); });
}); });
} }

View File

@ -45,7 +45,7 @@ class CertEditPage extends React.Component {
getCert() { getCert() {
CertBackend.getCert(this.state.owner, this.state.certName) CertBackend.getCert(this.state.owner, this.state.certName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@ -56,7 +56,7 @@ class CertEditPage extends React.Component {
} }
this.setState({ this.setState({
cert: res, cert: res.data,
}); });
}); });
} }
@ -65,7 +65,7 @@ class CertEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@ -41,7 +41,7 @@ class ChatEditPage extends React.Component {
getChat() { getChat() {
ChatBackend.getChat("admin", this.state.chatName) ChatBackend.getChat("admin", this.state.chatName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@ -51,7 +51,7 @@ class ChatEditPage extends React.Component {
return; return;
} }
this.setState({ this.setState({
chat: res, chat: res.data,
}); });
this.getUsers(res.organization); this.getUsers(res.organization);
@ -62,7 +62,7 @@ class ChatEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }
@ -76,7 +76,7 @@ class ChatEditPage extends React.Component {
} }
this.setState({ this.setState({
users: res, users: res.data,
}); });
}); });
} }

View File

@ -79,7 +79,8 @@ class ChatPage extends BaseListPage {
getMessages(chatName) { getMessages(chatName) {
MessageBackend.getChatMessages(chatName) MessageBackend.getChatMessages(chatName)
.then((messages) => { .then((res) => {
const messages = res.data;
this.setState({ this.setState({
messages: messages, messages: messages,
}); });
@ -229,7 +230,7 @@ class ChatPage extends BaseListPage {
</div> </div>
) )
} }
<ChatBox messages={this.state.messages} sendMessage={(text) => {this.sendMessage(text);}} account={this.props.account} /> <ChatBox messages={this.state.messages || []} sendMessage={(text) => {this.sendMessage(text);}} account={this.props.account} />
</div> </div>
</div> </div>
); );

View File

@ -79,7 +79,9 @@ class EntryPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
const themeData = res !== null ? Setting.getThemeData(res.organizationObj, res) : Conf.ThemeDefault;
const application = res.data;
const themeData = application !== null ? Setting.getThemeData(application.organizationObj, application) : Conf.ThemeDefault;
this.props.updataThemeData(themeData); this.props.updataThemeData(themeData);
}); });
}; };

View File

@ -67,7 +67,7 @@ class GroupEditPage extends React.Component {
.then((res) => { .then((res) => {
if (res.status === "ok") { if (res.status === "ok") {
this.setState({ this.setState({
organizations: res.data, organizations: res.data || [],
}); });
} }
}); });

View File

@ -55,7 +55,7 @@ class LdapEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@ -46,7 +46,7 @@ class MessageEditPage extends React.Component {
getMessage() { getMessage() {
MessageBackend.getMessage("admin", this.state.messageName) MessageBackend.getMessage("admin", this.state.messageName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@ -54,10 +54,10 @@ class MessageEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({
message: res,
});
this.setState({
message: res.data,
});
this.getUsers(res.organization); this.getUsers(res.organization);
}); });
} }
@ -66,7 +66,7 @@ class MessageEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }
@ -87,8 +87,9 @@ class MessageEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
users: res, users: res.data,
}); });
}); });
} }

View File

@ -48,7 +48,7 @@ class ModelEditPage extends React.Component {
getModel() { getModel() {
ModelBackend.getModel(this.state.organizationName, this.state.modelName) ModelBackend.getModel(this.state.organizationName, this.state.modelName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@ -59,7 +59,7 @@ class ModelEditPage extends React.Component {
} }
this.setState({ this.setState({
model: res, model: res.data,
}); });
}); });
} }
@ -68,7 +68,7 @@ class ModelEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@ -75,7 +75,7 @@ class OrganizationEditPage extends React.Component {
} }
this.setState({ this.setState({
applications: res, applications: res.data || [],
}); });
}); });
} }

View File

@ -41,14 +41,14 @@ class PaymentEditPage extends React.Component {
getPayment() { getPayment() {
PaymentBackend.getPayment("admin", this.state.paymentName) PaymentBackend.getPayment("admin", this.state.paymentName)
.then((payment) => { .then((res) => {
if (payment === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
this.setState({ this.setState({
payment: payment, payment: res.data,
}); });
Setting.scrollToDiv("invoice-area"); Setting.scrollToDiv("invoice-area");

View File

@ -50,7 +50,9 @@ class PermissionEditPage extends React.Component {
getPermission() { getPermission() {
PermissionBackend.getPermission(this.state.organizationName, this.state.permissionName) PermissionBackend.getPermission(this.state.organizationName, this.state.permissionName)
.then((res) => { .then((res) => {
if (res === null) { const permission = res.data;
if (permission === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@ -61,14 +63,14 @@ class PermissionEditPage extends React.Component {
} }
this.setState({ this.setState({
permission: res, permission: permission,
}); });
this.getUsers(res.owner); this.getUsers(permission.owner);
this.getRoles(res.owner); this.getRoles(permission.owner);
this.getModels(res.owner); this.getModels(permission.owner);
this.getResources(res.owner); this.getResources(permission.owner);
this.getModel(res.owner, res.model); this.getModel(permission.owner, permission.model);
}); });
} }
@ -76,7 +78,7 @@ class PermissionEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }
@ -88,8 +90,9 @@ class PermissionEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
users: res, users: res.data,
}); });
}); });
} }
@ -101,8 +104,9 @@ class PermissionEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
roles: res, roles: res.data,
}); });
}); });
} }
@ -114,21 +118,21 @@ class PermissionEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
models: res, models: res.data,
}); });
}); });
} }
getModel(organizationName, modelName) { getModel(organizationName, modelName) {
ModelBackend.getModel(organizationName, modelName) if (modelName === "") {
.then((res) => {
if (res.status === "error") {
Setting.showMessage("error", res.msg);
return; return;
} }
ModelBackend.getModel(organizationName, modelName)
.then((res) => {
this.setState({ this.setState({
model: res, model: res.data,
}); });
}); });
} }
@ -137,7 +141,7 @@ class PermissionEditPage extends React.Component {
ApplicationBackend.getApplicationsByOrganization("admin", organizationName) ApplicationBackend.getApplicationsByOrganization("admin", organizationName)
.then((res) => { .then((res) => {
this.setState({ this.setState({
resources: (res.msg === undefined) ? res : [], resources: res.data || [],
}); });
}); });
} }

View File

@ -68,8 +68,9 @@ class PlanEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
roles: res, roles: res.data,
}); });
}); });
} }
@ -81,8 +82,9 @@ class PlanEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
users: res, users: res.data,
}); });
}); });
} }
@ -91,7 +93,7 @@ class PlanEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@ -44,13 +44,12 @@ class PricingEditPage extends React.Component {
this.getPricing(); this.getPricing();
this.getOrganizations(); this.getOrganizations();
this.getApplicationsByOrganization(this.state.organizationName); this.getApplicationsByOrganization(this.state.organizationName);
this.getUserApplication();
} }
getPricing() { getPricing() {
PricingBackend.getPricing(this.state.organizationName, this.state.pricingName) PricingBackend.getPricing(this.state.organizationName, this.state.pricingName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@ -61,7 +60,7 @@ class PricingEditPage extends React.Component {
} }
this.setState({ this.setState({
pricing: res, pricing: res.data,
}); });
this.getPlans(res.owner); this.getPlans(res.owner);
}); });
@ -74,8 +73,9 @@ class PricingEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
plans: res, plans: res.data,
}); });
}); });
} }
@ -84,7 +84,16 @@ class PricingEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
});
});
}
getApplicationsByOrganization(organizationName) {
ApplicationBackend.getApplicationsByOrganization("admin", organizationName)
.then((res) => {
this.setState({
applications: res.data || [],
}); });
}); });
} }
@ -107,28 +116,6 @@ class PricingEditPage extends React.Component {
}); });
} }
getApplicationsByOrganization(organizationName) {
ApplicationBackend.getApplicationsByOrganization("admin", organizationName)
.then((res) => {
this.setState({
applications: (res.msg === undefined) ? res : [],
});
});
}
getUserApplication() {
ApplicationBackend.getUserApplication(this.state.organizationName, this.state.userName)
.then((res) => {
if (res.status === "error") {
Setting.showMessage("error", res.msg);
return;
}
this.setState({
application: res,
});
});
}
renderPricing() { renderPricing() {
return ( return (
<Card size="small" title={ <Card size="small" title={

View File

@ -48,7 +48,7 @@ class ProductBuyPage extends React.Component {
} }
this.setState({ this.setState({
product: res, product: res.data,
}); });
}); });
} }

View File

@ -62,7 +62,7 @@ class ProductEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@ -50,7 +50,7 @@ class ProviderEditPage extends React.Component {
getProvider() { getProvider() {
ProviderBackend.getProvider(this.state.owner, this.state.providerName) ProviderBackend.getProvider(this.state.owner, this.state.providerName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@ -72,7 +72,7 @@ class ProviderEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: res.msg === undefined ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@ -43,7 +43,7 @@ class RoleEditPage extends React.Component {
getRole() { getRole() {
RoleBackend.getRole(this.state.organizationName, this.state.roleName) RoleBackend.getRole(this.state.organizationName, this.state.roleName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@ -53,7 +53,7 @@ class RoleEditPage extends React.Component {
} }
this.setState({ this.setState({
role: res, role: res.data,
}); });
this.getUsers(res.owner); this.getUsers(res.owner);
@ -65,7 +65,7 @@ class RoleEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }
@ -77,8 +77,9 @@ class RoleEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
users: res, users: res.data,
}); });
}); });
} }
@ -90,8 +91,9 @@ class RoleEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
roles: res, roles: res.data,
}); });
}); });
} }

View File

@ -47,7 +47,7 @@ class SubscriptionEditPage extends React.Component {
getSubscription() { getSubscription() {
SubscriptionBackend.getSubscription(this.state.organizationName, this.state.subscriptionName) SubscriptionBackend.getSubscription(this.state.organizationName, this.state.subscriptionName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@ -58,7 +58,7 @@ class SubscriptionEditPage extends React.Component {
} }
this.setState({ this.setState({
subscription: res, subscription: res.data,
}); });
this.getUsers(res.owner); this.getUsers(res.owner);
@ -70,7 +70,7 @@ class SubscriptionEditPage extends React.Component {
PlanBackend.getPlans(organizationName) PlanBackend.getPlans(organizationName)
.then((res) => { .then((res) => {
this.setState({ this.setState({
planes: res, planes: res.data,
}); });
}); });
} }
@ -82,8 +82,9 @@ class SubscriptionEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({ this.setState({
users: res, users: res.data,
}); });
}); });
} }
@ -92,7 +93,7 @@ class SubscriptionEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@ -48,7 +48,7 @@ class SyncerEditPage extends React.Component {
getSyncer() { getSyncer() {
SyncerBackend.getSyncer("admin", this.state.syncerName) SyncerBackend.getSyncer("admin", this.state.syncerName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@ -59,7 +59,7 @@ class SyncerEditPage extends React.Component {
} }
this.setState({ this.setState({
syncer: res, syncer: res.data,
}); });
}); });
} }
@ -68,7 +68,7 @@ class SyncerEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@ -36,7 +36,7 @@ class TokenEditPage extends React.Component {
getToken() { getToken() {
TokenBackend.getToken("admin", this.state.tokenName) TokenBackend.getToken("admin", this.state.tokenName)
.then((res) => { .then((res) => {
if (res === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
@ -47,7 +47,7 @@ class TokenEditPage extends React.Component {
} }
this.setState({ this.setState({
token: res, token: res.data,
}); });
}); });
} }

View File

@ -75,19 +75,20 @@ class UserEditPage extends React.Component {
getUser() { getUser() {
UserBackend.getUser(this.state.organizationName, this.state.userName) UserBackend.getUser(this.state.organizationName, this.state.userName)
.then((data) => { .then((res) => {
if (data === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
if (data.status === null || data.status !== "error") { if (res.status === "error") {
this.setState({ Setting.showMessage("error", res.msg);
user: data, return;
multiFactorAuths: data?.multiFactorAuths ?? [],
});
} }
this.setState({ this.setState({
user: res.data,
multiFactorAuths: res.data?.multiFactorAuths ?? [],
loading: false, loading: false,
}); });
}); });
@ -108,7 +109,7 @@ class UserEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }
@ -117,7 +118,7 @@ class UserEditPage extends React.Component {
ApplicationBackend.getApplicationsByOrganization("admin", organizationName) ApplicationBackend.getApplicationsByOrganization("admin", organizationName)
.then((res) => { .then((res) => {
this.setState({ this.setState({
applications: (res.msg === undefined) ? res : [], applications: res.data || [],
}); });
}); });
} }
@ -129,12 +130,10 @@ class UserEditPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.setState({
application: res,
});
this.setState({ this.setState({
isGroupsVisible: res.organizationObj.accountItems?.some((item) => item.name === "Groups" && item.visible), application: res.data,
isGroupsVisible: res.data?.organizationObj.accountItems?.some((item) => item.name === "Groups" && item.visible),
}); });
}); });
} }

View File

@ -122,14 +122,14 @@ class WebhookEditPage extends React.Component {
getWebhook() { getWebhook() {
WebhookBackend.getWebhook("admin", this.state.webhookName) WebhookBackend.getWebhook("admin", this.state.webhookName)
.then((webhook) => { .then((res) => {
if (webhook === null) { if (res.data === null) {
this.props.history.push("/404"); this.props.history.push("/404");
return; return;
} }
this.setState({ this.setState({
webhook: webhook, webhook: res.data,
}); });
}); });
} }
@ -138,7 +138,7 @@ class WebhookEditPage extends React.Component {
OrganizationBackend.getOrganizations("admin") OrganizationBackend.getOrganizations("admin")
.then((res) => { .then((res) => {
this.setState({ this.setState({
organizations: (res.msg === undefined) ? res : [], organizations: res.data || [],
}); });
}); });
} }

View File

@ -68,7 +68,7 @@ class ForgetPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.onUpdateApplication(res); this.onUpdateApplication(res.data);
}); });
} }
getApplicationObj() { getApplicationObj() {

View File

@ -170,7 +170,7 @@ class LoginPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.onUpdateApplication(res); this.onUpdateApplication(res.data);
}); });
} else { } else {
OrganizationBackend.getDefaultApplication("admin", this.state.owner) OrganizationBackend.getDefaultApplication("admin", this.state.owner)

View File

@ -69,7 +69,7 @@ class MfaSetupPage extends React.Component {
return; return;
} }
this.setState({ this.setState({
application: res, application: res.data,
}); });
} else { } else {
Setting.showMessage("error", i18next.t("mfa:Failed to get application")); Setting.showMessage("error", i18next.t("mfa:Failed to get application"));

View File

@ -63,7 +63,7 @@ class PromptPage extends React.Component {
} }
this.setState({ this.setState({
user: res, user: res.data,
}); });
}); });
} }
@ -80,9 +80,9 @@ class PromptPage extends React.Component {
return; return;
} }
this.onUpdateApplication(res); this.onUpdateApplication(res.data);
this.setState({ this.setState({
application: res, application: res.data,
}); });
}); });
} }

View File

@ -48,9 +48,10 @@ class ResultPage extends React.Component {
Setting.showMessage("error", res.msg); Setting.showMessage("error", res.msg);
return; return;
} }
this.onUpdateApplication(res);
this.onUpdateApplication(res.data);
this.setState({ this.setState({
application: res, application: res.data,
}); });
}); });
} }

View File

@ -114,7 +114,7 @@ class SignupPage extends React.Component {
return; return;
} }
this.onUpdateApplication(res); this.onUpdateApplication(res.data);
}); });
} }

View File

@ -36,7 +36,7 @@ class HomePage extends React.Component {
ApplicationBackend.getApplicationsByOrganization("admin", organizationName) ApplicationBackend.getApplicationsByOrganization("admin", organizationName)
.then((res) => { .then((res) => {
this.setState({ this.setState({
applications: (res.msg === undefined) ? res : [], applications: res.data || [],
}); });
}); });
} }