forked from vikunja/vikunja
Fix getting user info from /user endpoint for link shares
This commit is contained in:
parent
cb0df3ebbc
commit
8ddc00bd29
@ -231,7 +231,7 @@ func (b *Bucket) ReadAll(s *xorm.Session, auth web.Auth, search string, page int
|
||||
// @Failure 500 {object} models.Message "Internal error"
|
||||
// @Router /lists/{id}/buckets [put]
|
||||
func (b *Bucket) Create(s *xorm.Session, a web.Auth) (err error) {
|
||||
b.CreatedBy, err = getUserOrLinkShareUser(s, a)
|
||||
b.CreatedBy, err = GetUserOrLinkShareUser(s, a)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ func (ta *TaskAttachment) NewAttachment(s *xorm.Session, f io.ReadCloser, realna
|
||||
// Add an entry to the db
|
||||
ta.FileID = file.ID
|
||||
|
||||
ta.CreatedBy, err = getUserOrLinkShareUser(s, a)
|
||||
ta.CreatedBy, err = GetUserOrLinkShareUser(s, a)
|
||||
if err != nil {
|
||||
// remove the uploaded file if adding it to the db fails
|
||||
if err2 := file.Delete(); err2 != nil {
|
||||
|
@ -67,7 +67,7 @@ func (tc *TaskComment) Create(s *xorm.Session, a web.Auth) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
tc.Author, err = getUserOrLinkShareUser(s, a)
|
||||
tc.Author, err = GetUserOrLinkShareUser(s, a)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ func (rel *TaskRelation) Create(s *xorm.Session, a web.Auth) error {
|
||||
}
|
||||
}
|
||||
|
||||
rel.CreatedBy, err = getUserOrLinkShareUser(s, a)
|
||||
rel.CreatedBy, err = GetUserOrLinkShareUser(s, a)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -817,7 +817,7 @@ func createTask(s *xorm.Session, t *Task, a web.Auth, updateAssignees bool) (err
|
||||
return err
|
||||
}
|
||||
|
||||
createdBy, err := getUserOrLinkShareUser(s, a)
|
||||
createdBy, err := GetUserOrLinkShareUser(s, a)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -22,8 +22,8 @@ import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
// Returns either a user or a link share disguised as a user.
|
||||
func getUserOrLinkShareUser(s *xorm.Session, a web.Auth) (uu *user.User, err error) {
|
||||
// GetUserOrLinkShareUser returns either a user or a link share disguised as a user.
|
||||
func GetUserOrLinkShareUser(s *xorm.Session, a web.Auth) (uu *user.User, err error) {
|
||||
if u, is := a.(*user.User); is {
|
||||
uu, err = user.GetUserByID(s, u.ID)
|
||||
return
|
||||
|
@ -19,9 +19,11 @@ package v1
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"code.vikunja.io/api/pkg/models"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
|
||||
user2 "code.vikunja.io/api/pkg/user"
|
||||
"code.vikunja.io/web/handler"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -38,7 +40,7 @@ import (
|
||||
// @Failure 500 {object} models.Message "Internal server error."
|
||||
// @Router /user [get]
|
||||
func UserShow(c echo.Context) error {
|
||||
userInfos, err := user2.GetCurrentUser(c)
|
||||
a, err := auth.GetAuthFromClaims(c)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Error getting current user.")
|
||||
}
|
||||
@ -46,14 +48,8 @@ func UserShow(c echo.Context) error {
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
user, err := user2.GetUserByID(s, userInfos.ID)
|
||||
user, err := models.GetUserOrLinkShareUser(s, a)
|
||||
if err != nil {
|
||||
_ = s.Rollback()
|
||||
return handler.HandleHTTPError(err, c)
|
||||
}
|
||||
|
||||
if err := s.Commit(); err != nil {
|
||||
_ = s.Rollback()
|
||||
return handler.HandleHTTPError(err, c)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user