implemented read all method for namespace teams
This commit is contained in:
parent
6618874441
commit
935c99be45
3 changed files with 45 additions and 0 deletions
|
@ -354,6 +354,22 @@ func (err ErrNeedToBeNamespaceAdmin) Error() string {
|
||||||
return fmt.Sprintf("You need to be namespace owner to do that [NamespaceID: %d, UserID: %d]", err.NamespaceID, err.UserID)
|
return fmt.Sprintf("You need to be namespace owner to do that [NamespaceID: %d, UserID: %d]", err.NamespaceID, err.UserID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrNeedToHaveNamespaceReadAccess represents an error, where the user is not the owner of that namespace (used i.e. when deleting a namespace)
|
||||||
|
type ErrNeedToHaveNamespaceReadAccess struct {
|
||||||
|
NamespaceID int64
|
||||||
|
UserID int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsErrNeedToHaveNamespaceReadAccess checks if an error is a ErrNamespaceDoesNotExist.
|
||||||
|
func IsErrNeedToHaveNamespaceReadAccess(err error) bool {
|
||||||
|
_, ok := err.(ErrNeedToHaveNamespaceReadAccess)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err ErrNeedToHaveNamespaceReadAccess) Error() string {
|
||||||
|
return fmt.Sprintf("You need to be namespace owner to do that [NamespaceID: %d, UserID: %d]", err.NamespaceID, err.UserID)
|
||||||
|
}
|
||||||
|
|
||||||
// ============
|
// ============
|
||||||
// Team errors
|
// Team errors
|
||||||
// ============
|
// ============
|
||||||
|
|
23
models/team_namespace_readall.go
Normal file
23
models/team_namespace_readall.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
func (tn *TeamNamespace) ReadAll(user *User) (interface{}, error) {
|
||||||
|
// Check if the user can read the namespace
|
||||||
|
n, err := GetNamespaceByID(tn.NamespaceID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if !n.CanRead(user) {
|
||||||
|
return nil, ErrNeedToHaveNamespaceReadAccess{NamespaceID:tn.NamespaceID, UserID:user.ID}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the teams
|
||||||
|
all := []*Team{}
|
||||||
|
|
||||||
|
err = x.Select("teams.*").
|
||||||
|
Table("teams").
|
||||||
|
Join("INNER", "team_namespaces", "team_id = teams.id").
|
||||||
|
Where("team_namespaces.namespace_id = ?", tn.NamespaceID).
|
||||||
|
Find(&all)
|
||||||
|
|
||||||
|
return all, err
|
||||||
|
}
|
|
@ -14,6 +14,12 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
||||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the object & bind params to struct
|
||||||
|
if err := ParamBinder(c.CObject, ctx); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.")
|
||||||
|
}
|
||||||
|
|
||||||
lists, err := c.CObject.ReadAll(¤tUser)
|
lists, err := c.CObject.ReadAll(¤tUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
|
Loading…
Reference in a new issue