2020-02-07 16:27:45 +00:00
|
|
|
// Vikunja is a to-do list application to facilitate your life.
|
2023-09-01 06:32:28 +00:00
|
|
|
// Copyright 2018-present Vikunja and contributors. All rights reserved.
|
2018-11-26 20:17:33 +00:00
|
|
|
//
|
2019-12-04 19:39:56 +00:00
|
|
|
// This program is free software: you can redistribute it and/or modify
|
2020-12-23 15:41:52 +00:00
|
|
|
// it under the terms of the GNU Affero General Public Licensee as published by
|
2019-12-04 19:39:56 +00:00
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2018-11-26 20:17:33 +00:00
|
|
|
//
|
2019-12-04 19:39:56 +00:00
|
|
|
// This program 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
|
2020-12-23 15:41:52 +00:00
|
|
|
// GNU Affero General Public Licensee for more details.
|
2018-11-26 20:17:33 +00:00
|
|
|
//
|
2020-12-23 15:41:52 +00:00
|
|
|
// You should have received a copy of the GNU Affero General Public Licensee
|
2019-12-04 19:39:56 +00:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-11-26 20:17:33 +00:00
|
|
|
|
2018-08-30 06:58:09 +00:00
|
|
|
package models
|
|
|
|
|
2018-10-31 12:42:38 +00:00
|
|
|
import (
|
2018-11-30 23:26:56 +00:00
|
|
|
"code.vikunja.io/web"
|
2020-12-23 15:32:28 +00:00
|
|
|
"xorm.io/xorm"
|
2018-08-30 06:58:09 +00:00
|
|
|
)
|
|
|
|
|
2022-11-13 16:07:01 +00:00
|
|
|
// CanCreate checks if the user can create a new user <-> project relation
|
|
|
|
func (lu *ProjectUser) CanCreate(s *xorm.Session, a web.Auth) (bool, error) {
|
|
|
|
return lu.canDoProjectUser(s, a)
|
2018-08-30 06:58:09 +00:00
|
|
|
}
|
2018-08-30 16:52:12 +00:00
|
|
|
|
2022-11-13 16:07:01 +00:00
|
|
|
// CanDelete checks if the user can delete a user <-> project relation
|
|
|
|
func (lu *ProjectUser) CanDelete(s *xorm.Session, a web.Auth) (bool, error) {
|
|
|
|
return lu.canDoProjectUser(s, a)
|
2018-08-30 16:52:12 +00:00
|
|
|
}
|
2018-09-19 05:54:47 +00:00
|
|
|
|
2022-11-13 16:07:01 +00:00
|
|
|
// CanUpdate checks if the user can update a user <-> project relation
|
|
|
|
func (lu *ProjectUser) CanUpdate(s *xorm.Session, a web.Auth) (bool, error) {
|
|
|
|
return lu.canDoProjectUser(s, a)
|
2019-08-31 20:56:41 +00:00
|
|
|
}
|
|
|
|
|
2022-11-13 16:07:01 +00:00
|
|
|
func (lu *ProjectUser) canDoProjectUser(s *xorm.Session, a web.Auth) (bool, error) {
|
2019-08-31 20:56:41 +00:00
|
|
|
// Link shares aren't allowed to do anything
|
|
|
|
if _, is := a.(*LinkSharing); is {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2022-11-13 16:07:01 +00:00
|
|
|
// Get the project and check if the user has write access on it
|
|
|
|
l := Project{ID: lu.ProjectID}
|
2020-12-23 15:32:28 +00:00
|
|
|
return l.IsAdmin(s, a)
|
2018-09-19 05:54:47 +00:00
|
|
|
}
|