Simplified condition building
continuous-integration/drone/push Build was killed Details

This commit is contained in:
konrad 2019-01-17 21:52:16 +01:00
parent 202d357890
commit 43f73c692d
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 19 additions and 22 deletions

View File

@ -92,30 +92,27 @@ func (l *List) checkListRight(user *User, rights ...ListRight) bool {
var conds []builder.Cond
for _, r := range rights {
// User conditions
conds = append(conds, builder.Or(
// If the list was shared directly with the user and the user has the right
builder.And(
builder.Eq{"ul.user_id": user.ID},
builder.Eq{"ul.right": r},
),
// If the namespace this list belongs to was shared directly with the user and the user has the right
builder.And(
builder.Eq{"un.user_id": user.ID},
builder.Eq{"un.right": r},
),
// If the list was shared directly with the user and the user has the right
conds = append(conds, builder.And(
builder.Eq{"ul.user_id": user.ID},
builder.Eq{"ul.right": r},
))
// If the namespace this list belongs to was shared directly with the user and the user has the right
conds = append(conds, builder.And(
builder.Eq{"un.user_id": user.ID},
builder.Eq{"un.right": r},
))
// Team rights
conds = append(conds, builder.Or(
// If the list was shared directly with the team and the team has the right
builder.And(
builder.Eq{"tm2.user_id": user.ID},
builder.Eq{"tl.right": r},
),
// If the namespace this list belongs to was shared directly with the team and the team has the right
builder.And(
builder.Eq{"tm.user_id": user.ID},
builder.Eq{"tn.right": r},
),
// If the list was shared directly with the team and the team has the right
conds = append(conds, builder.And(
builder.Eq{"tm2.user_id": user.ID},
builder.Eq{"tl.right": r},
))
// If the namespace this list belongs to was shared directly with the team and the team has the right
conds = append(conds, builder.And(
builder.Eq{"tm.user_id": user.ID},
builder.Eq{"tn.right": r},
))
}