🐛 Fix permissions in groups
This commit is contained in:
parent
7737d9fd08
commit
c458123d9e
11
.idea/workspace.xml
generated
11
.idea/workspace.xml
generated
@ -4,10 +4,11 @@
|
||||
<option name="autoReloadType" value="ALL" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Account groups">
|
||||
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Default user group">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/internal/services/accounts.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/accounts.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/settings.toml" beforeDir="false" afterPath="$PROJECT_DIR$/settings.toml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/accounts_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/accounts_api.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/internal/server/api/userinfo_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/server/api/userinfo_api.go" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/pkg/internal/services/account_groups.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/account_groups.go" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@ -154,7 +155,6 @@
|
||||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value=":bug: Fix API mapping issue" />
|
||||
<MESSAGE value=":recycle: Improve notify API" />
|
||||
<MESSAGE value=":sparkles: Reset password APIs" />
|
||||
<MESSAGE value=":sparkles: Password reset & user lookup API" />
|
||||
@ -179,7 +179,8 @@
|
||||
<MESSAGE value=":recycle: Use dealer postman instead of built-in feature to deliver email and notify" />
|
||||
<MESSAGE value=":bug: Fix push notification to wrong person" />
|
||||
<MESSAGE value=":sparkles: Account groups" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: Account groups" />
|
||||
<MESSAGE value=":sparkles: Default user group" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: Default user group" />
|
||||
</component>
|
||||
<component name="VgoProject">
|
||||
<settings-migrated>true</settings-migrated>
|
||||
|
@ -43,6 +43,8 @@ func getUserinfo(c *fiber.Ctx) error {
|
||||
Preload("Badges").
|
||||
First(&data).Error; err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
} else {
|
||||
data.PermNodes = c.Locals("permissions").(map[string]any)
|
||||
}
|
||||
|
||||
var resp fiber.Map
|
||||
|
@ -1,8 +1,10 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
@ -19,5 +21,17 @@ func getOtherUserinfo(c *fiber.Ctx) error {
|
||||
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||
}
|
||||
|
||||
groups, err := services.GetUserAccountGroup(account)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, fmt.Sprintf("unable to get account groups: %v", err))
|
||||
}
|
||||
for _, group := range groups {
|
||||
for k, v := range group.PermNodes {
|
||||
if _, ok := account.PermNodes[k]; !ok {
|
||||
account.PermNodes[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return c.JSON(account)
|
||||
}
|
||||
|
@ -15,8 +15,8 @@ func GetUserAccountGroup(user models.Account) ([]models.AccountGroup, error) {
|
||||
}
|
||||
|
||||
var groups []models.AccountGroup
|
||||
if err := database.C.Where("id IN ?", lo.Map(groups, func(item models.AccountGroup, index int) uint {
|
||||
return item.ID
|
||||
if err := database.C.Where("id IN ?", lo.Map(members, func(item models.AccountGroupMember, index int) uint {
|
||||
return item.GroupID
|
||||
})).Find(&groups).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user