Share: Ensure that shares are always loaded in the user entity model
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
e6b1a28bcf
commit
3c0f1f37ad
|
@ -312,8 +312,9 @@ func (m *User) Deleted() bool {
|
||||||
|
|
||||||
// LoadRelated loads related settings and details.
|
// LoadRelated loads related settings and details.
|
||||||
func (m *User) LoadRelated() *User {
|
func (m *User) LoadRelated() *User {
|
||||||
m.Settings()
|
|
||||||
m.Details()
|
m.Details()
|
||||||
|
m.Settings()
|
||||||
|
m.RefreshShares()
|
||||||
|
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
@ -948,7 +949,7 @@ func (m *User) RefreshShares() *User {
|
||||||
|
|
||||||
// NoShares checks if the user has no shares yet.
|
// NoShares checks if the user has no shares yet.
|
||||||
func (m *User) NoShares() bool {
|
func (m *User) NoShares() bool {
|
||||||
if !m.IsRegistered() {
|
if m.NotRegistered() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -962,23 +963,17 @@ func (m *User) HasShares() bool {
|
||||||
|
|
||||||
// HasShare if a uid was shared with the user.
|
// HasShare if a uid was shared with the user.
|
||||||
func (m *User) HasShare(uid string) bool {
|
func (m *User) HasShare(uid string) bool {
|
||||||
if !m.IsRegistered() {
|
if m.NotRegistered() || m.NoShares() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check cashed list of user shares.
|
// Check if the share list contains the specified UID.
|
||||||
if m.UserShares.Contains(uid) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Refresh cache and try again if not found.
|
|
||||||
m.RefreshShares()
|
|
||||||
return m.UserShares.Contains(uid)
|
return m.UserShares.Contains(uid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SharedUIDs returns shared entity UIDs.
|
// SharedUIDs returns shared entity UIDs.
|
||||||
func (m *User) SharedUIDs() UIDs {
|
func (m *User) SharedUIDs() UIDs {
|
||||||
if m.IsRegistered() && m.UserShares.Empty() {
|
if m.IsRegistered() && m.NoShares() {
|
||||||
m.RefreshShares()
|
m.RefreshShares()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1773,8 +1773,6 @@ func TestUser_HasShares(t *testing.T) {
|
||||||
})
|
})
|
||||||
t.Run("Alice", func(t *testing.T) {
|
t.Run("Alice", func(t *testing.T) {
|
||||||
m := FindLocalUser("alice")
|
m := FindLocalUser("alice")
|
||||||
assert.False(t, m.HasShares())
|
|
||||||
m.RefreshShares()
|
|
||||||
assert.True(t, m.HasShares())
|
assert.True(t, m.HasShares())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue