// Copyright 2021 Vikunja and contriubtors. All rights reserved. // // This file is part of Vikunja. // // Vikunja is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // Vikunja is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with Vikunja. If not, see . package models import ( "code.vikunja.io/api/pkg/user" "code.vikunja.io/web" "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) { if u, is := a.(*user.User); is { uu, err = user.GetUserByID(s, u.ID) return } if ls, is := a.(*LinkSharing); is { l, err := GetLinkShareByID(s, ls.ID) if err != nil { return nil, err } return l.toUser(), nil } return } // Returns all users or pseudo link shares from a slice of ids. ids < 0 are considered to be a link share in that case. func getUsersOrLinkSharesFromIDs(s *xorm.Session, ids []int64) (users map[int64]*user.User, err error) { var userIDs []int64 var linkShareIDs []int64 for _, id := range ids { if id < 0 { linkShareIDs = append(linkShareIDs, id*-1) continue } userIDs = append(userIDs, id) } users, err = user.GetUsersByIDs(s, userIDs) if err != nil { return } shares, err := GetLinkSharesByIDs(s, linkShareIDs) if err != nil { return nil, err } for _, share := range shares { users[share.ID*-1] = share.toUser() } return }