From f6cc86d75af8e8ad0bfb9b2512dbeee47aa2d809 Mon Sep 17 00:00:00 2001 From: viktorstrate Date: Thu, 30 Sep 2021 16:05:23 +0200 Subject: [PATCH] Fix bug --- api/graphql/models/actions/share_token_actions.go | 9 ++++++++- api/graphql/models/actions/share_token_actions_test.go | 6 +++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/api/graphql/models/actions/share_token_actions.go b/api/graphql/models/actions/share_token_actions.go index 09213282..7cad542d 100644 --- a/api/graphql/models/actions/share_token_actions.go +++ b/api/graphql/models/actions/share_token_actions.go @@ -145,8 +145,15 @@ func hashSharePassword(password *string) (*string, error) { func getUserToken(db *gorm.DB, userID int, tokenValue string) (*models.ShareToken, error) { + var query string + if db.Dialector.Name() == "postgres" { + query = "\"Owner\".id = ? OR \"Owner\".admin = TRUE" + } else { + query = "Owner.id = ? OR Owner.admin = TRUE" + } + var token models.ShareToken - err := db.Where("share_tokens.value = ?", tokenValue).Joins("Owner").Where("Owner.id = ? OR Owner.admin = TRUE", userID).First(&token).Error + err := db.Where("share_tokens.value = ?", tokenValue).Joins("Owner").Where(query, userID).First(&token).Error if err != nil { return nil, errors.Wrap(err, "failed to get user share token from database") diff --git a/api/graphql/models/actions/share_token_actions_test.go b/api/graphql/models/actions/share_token_actions_test.go index 6b77e9e5..3cef1664 100644 --- a/api/graphql/models/actions/share_token_actions_test.go +++ b/api/graphql/models/actions/share_token_actions_test.go @@ -69,19 +69,19 @@ func TestShareToken(t *testing.T) { assert.NotNil(t, share) assert.NotEmpty(t, share.Value) - assert.NotNil(t, share.AlbumID) + assert.Equal(t, rootAlbum.ID, *share.AlbumID) assert.Nil(t, share.MediaID) }) t.Run("Add media share", func(t *testing.T) { - share, err := actions.AddMediaShare(db, user, rootAlbum.ID, &expireTime, &sharePassword) + share, err := actions.AddMediaShare(db, user, media[0].ID, &expireTime, &sharePassword) mediaShare = share assert.NoError(t, err) assert.NotNil(t, share) assert.NotEmpty(t, share.Value) - assert.NotNil(t, share.MediaID) + assert.Equal(t, media[0].ID, *share.MediaID) assert.Nil(t, share.AlbumID) })