From 0e41568f620058e824177957e8b5edb8acde3891 Mon Sep 17 00:00:00 2001 From: Gucheng Wang Date: Mon, 25 Apr 2022 13:27:26 +0800 Subject: [PATCH] Add apps to homepage. --- authz/authz.go | 1 + web/src/Setting.js | 5 +++++ web/src/basic/HomePage.js | 44 +++++++++++++++++++++++++++---------- web/src/basic/SingleCard.js | 4 ++-- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/authz/authz.go b/authz/authz.go index d0dab756..a414e5ae 100644 --- a/authz/authz.go +++ b/authz/authz.go @@ -82,6 +82,7 @@ p, *, *, GET, /api/get-account, *, * p, *, *, GET, /api/userinfo, *, * p, *, *, *, /api/login/oauth, *, * p, *, *, GET, /api/get-application, *, * +p, *, *, GET, /api/get-applications, *, * p, *, *, GET, /api/get-user, *, * p, *, *, GET, /api/get-user-application, *, * p, *, *, GET, /api/get-resources, *, * diff --git a/web/src/Setting.js b/web/src/Setting.js index dd618a3b..b7db2427 100644 --- a/web/src/Setting.js +++ b/web/src/Setting.js @@ -277,6 +277,11 @@ export function goToLink(link) { } export function goToLinkSoft(ths, link) { + if (link.startsWith("http")) { + openLink(link); + return; + } + ths.props.history.push(link); } diff --git a/web/src/basic/HomePage.js b/web/src/basic/HomePage.js index 6c897b8d..e7107ff9 100644 --- a/web/src/basic/HomePage.js +++ b/web/src/basic/HomePage.js @@ -14,6 +14,7 @@ import React from "react"; import {Card, Col, Row} from "antd"; +import * as ApplicationBackend from "../backend/ApplicationBackend"; import * as Setting from "../Setting"; import SingleCard from "./SingleCard"; import i18next from "i18next"; @@ -23,9 +24,23 @@ class HomePage extends React.Component { super(props); this.state = { classes: props, + applications: null, }; } + UNSAFE_componentWillMount() { + this.getApplicationsByOrganization(this.props.account.owner); + } + + getApplicationsByOrganization(organizationName) { + ApplicationBackend.getApplicationsByOrganization("admin", organizationName) + .then((res) => { + this.setState({ + applications: (res.msg === undefined) ? res : [], + }); + }); + } + getItems() { let items = []; if (Setting.isAdminUser(this.props.account)) { @@ -35,25 +50,32 @@ class HomePage extends React.Component { {link: "/providers", name: i18next.t("general:Providers"), organizer: i18next.t("general:OAuth providers")}, {link: "/applications", name: i18next.t("general:Applications"), organizer: i18next.t("general:Applications that require authentication")}, ]; - } else { - items = [ - {link: "/account", name: i18next.t("account:My Account"), organizer: i18next.t("account:Settings for your account")}, - ]; - } - for (let i = 0; i < items.length; i ++) { - let filename = items[i].link; - if (filename === "/account") { - filename = "/users"; + for (let i = 0; i < items.length; i ++) { + let filename = items[i].link; + if (filename === "/account") { + filename = "/users"; + } + items[i].logo = `https://cdn.casbin.com/static/img${filename}.png`; + items[i].createdTime = ""; } - items[i].logo = `https://cdn.casbin.com/static/img${filename}.png`; - items[i].createdTime = ""; + } else { + this.state.applications.forEach(application => { + console.log(application) + items.push({ + link: application.homepageUrl, name: application.displayName, organizer: application.description, logo: application.logo, createdTime: "", + }); + }); } return items } renderCards() { + if (this.state.applications === null) { + return null; + } + const items = this.getItems(); if (Setting.isMobile()) { diff --git a/web/src/basic/SingleCard.js b/web/src/basic/SingleCard.js index fedc0e91..e16390ee 100644 --- a/web/src/basic/SingleCard.js +++ b/web/src/basic/SingleCard.js @@ -51,10 +51,10 @@ class SingleCard extends React.Component { + logo } onClick={() => Setting.goToLinkSoft(this, link)} - style={isSingle ? {width: "320px"} : null} + style={isSingle ? {width: "320px"} : {width: "100%"}} >