71cb654d71
* revert in-memory unit tests for sqlite * fix unit test * fix comments * fix unit tests
64 lines
1.7 KiB
Go
64 lines
1.7 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package localpermissions
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
|
|
"github.com/mattermost/focalboard/server/model"
|
|
"github.com/mattermost/focalboard/server/services/permissions"
|
|
|
|
mmModel "github.com/mattermost/mattermost-server/v6/model"
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
|
)
|
|
|
|
type Service struct {
|
|
store permissions.Store
|
|
logger *mlog.Logger
|
|
}
|
|
|
|
func New(store permissions.Store, logger *mlog.Logger) *Service {
|
|
return &Service{
|
|
store: store,
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
func (s *Service) HasPermissionToTeam(userID, teamID string, permission *mmModel.Permission) bool {
|
|
if userID == "" || teamID == "" || permission == nil {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (s *Service) HasPermissionToBoard(userID, boardID string, permission *mmModel.Permission) bool {
|
|
if userID == "" || boardID == "" || permission == nil {
|
|
return false
|
|
}
|
|
|
|
member, err := s.store.GetMemberForBoard(boardID, userID)
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return false
|
|
}
|
|
if err != nil {
|
|
s.logger.Error("error getting member for board",
|
|
mlog.String("boardID", boardID),
|
|
mlog.String("userID", userID),
|
|
mlog.Err(err),
|
|
)
|
|
return false
|
|
}
|
|
|
|
switch permission {
|
|
case model.PermissionManageBoardType, model.PermissionDeleteBoard, model.PermissionManageBoardRoles, model.PermissionShareBoard:
|
|
return member.SchemeAdmin
|
|
case model.PermissionManageBoardCards, model.PermissionManageBoardProperties:
|
|
return member.SchemeAdmin || member.SchemeEditor
|
|
case model.PermissionViewBoard:
|
|
return member.SchemeAdmin || member.SchemeEditor || member.SchemeCommenter || member.SchemeViewer
|
|
default:
|
|
return false
|
|
}
|
|
}
|