mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-03 20:47:35 +03:00
Add referential integrity to player and playlist tables
This commit is contained in:
parent
c9bcb333ae
commit
94d88395e7
6 changed files with 142 additions and 5 deletions
|
@ -46,11 +46,19 @@ func (r *playerRepository) FindByName(client, userName string) (*model.Player, e
|
|||
|
||||
func (r *playerRepository) newRestSelect(options ...model.QueryOptions) SelectBuilder {
|
||||
s := r.newSelect(options...)
|
||||
return s.Where(r.addRestriction())
|
||||
}
|
||||
|
||||
func (r *playerRepository) addRestriction(sql ...Sqlizer) Sqlizer {
|
||||
s := And{}
|
||||
if len(sql) > 0 {
|
||||
s = append(s, sql[0])
|
||||
}
|
||||
u := loggedUser(r.ctx)
|
||||
if u.IsAdmin {
|
||||
return s
|
||||
}
|
||||
return s.Where(Eq{"user_name": u.UserName})
|
||||
return append(s, Eq{"user_name": u.UserName})
|
||||
}
|
||||
|
||||
func (r *playerRepository) Count(options ...rest.QueryOptions) (int64, error) {
|
||||
|
@ -109,7 +117,8 @@ func (r *playerRepository) Update(entity interface{}, cols ...string) error {
|
|||
}
|
||||
|
||||
func (r *playerRepository) Delete(id string) error {
|
||||
err := r.delete(And{Eq{"id": id}, Eq{"user_name": loggedUser(r.ctx).UserName}})
|
||||
filter := r.addRestriction(And{Eq{"id": id}})
|
||||
err := r.delete(filter)
|
||||
if err == model.ErrNotFound {
|
||||
return rest.ErrNotFound
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue