2018-11-26 21:17:33 +01:00
|
|
|
// Vikunja is a todo-list application to facilitate your life.
|
|
|
|
// Copyright 2018 Vikunja and contributors. All rights reserved.
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
2018-07-18 22:06:29 +02:00
|
|
|
package models
|
|
|
|
|
2018-12-01 00:26:56 +01:00
|
|
|
import "code.vikunja.io/web"
|
|
|
|
|
2018-07-21 15:28:09 +02:00
|
|
|
// ReadAll implements the method to read all teams of a namespace
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Summary Get teams on a namespace
|
|
|
|
// @Description Returns a namespace with all teams which have access on a given namespace.
|
|
|
|
// @tags sharing
|
|
|
|
// @Accept json
|
|
|
|
// @Produce json
|
|
|
|
// @Param id path int true "Namespace ID"
|
|
|
|
// @Param p query int false "The page number. Used for pagination. If not provided, the first page of results is returned."
|
|
|
|
// @Param s query string false "Search teams by its name."
|
2019-01-03 23:22:06 +01:00
|
|
|
// @Security JWTKeyAuth
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Success 200 {array} models.TeamWithRight "The teams with the right they have."
|
2018-12-01 02:59:17 +01:00
|
|
|
// @Failure 403 {object} code.vikunja.io/web.HTTPError "No right to see the namespace."
|
2018-11-12 16:46:35 +01:00
|
|
|
// @Failure 500 {object} models.Message "Internal error"
|
|
|
|
// @Router /namespaces/{id}/teams [get]
|
2018-12-01 00:26:56 +01:00
|
|
|
func (tn *TeamNamespace) ReadAll(search string, a web.Auth, page int) (interface{}, error) {
|
2018-07-18 22:06:29 +02:00
|
|
|
// Check if the user can read the namespace
|
2019-04-01 21:48:48 +02:00
|
|
|
n := Namespace{ID: tn.NamespaceID}
|
2019-06-28 10:21:48 +02:00
|
|
|
canRead, err := n.CanRead(a)
|
2019-03-24 13:35:50 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if !canRead {
|
2019-06-28 10:21:48 +02:00
|
|
|
return nil, ErrNeedToHaveNamespaceReadAccess{NamespaceID: tn.NamespaceID, UserID: a.GetID()}
|
2018-07-18 22:06:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get the teams
|
2018-11-12 16:46:35 +01:00
|
|
|
all := []*TeamWithRight{}
|
2018-07-18 22:06:29 +02:00
|
|
|
|
2018-09-18 08:17:18 +02:00
|
|
|
err = x.Table("teams").
|
2018-07-18 22:06:29 +02:00
|
|
|
Join("INNER", "team_namespaces", "team_id = teams.id").
|
|
|
|
Where("team_namespaces.namespace_id = ?", tn.NamespaceID).
|
2018-11-09 11:30:17 +01:00
|
|
|
Limit(getLimitFromPageIndex(page)).
|
2018-11-09 18:33:06 +01:00
|
|
|
Where("teams.name LIKE ?", "%"+search+"%").
|
2018-07-18 22:06:29 +02:00
|
|
|
Find(&all)
|
|
|
|
|
|
|
|
return all, err
|
2018-07-21 15:28:09 +02:00
|
|
|
}
|