Able to read current user's realm profile

This commit is contained in:
LittleSheep 2024-06-09 00:12:03 +08:00
parent 6d035c1147
commit ef055e1144
4 changed files with 24 additions and 7 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="dataSourceStorageLocal" created-in="GO-241.14494.238"> <component name="dataSourceStorageLocal" created-in="GO-241.17011.92">
<data-source name="hy_passport@localhost" uuid="74bcf3ef-a2b9-435b-b9e5-f32902a33b25"> <data-source name="hy_passport@localhost" uuid="74bcf3ef-a2b9-435b-b9e5-f32902a33b25">
<database-info product="PostgreSQL" version="16.2 (Homebrew)" jdbc-version="4.2" driver-name="PostgreSQL JDBC Driver" driver-version="42.6.0" dbms="POSTGRES" exact-version="16.2" exact-driver-version="42.6"> <database-info product="PostgreSQL" version="16.2 (Homebrew)" jdbc-version="4.2" driver-name="PostgreSQL JDBC Driver" driver-version="42.6.0" dbms="POSTGRES" exact-version="16.2" exact-driver-version="42.6">
<identifier-quote-string>&quot;</identifier-quote-string> <identifier-quote-string>&quot;</identifier-quote-string>

14
.idea/workspace.xml generated
View File

@ -4,9 +4,11 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":bug: Fix APNs pushes no sound (again)"> <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":fire: Remove ws connected does not push notify feature">
<change beforePath="$PROJECT_DIR$/.idea/dataSources.local.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/dataSources.local.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/services/notifications.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/services/notifications.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/server/realm_members_api.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/server/realm_members_api.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/server/startup.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/server/startup.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -108,8 +110,8 @@
<component name="SharedIndexes"> <component name="SharedIndexes">
<attachedChunks> <attachedChunks>
<set> <set>
<option value="bundled-gosdk-33c477a475b1-b97fc8a1e17c-org.jetbrains.plugins.go.sharedIndexes.bundled-GO-241.14494.238" /> <option value="bundled-gosdk-33c477a475b1-e0158606a674-org.jetbrains.plugins.go.sharedIndexes.bundled-GO-241.17011.92" />
<option value="bundled-js-predefined-1d06a55b98c1-74d2a5396914-JavaScript-GO-241.14494.238" /> <option value="bundled-js-predefined-1d06a55b98c1-0b3e54e931b4-JavaScript-GO-241.17011.92" />
</set> </set>
</attachedChunks> </attachedChunks>
</component> </component>
@ -141,7 +143,6 @@
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value=":bug: Bug fix on missing id in realm" />
<MESSAGE value=":bug: Bug fixes on realm missing member on creation" /> <MESSAGE value=":bug: Bug fixes on realm missing member on creation" />
<MESSAGE value=":bug: Dumb man make dumb mistake again" /> <MESSAGE value=":bug: Dumb man make dumb mistake again" />
<MESSAGE value=":bug: Fix new realm owner missing permissions" /> <MESSAGE value=":bug: Fix new realm owner missing permissions" />
@ -166,7 +167,8 @@
<MESSAGE value=":bug: Bug fixes on notification badges for APNs" /> <MESSAGE value=":bug: Bug fixes on notification badges for APNs" />
<MESSAGE value=":bug: Fix APNs pushes no sound" /> <MESSAGE value=":bug: Fix APNs pushes no sound" />
<MESSAGE value=":bug: Fix APNs pushes no sound (again)" /> <MESSAGE value=":bug: Fix APNs pushes no sound (again)" />
<option name="LAST_COMMIT_MESSAGE" value=":bug: Fix APNs pushes no sound (again)" /> <MESSAGE value=":fire: Remove ws connected does not push notify feature" />
<option name="LAST_COMMIT_MESSAGE" value=":fire: Remove ws connected does not push notify feature" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
<settings-migrated>true</settings-migrated> <settings-migrated>true</settings-migrated>

View File

@ -10,6 +10,7 @@ import (
func listRealmMembers(c *fiber.Ctx) error { func listRealmMembers(c *fiber.Ctx) error {
alias := c.Params("realm") alias := c.Params("realm")
if realm, err := services.GetRealmWithAlias(alias); err != nil { if realm, err := services.GetRealmWithAlias(alias); err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error()) return fiber.NewError(fiber.StatusNotFound, err.Error())
} else if members, err := services.ListRealmMember(realm.ID); err != nil { } else if members, err := services.ListRealmMember(realm.ID); err != nil {
@ -19,6 +20,19 @@ func listRealmMembers(c *fiber.Ctx) error {
} }
} }
func getMyRealmMember(c *fiber.Ctx) error {
alias := c.Params("realm")
user := c.Locals("principal").(models.Account)
if realm, err := services.GetRealmWithAlias(alias); err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
} else if member, err := services.GetRealmMember(user.ID, realm.ID); err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
} else {
return c.JSON(member)
}
}
func addRealmMember(c *fiber.Ctx) error { func addRealmMember(c *fiber.Ctx) error {
user := c.Locals("principal").(models.Account) user := c.Locals("principal").(models.Account)
alias := c.Params("realm") alias := c.Params("realm")

View File

@ -122,6 +122,7 @@ func NewServer() {
realms.Get("/me/available", authMiddleware, listAvailableRealm) realms.Get("/me/available", authMiddleware, listAvailableRealm)
realms.Get("/:realm", getRealm) realms.Get("/:realm", getRealm)
realms.Get("/:realm/members", listRealmMembers) realms.Get("/:realm/members", listRealmMembers)
realms.Get("/:realm/members/me", authMiddleware, getMyRealmMember)
realms.Post("/", authMiddleware, createRealm) realms.Post("/", authMiddleware, createRealm)
realms.Put("/:realmId", authMiddleware, editRealm) realms.Put("/:realmId", authMiddleware, editRealm)
realms.Delete("/:realmId", authMiddleware, deleteRealm) realms.Delete("/:realmId", authMiddleware, deleteRealm)