Added list user swagger docs

This commit is contained in:
kolaente 2018-11-12 13:08:27 +01:00
parent 56cf496586
commit 18f6bbb8a5
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
10 changed files with 915 additions and 8 deletions

View File

@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2018-11-12 01:55:18.060385386 +0100 CET m=+0.052034835
// 2018-11-12 13:07:29.286114926 +0100 CET m=+0.107998287
package docs
@ -365,7 +365,7 @@ var doc = `{
],
"responses": {
"200": {
"description": "The tasks",
"description": "The teams with their right.",
"schema": {
"type": "array",
"items": {
@ -466,6 +466,148 @@ var doc = `{
}
}
},
"/lists/{id}/users": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Returns a list with all users which have access on a given list.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"sharing"
],
"summary": "Get users on a list",
"parameters": [
{
"type": "integer",
"description": "List ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "The page number. Used for pagination. If not provided, the first page of results is returned.",
"name": "p",
"in": "query"
},
{
"type": "string",
"description": "Search users by its name.",
"name": "s",
"in": "query"
}
],
"responses": {
"200": {
"description": "The users with the right they have.",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.UserWithRight"
}
}
},
"403": {
"description": "No right to see the list.",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.HTTPError"
}
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
},
"put": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Gives a user access to a list.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"sharing"
],
"summary": "Add a user to a list",
"parameters": [
{
"type": "integer",
"description": "List ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "The user you want to add to the list.",
"name": "list",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/models.ListUser"
}
}
],
"responses": {
"200": {
"description": "The created user\u003c-\u003elist relation.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.ListUser"
}
},
"400": {
"description": "Invalid user list object provided.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"403": {
"description": "The user does not have access to the list",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"404": {
"description": "The user does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
}
},
"/lists/{listID}/teams/{teamID}": {
"post": {
"security": [
@ -603,6 +745,143 @@ var doc = `{
}
}
},
"/lists/{listID}/users/{userID}": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Update a user \u003c-\u003e list relation. Mostly used to update the right that user has.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"sharing"
],
"summary": "Update a user \u003c-\u003e list relation",
"parameters": [
{
"type": "integer",
"description": "List ID",
"name": "listID",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "User ID",
"name": "userID",
"in": "path",
"required": true
},
{
"description": "The user you want to update.",
"name": "list",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/models.ListUser"
}
}
],
"responses": {
"200": {
"description": "The updated user \u003c-\u003e list relation.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.ListUser"
}
},
"403": {
"description": "The user does not have admin-access to the list",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"404": {
"description": "User or list does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
},
"delete": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Delets a user from a list. The user won't have access to the list anymore.",
"produces": [
"application/json"
],
"tags": [
"sharing"
],
"summary": "Delete a user from a list",
"parameters": [
{
"type": "integer",
"description": "List ID",
"name": "listID",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "User ID",
"name": "userID",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "The user was successfully removed from the list.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"403": {
"description": "The user does not have access to the list",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"404": {
"description": "user or list does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
}
},
"/login": {
"post": {
"description": "Logs a user in. Returns a JWT-Token to authenticate further requests.",
@ -1390,6 +1669,29 @@ var doc = `{
}
}
},
"models.ListUser": {
"type": "object",
"properties": {
"created": {
"type": "integer"
},
"id": {
"type": "integer"
},
"list_id": {
"type": "integer"
},
"right": {
"type": "integer"
},
"updated": {
"type": "integer"
},
"user_id": {
"type": "integer"
}
}
},
"models.Message": {
"type": "object",
"properties": {
@ -1515,6 +1817,23 @@ var doc = `{
}
}
},
"models.UserWithRight": {
"type": "object",
"properties": {
"email": {
"type": "string"
},
"id": {
"type": "integer"
},
"right": {
"type": "integer"
},
"username": {
"type": "string"
}
}
},
"v1.Token": {
"type": "object",
"properties": {

View File

@ -352,7 +352,7 @@
],
"responses": {
"200": {
"description": "The tasks",
"description": "The teams with their right.",
"schema": {
"type": "array",
"items": {
@ -453,6 +453,148 @@
}
}
},
"/lists/{id}/users": {
"get": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Returns a list with all users which have access on a given list.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"sharing"
],
"summary": "Get users on a list",
"parameters": [
{
"type": "integer",
"description": "List ID",
"name": "id",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "The page number. Used for pagination. If not provided, the first page of results is returned.",
"name": "p",
"in": "query"
},
{
"type": "string",
"description": "Search users by its name.",
"name": "s",
"in": "query"
}
],
"responses": {
"200": {
"description": "The users with the right they have.",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.UserWithRight"
}
}
},
"403": {
"description": "No right to see the list.",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/models.HTTPError"
}
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
},
"put": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Gives a user access to a list.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"sharing"
],
"summary": "Add a user to a list",
"parameters": [
{
"type": "integer",
"description": "List ID",
"name": "id",
"in": "path",
"required": true
},
{
"description": "The user you want to add to the list.",
"name": "list",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/models.ListUser"
}
}
],
"responses": {
"200": {
"description": "The created user\u003c-\u003elist relation.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.ListUser"
}
},
"400": {
"description": "Invalid user list object provided.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"403": {
"description": "The user does not have access to the list",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"404": {
"description": "The user does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
}
},
"/lists/{listID}/teams/{teamID}": {
"post": {
"security": [
@ -590,6 +732,143 @@
}
}
},
"/lists/{listID}/users/{userID}": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Update a user \u003c-\u003e list relation. Mostly used to update the right that user has.",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"sharing"
],
"summary": "Update a user \u003c-\u003e list relation",
"parameters": [
{
"type": "integer",
"description": "List ID",
"name": "listID",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "User ID",
"name": "userID",
"in": "path",
"required": true
},
{
"description": "The user you want to update.",
"name": "list",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/models.ListUser"
}
}
],
"responses": {
"200": {
"description": "The updated user \u003c-\u003e list relation.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.ListUser"
}
},
"403": {
"description": "The user does not have admin-access to the list",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"404": {
"description": "User or list does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
},
"delete": {
"security": [
{
"ApiKeyAuth": []
}
],
"description": "Delets a user from a list. The user won't have access to the list anymore.",
"produces": [
"application/json"
],
"tags": [
"sharing"
],
"summary": "Delete a user from a list",
"parameters": [
{
"type": "integer",
"description": "List ID",
"name": "listID",
"in": "path",
"required": true
},
{
"type": "integer",
"description": "User ID",
"name": "userID",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "The user was successfully removed from the list.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
},
"403": {
"description": "The user does not have access to the list",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"404": {
"description": "user or list does not exist.",
"schema": {
"type": "object",
"$ref": "#/definitions/models.HTTPError"
}
},
"500": {
"description": "Internal error",
"schema": {
"type": "object",
"$ref": "#/definitions/models.Message"
}
}
}
}
},
"/login": {
"post": {
"description": "Logs a user in. Returns a JWT-Token to authenticate further requests.",
@ -1377,6 +1656,29 @@
}
}
},
"models.ListUser": {
"type": "object",
"properties": {
"created": {
"type": "integer"
},
"id": {
"type": "integer"
},
"list_id": {
"type": "integer"
},
"right": {
"type": "integer"
},
"updated": {
"type": "integer"
},
"user_id": {
"type": "integer"
}
}
},
"models.Message": {
"type": "object",
"properties": {
@ -1502,6 +1804,23 @@
}
}
},
"models.UserWithRight": {
"type": "object",
"properties": {
"email": {
"type": "string"
},
"id": {
"type": "integer"
},
"right": {
"type": "integer"
},
"username": {
"type": "string"
}
}
},
"v1.Token": {
"type": "object",
"properties": {

View File

@ -67,6 +67,21 @@ definitions:
updated:
type: integer
type: object
models.ListUser:
properties:
created:
type: integer
id:
type: integer
list_id:
type: integer
right:
type: integer
updated:
type: integer
user_id:
type: integer
type: object
models.Message:
properties:
message:
@ -148,6 +163,17 @@ definitions:
username:
type: string
type: object
models.UserWithRight:
properties:
email:
type: string
id:
type: integer
right:
type: integer
username:
type: string
type: object
v1.Token:
properties:
token:
@ -392,7 +418,7 @@ paths:
- application/json
responses:
"200":
description: The tasks
description: The teams with their right.
schema:
items:
$ref: '#/definitions/models.TeamWithRight'
@ -463,6 +489,101 @@ paths:
summary: Add a team to a list
tags:
- sharing
/lists/{id}/users:
get:
consumes:
- application/json
description: Returns a list with all users which have access on a given list.
parameters:
- description: List ID
in: path
name: id
required: true
type: integer
- description: The page number. Used for pagination. If not provided, the first
page of results is returned.
in: query
name: p
type: integer
- description: Search users by its name.
in: query
name: s
type: string
produces:
- application/json
responses:
"200":
description: The users with the right they have.
schema:
items:
$ref: '#/definitions/models.UserWithRight'
type: array
"403":
description: No right to see the list.
schema:
items:
$ref: '#/definitions/models.HTTPError'
type: array
"500":
description: Internal error
schema:
$ref: '#/definitions/models.Message'
type: object
security:
- ApiKeyAuth: []
summary: Get users on a list
tags:
- sharing
put:
consumes:
- application/json
description: Gives a user access to a list.
parameters:
- description: List ID
in: path
name: id
required: true
type: integer
- description: The user you want to add to the list.
in: body
name: list
required: true
schema:
$ref: '#/definitions/models.ListUser'
type: object
produces:
- application/json
responses:
"200":
description: The created user<->list relation.
schema:
$ref: '#/definitions/models.ListUser'
type: object
"400":
description: Invalid user list object provided.
schema:
$ref: '#/definitions/models.HTTPError'
type: object
"403":
description: The user does not have access to the list
schema:
$ref: '#/definitions/models.HTTPError'
type: object
"404":
description: The user does not exist.
schema:
$ref: '#/definitions/models.HTTPError'
type: object
"500":
description: Internal error
schema:
$ref: '#/definitions/models.Message'
type: object
security:
- ApiKeyAuth: []
summary: Add a user to a list
tags:
- sharing
/lists/{listID}/teams/{teamID}:
delete:
description: Delets a team from a list. The team won't have access to the list
@ -557,6 +678,100 @@ paths:
summary: Update a team <-> list relation
tags:
- sharing
/lists/{listID}/users/{userID}:
delete:
description: Delets a user from a list. The user won't have access to the list
anymore.
parameters:
- description: List ID
in: path
name: listID
required: true
type: integer
- description: User ID
in: path
name: userID
required: true
type: integer
produces:
- application/json
responses:
"200":
description: The user was successfully removed from the list.
schema:
$ref: '#/definitions/models.Message'
type: object
"403":
description: The user does not have access to the list
schema:
$ref: '#/definitions/models.HTTPError'
type: object
"404":
description: user or list does not exist.
schema:
$ref: '#/definitions/models.HTTPError'
type: object
"500":
description: Internal error
schema:
$ref: '#/definitions/models.Message'
type: object
security:
- ApiKeyAuth: []
summary: Delete a user from a list
tags:
- sharing
post:
consumes:
- application/json
description: Update a user <-> list relation. Mostly used to update the right
that user has.
parameters:
- description: List ID
in: path
name: listID
required: true
type: integer
- description: User ID
in: path
name: userID
required: true
type: integer
- description: The user you want to update.
in: body
name: list
required: true
schema:
$ref: '#/definitions/models.ListUser'
type: object
produces:
- application/json
responses:
"200":
description: The updated user <-> list relation.
schema:
$ref: '#/definitions/models.ListUser'
type: object
"403":
description: The user does not have admin-access to the list
schema:
$ref: '#/definitions/models.HTTPError'
type: object
"404":
description: User or list does not exist.
schema:
$ref: '#/definitions/models.HTTPError'
type: object
"500":
description: Internal error
schema:
$ref: '#/definitions/models.Message'
type: object
security:
- ApiKeyAuth: []
summary: Update a user <-> list relation
tags:
- sharing
/login:
post:
consumes:

View File

@ -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"`
}

View File

@ -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

View File

@ -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

View File

@ -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."
// @Success 403 {array} 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).

View File

@ -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

View File

@ -12,7 +12,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).

View File

@ -10,7 +10,7 @@ package models
// @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 tasks"
// @Success 200 {array} models.TeamWithRight "The teams with their right."
// @Success 403 {array} models.HTTPError "No right to see the list."
// @Failure 500 {object} models.Message "Internal error"
// @Router /lists/{id}/teams [get]