Add utility functions to link shares
This commit is contained in:
parent
44ea584ffe
commit
a8750e2fef
@ -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.
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user