mirror of
https://github.com/wisplite/raster.git
synced 2026-05-01 06:32:44 -05:00
refactor album access logic to handle guest users and improve state initialization in gallery components
This commit is contained in:
@@ -11,10 +11,6 @@ func RegisterAlbumRoutes(rg *gin.RouterGroup) {
|
||||
album := rg.Group("/albums")
|
||||
album.POST("/getAlbumsInParent", func(c *gin.Context) {
|
||||
accessToken := c.GetHeader("Authorization")
|
||||
if accessToken == "" {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "Unauthorized"})
|
||||
return
|
||||
}
|
||||
var request struct {
|
||||
ParentID string `json:"parentId"`
|
||||
}
|
||||
|
||||
@@ -14,17 +14,22 @@ import (
|
||||
func GetAlbumsInParent(parentID string, authToken string) ([]models.Album, error) {
|
||||
userID, err := ValidateAccessToken(authToken)
|
||||
if err != nil {
|
||||
return []models.Album{}, err
|
||||
if err != gorm.ErrRecordNotFound { //if record not found, assume user is guest
|
||||
return []models.Album{}, err
|
||||
}
|
||||
}
|
||||
accessLevel, err := CheckUserAlbumAccess(userID, parentID)
|
||||
if err != nil {
|
||||
return []models.Album{}, err
|
||||
if err != gorm.ErrRecordNotFound { //if record not found, assume user is guest
|
||||
return []models.Album{}, err
|
||||
}
|
||||
accessLevel = 1
|
||||
}
|
||||
if accessLevel < 1 {
|
||||
if accessLevel < 0 {
|
||||
return []models.Album{}, fmt.Errorf("user does not have permission to view albums in this parent")
|
||||
}
|
||||
albums := []models.Album{}
|
||||
result := db.GetDB().Where("private = ?", false).Where("parent_id = ?", parentID).Find(&albums)
|
||||
result := db.GetDB().Where("parent_id = ?", parentID).Find(&albums)
|
||||
if result.Error != nil {
|
||||
return []models.Album{}, result.Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user