Migrate to new swagger docs generation (#18)
This commit is contained in:
@ -27,6 +27,18 @@ func GetListsByNamespaceID(nID int64) (lists []*List, err error) {
|
||||
}
|
||||
|
||||
// ReadAll gets all lists a user has access to
|
||||
// @Summary Get all lists a user has access to
|
||||
// @Description Returns all lists a user has access to.
|
||||
// @tags list
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @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 lists by title."
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {array} models.List "The lists"
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the list"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists [get]
|
||||
func (l *List) ReadAll(search string, u *User, page int) (interface{}, error) {
|
||||
lists, err := getRawListsForUser(search, u, page)
|
||||
if err != nil {
|
||||
@ -40,6 +52,17 @@ func (l *List) ReadAll(search string, u *User, page int) (interface{}, error) {
|
||||
}
|
||||
|
||||
// ReadOne gets one list by its ID
|
||||
// @Summary Gets one list
|
||||
// @Description Returns a list by its ID.
|
||||
// @tags list
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "List ID"
|
||||
// @Success 200 {object} models.List "The list"
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the list"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{id} [get]
|
||||
func (l *List) ReadOne() (err error) {
|
||||
err = l.GetSimpleByID()
|
||||
if err != nil {
|
||||
@ -155,21 +178,26 @@ func AddListDetails(lists []*List) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// ListTasksDummy is a dummy we use to be able to use the crud handler
|
||||
type ListTasksDummy struct {
|
||||
CRUDable
|
||||
Rights
|
||||
}
|
||||
|
||||
// ReadAll gets all tasks for a user
|
||||
func (lt *ListTasksDummy) ReadAll(search string, u *User, page int) (interface{}, error) {
|
||||
// @Summary Get tasks
|
||||
// @Description Returns all tasks on any list the user has access to.
|
||||
// @tags task
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @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 tasks by task text."
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {array} models.List "The tasks"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /tasks [get]
|
||||
func (lt *ListTask) ReadAll(search string, u *User, page int) (interface{}, error) {
|
||||
return GetTasksByUser(search, u, page)
|
||||
}
|
||||
|
||||
//GetTasksByUser returns all tasks for a user
|
||||
func GetTasksByUser(search string, u *User, page int) (tasks []*ListTask, err error) {
|
||||
// Get all lists
|
||||
lists, err := getRawListsForUser(search, u, page)
|
||||
lists, err := getRawListsForUser("", u, page)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -181,7 +209,7 @@ func GetTasksByUser(search string, u *User, page int) (tasks []*ListTask, err er
|
||||
}
|
||||
|
||||
// Then return all tasks for that lists
|
||||
if err := x.In("list_id", listIDs).Find(&tasks); err != nil {
|
||||
if err := x.In("list_id", listIDs).Where("text LIKE ?", "%"+search+"%").Find(&tasks); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,19 @@ func CreateOrUpdateList(list *List) (err error) {
|
||||
}
|
||||
|
||||
// Update implements the update method of CRUDable
|
||||
// @Summary Updates a list
|
||||
// @Description Updates a list. This does not include adding a task (see below).
|
||||
// @tags list
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "List ID"
|
||||
// @Param list body models.List true "The list with updated values you want to update."
|
||||
// @Success 200 {object} models.List "The updated list."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid list object provided."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the list"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{id} [post]
|
||||
func (l *List) Update() (err error) {
|
||||
// Check if it exists
|
||||
if err = l.GetSimpleByID(); err != nil {
|
||||
@ -42,6 +55,19 @@ func (l *List) Update() (err error) {
|
||||
}
|
||||
|
||||
// Create implements the create method of CRUDable
|
||||
// @Summary Creates a new list
|
||||
// @Description Creates a new list in a given namespace. The user needs write-access to the namespace.
|
||||
// @tags list
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param namespaceID path int true "Namespace ID"
|
||||
// @Param list body models.List true "The list you want to create."
|
||||
// @Success 200 {object} models.List "The created list."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid list object provided."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the list"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces/{namespaceID}/lists [put]
|
||||
func (l *List) Create(doer *User) (err error) {
|
||||
// Check rights
|
||||
u, err := GetUserByID(doer.ID)
|
||||
|
@ -1,6 +1,17 @@
|
||||
package models
|
||||
|
||||
// Delete implements the delete method of CRUDable
|
||||
// @Summary Deletes a list
|
||||
// @Description Delets a list
|
||||
// @tags list
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "List ID"
|
||||
// @Success 200 {object} models.Message "The list was successfully deleted."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid list object provided."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the list"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{id} [delete]
|
||||
func (l *List) Delete() (err error) {
|
||||
// Check if the list exists
|
||||
if err = l.GetSimpleByID(); err != nil {
|
||||
|
@ -5,6 +5,19 @@ import (
|
||||
)
|
||||
|
||||
// Create is the implementation to create a list task
|
||||
// @Summary Create a task
|
||||
// @Description Inserts a task into a list.
|
||||
// @tags task
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "List ID"
|
||||
// @Param task body models.ListTask true "The task object"
|
||||
// @Success 200 {object} models.ListTask "The created task object."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid task object provided."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the list"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{id} [put]
|
||||
func (i *ListTask) Create(doer *User) (err error) {
|
||||
i.ID = 0
|
||||
|
||||
@ -31,6 +44,19 @@ func (i *ListTask) Create(doer *User) (err error) {
|
||||
}
|
||||
|
||||
// Update updates a list task
|
||||
// @Summary Update a task
|
||||
// @Description Updates a task. This includes marking it as done.
|
||||
// @tags task
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "Task ID"
|
||||
// @Param task body models.ListTask true "The task object"
|
||||
// @Success 200 {object} models.ListTask "The updated task object."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid task object provided."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the task (aka its list)"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /tasks/{id} [post]
|
||||
func (i *ListTask) Update() (err error) {
|
||||
// Check if the task exists
|
||||
ot, err := GetListTaskByID(i.ID)
|
||||
|
@ -1,6 +1,17 @@
|
||||
package models
|
||||
|
||||
// Delete implements the delete method for listTask
|
||||
// @Summary Delete a task
|
||||
// @Description Deletes a task from a list. This does not mean "mark it done".
|
||||
// @tags task
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "Task ID"
|
||||
// @Success 200 {object} models.Message "The created task object."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid task ID provided."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the list"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /tasks/{id} [delete]
|
||||
func (i *ListTask) Delete() (err error) {
|
||||
|
||||
// Check if it exists
|
||||
|
@ -19,7 +19,8 @@ func (ListUser) TableName() string {
|
||||
return "users_list"
|
||||
}
|
||||
|
||||
type userWithRight struct {
|
||||
// UserWithRight represents a user in combination with the right it can have on a list/namespace
|
||||
type UserWithRight struct {
|
||||
User `xorm:"extends"`
|
||||
Right UserRight `json:"right"`
|
||||
}
|
||||
|
@ -1,6 +1,20 @@
|
||||
package models
|
||||
|
||||
// Create creates a new list <-> user relation
|
||||
// @Summary Add a user to a list
|
||||
// @Description Gives a user access to a list.
|
||||
// @tags sharing
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "List ID"
|
||||
// @Param list body models.ListUser true "The user you want to add to the list."
|
||||
// @Success 200 {object} models.ListUser "The created user<->list relation."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid user list object provided."
|
||||
// @Failure 404 {object} models.HTTPError "The user does not exist."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the list"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{id}/users [put]
|
||||
func (ul *ListUser) Create(u *User) (err error) {
|
||||
|
||||
// Check if the right is valid
|
||||
|
@ -1,6 +1,18 @@
|
||||
package models
|
||||
|
||||
// Delete deletes a list <-> user relation
|
||||
// @Summary Delete a user from a list
|
||||
// @Description Delets a user from a list. The user won't have access to the list anymore.
|
||||
// @tags sharing
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param listID path int true "List ID"
|
||||
// @Param userID path int true "User ID"
|
||||
// @Success 200 {object} models.Message "The user was successfully removed from the list."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the list"
|
||||
// @Failure 404 {object} models.HTTPError "user or list does not exist."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{listID}/users/{userID} [delete]
|
||||
func (lu *ListUser) Delete() (err error) {
|
||||
|
||||
// Check if the user exists
|
||||
|
@ -1,6 +1,19 @@
|
||||
package models
|
||||
|
||||
// ReadAll gets all users who have access to a list
|
||||
// @Summary Get users on a list
|
||||
// @Description Returns a list with all users which have access on a given list.
|
||||
// @tags sharing
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "List 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 users by its name."
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {array} models.UserWithRight "The users with the right they have."
|
||||
// @Failure 403 {object} models.HTTPError "No right to see the list."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{id}/users [get]
|
||||
func (ul *ListUser) ReadAll(search string, u *User, page int) (interface{}, error) {
|
||||
// Check if the user has access to the list
|
||||
l := &List{ID: ul.ListID}
|
||||
@ -12,7 +25,7 @@ func (ul *ListUser) ReadAll(search string, u *User, page int) (interface{}, erro
|
||||
}
|
||||
|
||||
// Get all users
|
||||
all := []*userWithRight{}
|
||||
all := []*UserWithRight{}
|
||||
err := x.
|
||||
Join("INNER", "users_list", "user_id = users.id").
|
||||
Where("users_list.list_id = ?", ul.ListID).
|
||||
|
@ -1,6 +1,20 @@
|
||||
package models
|
||||
|
||||
// Update updates a user <-> list relation
|
||||
// @Summary Update a user <-> list relation
|
||||
// @Description Update a user <-> list relation. Mostly used to update the right that user has.
|
||||
// @tags sharing
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param listID path int true "List ID"
|
||||
// @Param userID path int true "User ID"
|
||||
// @Param list body models.ListUser true "The user you want to update."
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {object} models.ListUser "The updated user <-> list relation."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have admin-access to the list"
|
||||
// @Failure 404 {object} models.HTTPError "User or list does not exist."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{listID}/users/{userID} [post]
|
||||
func (lu *ListUser) Update() (err error) {
|
||||
|
||||
// Check if the right is valid
|
||||
|
@ -47,20 +47,43 @@ func GetNamespaceByID(id int64) (namespace Namespace, err error) {
|
||||
}
|
||||
|
||||
// ReadOne gets one namespace
|
||||
// @Summary Gets one namespace
|
||||
// @Description Returns a namespace by its ID.
|
||||
// @tags namespace
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "Namespace ID"
|
||||
// @Success 200 {object} models.Namespace "The Namespace"
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to that namespace."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces/{id} [get]
|
||||
func (n *Namespace) ReadOne() (err error) {
|
||||
*n, err = GetNamespaceByID(n.ID)
|
||||
return
|
||||
}
|
||||
|
||||
// NamespaceWithLists represents a namespace with list meta informations
|
||||
type NamespaceWithLists struct {
|
||||
Namespace `xorm:"extends"`
|
||||
Lists []*List `xorm:"-" json:"lists"`
|
||||
}
|
||||
|
||||
// ReadAll gets all namespaces a user has access to
|
||||
// @Summary Get all namespaces a user has access to
|
||||
// @Description Returns all namespaces a user has access to.
|
||||
// @tags namespace
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @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 namespaces by name."
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {array} models.NamespaceWithLists "The Namespaces."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces [get]
|
||||
func (n *Namespace) ReadAll(search string, doer *User, page int) (interface{}, error) {
|
||||
|
||||
type namespaceWithLists struct {
|
||||
Namespace `xorm:"extends"`
|
||||
Lists []*List `xorm:"-" json:"lists"`
|
||||
}
|
||||
|
||||
all := []*namespaceWithLists{}
|
||||
all := []*NamespaceWithLists{}
|
||||
|
||||
err := x.Select("namespaces.*").
|
||||
Table("namespaces").
|
||||
|
@ -1,6 +1,18 @@
|
||||
package models
|
||||
|
||||
// Create implements the creation method via the interface
|
||||
// @Summary Creates a new namespace
|
||||
// @Description Creates a new namespace.
|
||||
// @tags namespace
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param namespace body models.Namespace true "The namespace you want to create."
|
||||
// @Success 200 {object} models.Namespace "The created namespace."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid namespace object provided."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the namespace"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces [put]
|
||||
func (n *Namespace) Create(doer *User) (err error) {
|
||||
// Check if we have at least a name
|
||||
if n.Name == "" {
|
||||
|
@ -1,6 +1,17 @@
|
||||
package models
|
||||
|
||||
// Delete deletes a namespace
|
||||
// @Summary Deletes a namespace
|
||||
// @Description Delets a namespace
|
||||
// @tags namespace
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "Namespace ID"
|
||||
// @Success 200 {object} models.Message "The namespace was successfully deleted."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid namespace object provided."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the namespace"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces/{id} [delete]
|
||||
func (n *Namespace) Delete() (err error) {
|
||||
|
||||
// Check if the namespace exists
|
||||
|
@ -1,6 +1,19 @@
|
||||
package models
|
||||
|
||||
// Update implements the update method via the interface
|
||||
// @Summary Updates a namespace
|
||||
// @Description Updates a namespace.
|
||||
// @tags namespace
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "Namespace ID"
|
||||
// @Param namespace body models.Namespace true "The namespace with updated values you want to update."
|
||||
// @Success 200 {object} models.Namespace "The updated namespace."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid namespace object provided."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the namespace"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespace/{id} [post]
|
||||
func (n *Namespace) Update() (err error) {
|
||||
// Check if we have at least a name
|
||||
if n.Name == "" {
|
||||
|
@ -1,6 +1,20 @@
|
||||
package models
|
||||
|
||||
// Create creates a new namespace <-> user relation
|
||||
// @Summary Add a user to a namespace
|
||||
// @Description Gives a user access to a namespace.
|
||||
// @tags sharing
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "Namespace ID"
|
||||
// @Param namespace body models.NamespaceUser true "The user you want to add to the namespace."
|
||||
// @Success 200 {object} models.NamespaceUser "The created user<->namespace relation."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid user namespace object provided."
|
||||
// @Failure 404 {object} models.HTTPError "The user does not exist."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the namespace"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces/{id}/users [put]
|
||||
func (un *NamespaceUser) Create(u *User) (err error) {
|
||||
|
||||
// Reset the id
|
||||
|
@ -1,6 +1,18 @@
|
||||
package models
|
||||
|
||||
// Delete deletes a namespace <-> user relation
|
||||
// @Summary Delete a user from a namespace
|
||||
// @Description Delets a user from a namespace. The user won't have access to the namespace anymore.
|
||||
// @tags sharing
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param namespaceID path int true "Namespace ID"
|
||||
// @Param userID path int true "user ID"
|
||||
// @Success 200 {object} models.Message "The user was successfully deleted."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the namespace"
|
||||
// @Failure 404 {object} models.HTTPError "user or namespace does not exist."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces/{namespaceID}/users/{userID} [delete]
|
||||
func (nu *NamespaceUser) Delete() (err error) {
|
||||
|
||||
// Check if the user exists
|
||||
|
@ -1,6 +1,19 @@
|
||||
package models
|
||||
|
||||
// ReadAll gets all users who have access to a namespace
|
||||
// @Summary Get users on a namespace
|
||||
// @Description Returns a namespace with all users 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 users by its name."
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {array} models.UserWithRight "The users with the right they have."
|
||||
// @Failure 403 {object} models.HTTPError "No right to see the namespace."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces/{id}/users [get]
|
||||
func (un *NamespaceUser) ReadAll(search string, u *User, page int) (interface{}, error) {
|
||||
// Check if the user has access to the namespace
|
||||
l, err := GetNamespaceByID(un.NamespaceID)
|
||||
@ -12,7 +25,7 @@ func (un *NamespaceUser) ReadAll(search string, u *User, page int) (interface{},
|
||||
}
|
||||
|
||||
// Get all users
|
||||
all := []*userWithRight{}
|
||||
all := []*UserWithRight{}
|
||||
err = x.
|
||||
Join("INNER", "users_namespace", "user_id = users.id").
|
||||
Where("users_namespace.namespace_id = ?", un.NamespaceID).
|
||||
|
@ -1,6 +1,20 @@
|
||||
package models
|
||||
|
||||
// Update updates a user <-> namespace relation
|
||||
// @Summary Update a user <-> namespace relation
|
||||
// @Description Update a user <-> namespace relation. Mostly used to update the right that user has.
|
||||
// @tags sharing
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param namespaceID path int true "Namespace ID"
|
||||
// @Param userID path int true "User ID"
|
||||
// @Param namespace body models.NamespaceUser true "The user you want to update."
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {object} models.NamespaceUser "The updated user <-> namespace relation."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have admin-access to the namespace"
|
||||
// @Failure 404 {object} models.HTTPError "User or namespace does not exist."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces/{namespaceID}/users/{userID} [post]
|
||||
func (nu *NamespaceUser) Update() (err error) {
|
||||
|
||||
// Check if the right is valid
|
||||
|
@ -19,7 +19,8 @@ func (TeamList) TableName() string {
|
||||
return "team_list"
|
||||
}
|
||||
|
||||
type teamWithRight struct {
|
||||
// TeamWithRight represents a team, combined with rights.
|
||||
type TeamWithRight struct {
|
||||
Team `xorm:"extends"`
|
||||
Right TeamRight `json:"right"`
|
||||
}
|
||||
|
@ -1,6 +1,20 @@
|
||||
package models
|
||||
|
||||
// Create creates a new team <-> list relation
|
||||
// @Summary Add a team to a list
|
||||
// @Description Gives a team access to a list.
|
||||
// @tags sharing
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "List ID"
|
||||
// @Param list body models.TeamList true "The team you want to add to the list."
|
||||
// @Success 200 {object} models.TeamList "The created team<->list relation."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid team list object provided."
|
||||
// @Failure 404 {object} models.HTTPError "The team does not exist."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the list"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{id}/teams [put]
|
||||
func (tl *TeamList) Create(doer *User) (err error) {
|
||||
|
||||
// Check if the rights are valid
|
||||
|
@ -1,6 +1,18 @@
|
||||
package models
|
||||
|
||||
// Delete deletes a team <-> list relation based on the list & team id
|
||||
// @Summary Delete a team from a list
|
||||
// @Description Delets a team from a list. The team won't have access to the list anymore.
|
||||
// @tags sharing
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param listID path int true "List ID"
|
||||
// @Param teamID path int true "Team ID"
|
||||
// @Success 200 {object} models.Message "The team was successfully deleted."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the list"
|
||||
// @Failure 404 {object} models.HTTPError "Team or list does not exist."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{listID}/teams/{teamID} [delete]
|
||||
func (tl *TeamList) Delete() (err error) {
|
||||
|
||||
// Check if the team exists
|
||||
|
@ -1,6 +1,19 @@
|
||||
package models
|
||||
|
||||
// ReadAll implements the method to read all teams of a list
|
||||
// @Summary Get teams on a list
|
||||
// @Description Returns a list with all teams which have access on a given list.
|
||||
// @tags sharing
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path int true "List 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."
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {array} models.TeamWithRight "The teams with their right."
|
||||
// @Failure 403 {object} models.HTTPError "No right to see the list."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{id}/teams [get]
|
||||
func (tl *TeamList) ReadAll(search string, u *User, page int) (interface{}, error) {
|
||||
// Check if the user can read the namespace
|
||||
l := &List{ID: tl.ListID}
|
||||
@ -12,7 +25,7 @@ func (tl *TeamList) ReadAll(search string, u *User, page int) (interface{}, erro
|
||||
}
|
||||
|
||||
// Get the teams
|
||||
all := []*teamWithRight{}
|
||||
all := []*TeamWithRight{}
|
||||
err := x.
|
||||
Table("teams").
|
||||
Join("INNER", "team_list", "team_id = teams.id").
|
||||
|
@ -1,6 +1,20 @@
|
||||
package models
|
||||
|
||||
// Update updates a team <-> list relation
|
||||
// @Summary Update a team <-> list relation
|
||||
// @Description Update a team <-> list relation. Mostly used to update the right that team has.
|
||||
// @tags sharing
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param listID path int true "List ID"
|
||||
// @Param teamID path int true "Team ID"
|
||||
// @Param list body models.TeamList true "The team you want to update."
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {object} models.TeamList "The updated team <-> list relation."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have admin-access to the list"
|
||||
// @Failure 404 {object} models.HTTPError "Team or list does not exist."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{listID}/teams/{teamID} [post]
|
||||
func (tl *TeamList) Update() (err error) {
|
||||
|
||||
// Check if the right is valid
|
||||
|
@ -1,6 +1,19 @@
|
||||
package models
|
||||
|
||||
// Create implements the create method to assign a user to a team
|
||||
// @Summary Add a user to a team
|
||||
// @Description Add a user to a team.
|
||||
// @tags team
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "Team ID"
|
||||
// @Param team body models.TeamMember true "The user to be added to a team."
|
||||
// @Success 200 {object} models.TeamMember "The newly created member object"
|
||||
// @Failure 400 {object} models.HTTPError "Invalid member object provided."
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the team"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /teams/{id}/members [put]
|
||||
func (tm *TeamMember) Create(doer *User) (err error) {
|
||||
// Check if the team extst
|
||||
_, err = GetTeamByID(tm.TeamID)
|
||||
|
@ -1,6 +1,16 @@
|
||||
package models
|
||||
|
||||
// Delete deletes a user from a team
|
||||
// @Summary Remove a user from a team
|
||||
// @Description Remove a user from a team. This will also revoke any access this user might have via that team.
|
||||
// @tags team
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "Team ID"
|
||||
// @Param userID path int true "User ID"
|
||||
// @Success 200 {object} models.Message "The user was successfully removed from the team."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /teams/{id}/members/{userID} [delete]
|
||||
func (tm *TeamMember) Delete() (err error) {
|
||||
|
||||
total, err := x.Where("team_id = ?", tm.TeamID).Count(&TeamMember{})
|
||||
|
@ -1,6 +1,20 @@
|
||||
package models
|
||||
|
||||
// Create creates a new team <-> namespace relation
|
||||
// @Summary Add a team to a namespace
|
||||
// @Description Gives a team access to a namespace.
|
||||
// @tags sharing
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "Namespace ID"
|
||||
// @Param namespace body models.TeamNamespace true "The team you want to add to the namespace."
|
||||
// @Success 200 {object} models.TeamNamespace "The created team<->namespace relation."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid team namespace object provided."
|
||||
// @Failure 404 {object} models.HTTPError "The team does not exist."
|
||||
// @Failure 403 {object} models.HTTPError "The team does not have access to the namespace"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces/{id}/teams [put]
|
||||
func (tn *TeamNamespace) Create(doer *User) (err error) {
|
||||
|
||||
// Check if the rights are valid
|
||||
|
@ -1,6 +1,18 @@
|
||||
package models
|
||||
|
||||
// Delete deletes a team <-> namespace relation based on the namespace & team id
|
||||
// @Summary Delete a team from a namespace
|
||||
// @Description Delets a team from a namespace. The team won't have access to the namespace anymore.
|
||||
// @tags sharing
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param namespaceID path int true "Namespace ID"
|
||||
// @Param teamID path int true "team ID"
|
||||
// @Success 200 {object} models.Message "The team was successfully deleted."
|
||||
// @Failure 403 {object} models.HTTPError "The team does not have access to the namespace"
|
||||
// @Failure 404 {object} models.HTTPError "team or namespace does not exist."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces/{namespaceID}/teams/{teamID} [delete]
|
||||
func (tn *TeamNamespace) Delete() (err error) {
|
||||
|
||||
// Check if the team exists
|
||||
|
@ -1,6 +1,19 @@
|
||||
package models
|
||||
|
||||
// ReadAll implements the method to read all teams of a namespace
|
||||
// @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."
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {array} models.TeamWithRight "The teams with the right they have."
|
||||
// @Failure 403 {object} models.HTTPError "No right to see the namespace."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces/{id}/teams [get]
|
||||
func (tn *TeamNamespace) ReadAll(search string, user *User, page int) (interface{}, error) {
|
||||
// Check if the user can read the namespace
|
||||
n, err := GetNamespaceByID(tn.NamespaceID)
|
||||
@ -12,7 +25,7 @@ func (tn *TeamNamespace) ReadAll(search string, user *User, page int) (interface
|
||||
}
|
||||
|
||||
// Get the teams
|
||||
all := []*teamWithRight{}
|
||||
all := []*TeamWithRight{}
|
||||
|
||||
err = x.Table("teams").
|
||||
Join("INNER", "team_namespaces", "team_id = teams.id").
|
||||
|
@ -1,6 +1,20 @@
|
||||
package models
|
||||
|
||||
// Update updates a team <-> namespace relation
|
||||
// @Summary Update a team <-> namespace relation
|
||||
// @Description Update a team <-> namespace relation. Mostly used to update the right that team has.
|
||||
// @tags sharing
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param namespaceID path int true "Namespace ID"
|
||||
// @Param teamID path int true "Team ID"
|
||||
// @Param namespace body models.TeamNamespace true "The team you want to update."
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {object} models.TeamNamespace "The updated team <-> namespace relation."
|
||||
// @Failure 403 {object} models.HTTPError "The team does not have admin-access to the namespace"
|
||||
// @Failure 404 {object} models.HTTPError "Team or namespace does not exist."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /namespaces/{namespaceID}/teams/{teamID} [post]
|
||||
func (tl *TeamNamespace) Update() (err error) {
|
||||
|
||||
// Check if the right is valid
|
||||
|
@ -78,12 +78,34 @@ func GetTeamByID(id int64) (team Team, err error) {
|
||||
}
|
||||
|
||||
// ReadOne implements the CRUD method to get one team
|
||||
// @Summary Gets one team
|
||||
// @Description Returns a team by its ID.
|
||||
// @tags team
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "Team ID"
|
||||
// @Success 200 {object} models.Team "The team"
|
||||
// @Failure 403 {object} models.HTTPError "The user does not have access to the team"
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{id} [get]
|
||||
func (t *Team) ReadOne() (err error) {
|
||||
*t, err = GetTeamByID(t.ID)
|
||||
return
|
||||
}
|
||||
|
||||
// ReadAll gets all teams the user is part of
|
||||
// @Summary Get teams
|
||||
// @Description Returns all teams the current user is part of.
|
||||
// @tags team
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @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."
|
||||
// @Security ApiKeyAuth
|
||||
// @Success 200 {array} models.Team "The teams."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /teams [get]
|
||||
func (t *Team) ReadAll(search string, user *User, page int) (teams interface{}, err error) {
|
||||
all := []*Team{}
|
||||
err = x.Select("teams.*").
|
||||
|
@ -1,6 +1,17 @@
|
||||
package models
|
||||
|
||||
// Create is the handler to create a team
|
||||
// @Summary Creates a new team
|
||||
// @Description Creates a new team in a given namespace. The user needs write-access to the namespace.
|
||||
// @tags team
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param team body models.Team true "The team you want to create."
|
||||
// @Success 200 {object} models.Team "The created team."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid team object provided."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /teams [put]
|
||||
func (t *Team) Create(doer *User) (err error) {
|
||||
// Check if we have a name
|
||||
if t.Name == "" {
|
||||
|
@ -1,6 +1,16 @@
|
||||
package models
|
||||
|
||||
// Delete deletes a team
|
||||
// @Summary Deletes a team
|
||||
// @Description Delets a team. This will also remove the access for all users in that team.
|
||||
// @tags team
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "Team ID"
|
||||
// @Success 200 {object} models.Message "The team was successfully deleted."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid team object provided."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /teams/{id} [delete]
|
||||
func (t *Team) Delete() (err error) {
|
||||
|
||||
// Check if the team exists
|
||||
|
@ -1,6 +1,18 @@
|
||||
package models
|
||||
|
||||
// Update is the handler to create a team
|
||||
// @Summary Updates a team
|
||||
// @Description Updates a team.
|
||||
// @tags team
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security ApiKeyAuth
|
||||
// @Param id path int true "Team ID"
|
||||
// @Param team body models.Team true "The team with updated values you want to update."
|
||||
// @Success 200 {object} models.Team "The updated team."
|
||||
// @Failure 400 {object} models.HTTPError "Invalid team object provided."
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /teams/{id} [post]
|
||||
func (t *Team) Update() (err error) {
|
||||
// Check if we have a name
|
||||
if t.Name == "" {
|
||||
|
Reference in New Issue
Block a user