Add utility functions to link shares

This commit is contained in:
kolaente 2021-04-03 23:14:28 +02:00
parent 44ea584ffe
commit a8750e2fef
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 26 additions and 1 deletions

View File

@ -86,6 +86,25 @@ func GetLinkShareFromClaims(claims jwt.MapClaims) (share *LinkSharing, err error
return
}
func (share *LinkSharing) getUserID() int64 {
return share.ID * -1
}
func (share *LinkSharing) toUser() *user.User {
suffix := "Link Share"
if share.Name != "" {
suffix = " (" + suffix + ")"
}
return &user.User{
ID: share.getUserID(),
Name: share.Name + suffix,
Username: share.Name,
Created: share.Created,
Updated: share.Updated,
}
}
// Create creates a new link share for a given list
// @Summary Share a list via link
// @Description Share a list via link. The user needs to have write-access to the list to be able do this.

View File

@ -68,6 +68,11 @@ func (tc *TaskComment) Create(s *xorm.Session, a web.Auth) (err error) {
}
tc.AuthorID = a.GetID()
if share, is := a.(*LinkSharing); is {
tc.AuthorID = share.getUserID()
}
_, err = s.Insert(tc)
if err != nil {
return
@ -83,7 +88,8 @@ func (tc *TaskComment) Create(s *xorm.Session, a web.Auth) (err error) {
return err
}
tc.Author, err = user.GetUserByID(s, a.GetID())
// TODO: Add a wrapper in models which returns either a user or a share disguised as a share
tc.Author, err = user.GetUserByID(s, tc.AuthorID)
return
}