Show logs to org admin

This commit is contained in:
Gucheng Wang 2022-09-18 16:16:45 +08:00
parent 6670450439
commit 084a5c3e6b
5 changed files with 37 additions and 14 deletions

View File

@ -89,6 +89,7 @@ p, *, *, GET, /api/get-organization-applications, *, *
p, *, *, GET, /api/get-user, *, *
p, *, *, GET, /api/get-user-application, *, *
p, *, *, GET, /api/get-resources, *, *
p, *, *, GET, /api/get-records, *, *
p, *, *, GET, /api/get-product, *, *
p, *, *, POST, /api/buy-product, *, *
p, *, *, GET, /api/get-payment, *, *

View File

@ -29,6 +29,11 @@ import (
// @Success 200 {object} object.Record The Response object
// @router /get-records [get]
func (c *ApiController) GetRecords() {
organization, ok := c.RequireAdmin()
if !ok {
return
}
limit := c.Input().Get("pageSize")
page := c.Input().Get("p")
field := c.Input().Get("field")
@ -40,8 +45,9 @@ func (c *ApiController) GetRecords() {
c.ServeJSON()
} else {
limit := util.ParseInt(limit)
paginator := pagination.SetPaginator(c.Ctx, limit, int64(object.GetRecordCount(field, value)))
records := object.GetPaginationRecords(paginator.Offset(), limit, field, value, sortField, sortOrder)
filterRecord := &object.Record{Organization: organization}
paginator := pagination.SetPaginator(c.Ctx, limit, int64(object.GetRecordCount(field, value, filterRecord)))
records := object.GetPaginationRecords(paginator.Offset(), limit, field, value, sortField, sortOrder, filterRecord)
c.ResponseOk(records, paginator.Nums())
}
}

View File

@ -90,6 +90,19 @@ func (c *ApiController) RequireSignedInUser() (*object.User, bool) {
return user, true
}
// RequireAdmin ...
func (c *ApiController) RequireAdmin() (string, bool) {
user, ok := c.RequireSignedInUser()
if !ok {
return "", false
}
if user.Owner == "built-in" {
return "", true
}
return user.Owner, true
}
func getInitScore() (int, error) {
return strconv.Atoi(conf.GetConfigString("initScore"))
}

View File

@ -101,9 +101,9 @@ func AddRecord(record *Record) bool {
return affected != 0
}
func GetRecordCount(field, value string) int {
func GetRecordCount(field, value string, filterRecord *Record) int {
session := GetSession("", -1, -1, field, value, "", "")
count, err := session.Count(&Record{})
count, err := session.Count(filterRecord)
if err != nil {
panic(err)
}
@ -121,10 +121,10 @@ func GetRecords() []*Record {
return records
}
func GetPaginationRecords(offset, limit int, field, value, sortField, sortOrder string) []*Record {
func GetPaginationRecords(offset, limit int, field, value, sortField, sortOrder string, filterRecord *Record) []*Record {
records := []*Record{}
session := GetSession("", offset, limit, field, value, sortField, sortOrder)
err := session.Find(&records)
err := session.Find(&records, filterRecord)
if err != nil {
panic(err)
}

View File

@ -432,7 +432,7 @@ class App extends Component {
);
}
if (Setting.isAdminUser(this.state.account)) {
if (Setting.isLocalAdminUser(this.state.account)) {
res.push(
<Menu.Item key="/resources">
<Link to="/resources">
@ -440,13 +440,6 @@ class App extends Component {
</Link>
</Menu.Item>
);
res.push(
<Menu.Item key="/tokens">
<Link to="/tokens">
{i18next.t("general:Tokens")}
</Link>
</Menu.Item>
);
res.push(
<Menu.Item key="/records">
<Link to="/records">
@ -454,6 +447,16 @@ class App extends Component {
</Link>
</Menu.Item>
);
}
if (Setting.isAdminUser(this.state.account)) {
res.push(
<Menu.Item key="/tokens">
<Link to="/tokens">
{i18next.t("general:Tokens")}
</Link>
</Menu.Item>
);
res.push(
<Menu.Item key="/webhooks">
<Link to="/webhooks">