Fixed getting all lists of one namespace
This commit is contained in:
@ -241,3 +241,21 @@ func IsErrNeedToBeNamespaceOwner(err error) bool {
|
||||
func (err ErrNeedToBeNamespaceOwner) Error() string {
|
||||
return fmt.Sprintf("You need to be namespace owner to do that [NamespaceID: %d, UserID: %d]", err.NamespaceID, err.UserID)
|
||||
}
|
||||
|
||||
// ErrUserDoesNotHaveAccessToNamespace represents an error, where the user is not the owner of that namespace (used i.e. when deleting a namespace)
|
||||
type ErrUserDoesNotHaveAccessToNamespace struct {
|
||||
NamespaceID int64
|
||||
UserID int64
|
||||
}
|
||||
|
||||
// IsErrUserDoesNotHaveAccessToNamespace checks if an error is a ErrNamespaceDoesNotExist.
|
||||
func IsErrUserDoesNotHaveAccessToNamespace(err error) bool {
|
||||
_, ok := err.(ErrUserDoesNotHaveAccessToNamespace)
|
||||
return ok
|
||||
}
|
||||
|
||||
func (err ErrUserDoesNotHaveAccessToNamespace) Error() string {
|
||||
return fmt.Sprintf("You need to be namespace owner to do that [NamespaceID: %d, UserID: %d]", err.NamespaceID, err.UserID)
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,12 +10,11 @@ func CreateOrUpdateListItem(item *ListItem) (newItem *ListItem, err error) {
|
||||
}
|
||||
|
||||
// Check if the user exists
|
||||
user, _, err := GetUserByID(item.CreatedBy.ID)
|
||||
item.CreatedBy, _, err = GetUserByID(item.CreatedBy.ID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
item.CreatedByID = item.CreatedBy.ID
|
||||
item.CreatedBy = user
|
||||
|
||||
// TODO: Check if the user has the right to add/update an item to that list
|
||||
|
||||
|
@ -65,10 +65,6 @@ func GetListsByUser(user *User) (lists []*List, err error) {
|
||||
}
|
||||
|
||||
func GetListsByNamespaceID(nID int64) (lists []*List, err error) {
|
||||
exists, err := x.Where("namespace_id = ?", nID).Get(lists)
|
||||
if !exists {
|
||||
return lists, ErrNamespaceDoesNotExist{}
|
||||
}
|
||||
|
||||
return
|
||||
err = x.Where("namespace_id = ?", nID).Find(&lists)
|
||||
return lists, err
|
||||
}
|
||||
|
@ -47,15 +47,15 @@ func (user *User) IsNamespaceAdmin(namespace *Namespace) (ok bool, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (user *User) HasNamespaceAccess(namespace *Namespace) (has bool, err error) {
|
||||
func (user *User) HasNamespaceAccess(namespace *Namespace) (err error) {
|
||||
// Owners always have access
|
||||
if user.ID == namespace.Owner.ID {
|
||||
return true, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// Check if the user is in a team which has access to the namespace
|
||||
|
||||
return
|
||||
return ErrUserDoesNotHaveAccessToNamespace{UserID:user.ID, NamespaceID:namespace.ID}
|
||||
}
|
||||
|
||||
func GetNamespaceByID(id int64) (namespace Namespace, err error) {
|
||||
|
Reference in New Issue
Block a user