func (hooks UserResourceHooks) AllowUpdate(res kit.Resource, obj kit.Model, old kit.Model, user kit.User) bool { if user == nil { return false } if user.HasRole("admin") || user.HasPermission("users.update") { return true } return obj.GetId() == user.GetId() }
func (UserResource) AllowDelete(res kit.Resource, obj kit.Model, user kit.User) bool { if user == nil { return false } if obj.(kit.UserModel).GetUserId() == user.GetId() { return true } return user.HasRole("admin") || user.HasPermission(res.Collection()+".delete") }
func (UserResource) AllowFind(res kit.Resource, model kit.Model, user kit.User) bool { if user == nil { return false } if model.(kit.UserModel).GetUserId() == user.GetId() { return true } return user.HasRole("admin") }
func (PageResource) AllowFind(res kit.Resource, obj kit.Model, user kit.User) bool { if p, ok := obj.(*PageIntId); ok && p.Published { return true } else if p, ok := obj.(*PageStrId); ok && p.Published { return true } u := obj.(kit.UserModel) return user != nil && (u.GetUserId() == user.GetId() || user.HasRole("admin")) }
// Restrict querying to admins. func (RoleResourceHooks) AllowFind(res kit.Resource, model kit.Model, user kit.User) bool { return user != nil && user.HasRole("admin") }
func (AdminResource) AllowDelete(res kit.Resource, obj kit.Model, user kit.User) bool { return user != nil && (user.HasRole("admin") || user.HasPermission(res.Collection()+".delete")) }