users on lists are now referenced by their username
continuous-integration/drone/push Build is failing Details

This commit is contained in:
kolaente 2019-05-25 10:52:47 +02:00
parent e67783888d
commit acb5364d1e
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 9 additions and 4 deletions

View File

@ -22,8 +22,10 @@ import "code.vikunja.io/web"
type ListUser struct {
// The unique, numeric id of this list <-> user relation.
ID int64 `xorm:"int(11) autoincr not null unique pk" json:"id" param:"namespace"`
// The user id.
UserID int64 `xorm:"int(11) not null INDEX" json:"userID" param:"user"`
// The username.
Username string `xorm:"-" json:"username" param:"user"`
// Used internally to reference the user
UserID int64 `xorm:"int(11) not null INDEX" json:"-"`
// The list id.
ListID int64 `xorm:"int(11) not null INDEX" json:"-" param:"list"`
// The right this user has. 0 = Read only, 1 = Read & Write, 2 = Admin. See the docs for more details.

View File

@ -47,9 +47,11 @@ func (lu *ListUser) Create(a web.Auth) (err error) {
}
// Check if the user exists
if _, err = GetUserByID(lu.UserID); err != nil {
user, err := GetUser(User{Username: lu.Username})
if err != nil {
return err
}
lu.UserID = user.ID
// Check if the user already has access or is owner of that list
// We explicitly DONT check for teams here

View File

@ -34,10 +34,11 @@ import _ "code.vikunja.io/web" // For swaggerdocs generation
func (lu *ListUser) Delete() (err error) {
// Check if the user exists
_, err = GetUserByID(lu.UserID)
user, err := GetUser(User{Username: lu.Username})
if err != nil {
return
}
lu.UserID = user.ID
// Check if the user has access to the list
has, err := x.Where("user_id = ? AND list_id = ?", lu.UserID, lu.ListID).