From 9985e22dab758cb9c6a292d1430e33dcfd05d109 Mon Sep 17 00:00:00 2001 From: Ibrahim Serdar Acikgoz Date: Thu, 26 May 2022 14:03:47 +0300 Subject: [PATCH] app: add permissions wrapper (#20242) --- app/channels.go | 4 ++++ app/permissions.go | 8 ++++++++ app/server.go | 15 ++++++++------- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/channels.go b/app/channels.go index 58ec7530fa..4ebb777907 100644 --- a/app/channels.go +++ b/app/channels.go @@ -219,6 +219,10 @@ func NewChannels(s *Server, services map[ServiceKey]interface{}) (*Channels, err app: &App{ch: ch}, } + services[PermissionsKey] = &permissionsServiceWrapper{ + app: &App{ch: ch}, + } + return ch, nil } diff --git a/app/permissions.go b/app/permissions.go index 8abc4ea710..6d875849cc 100644 --- a/app/permissions.go +++ b/app/permissions.go @@ -19,6 +19,14 @@ import ( const permissionsExportBatchSize = 100 const systemSchemeName = "00000000-0000-0000-0000-000000000000" // Prevents collisions with user-created schemes. +type permissionsServiceWrapper struct { + app AppIface +} + +func (s *permissionsServiceWrapper) HasPermissionToTeam(userID string, teamID string, permission *model.Permission) bool { + return s.app.HasPermissionToTeam(userID, teamID, permission) +} + func (a *App) ResetPermissionsSystem() *model.AppError { // Reset all Teams to not have a scheme. if err := a.Srv().Store.Team().ResetAllTeamSchemes(); err != nil { diff --git a/app/server.go b/app/server.go index 01b2c24a8f..d7cde0020f 100644 --- a/app/server.go +++ b/app/server.go @@ -86,13 +86,14 @@ var SentryDSN = "placeholder_sentry_dsn" type ServiceKey string const ( - ChannelKey ServiceKey = "channel" - ConfigKey ServiceKey = "config" - LicenseKey ServiceKey = "license" - FilestoreKey ServiceKey = "filestore" - ClusterKey ServiceKey = "cluster" - PostKey ServiceKey = "post" - TeamKey ServiceKey = "team" + ChannelKey ServiceKey = "channel" + ConfigKey ServiceKey = "config" + LicenseKey ServiceKey = "license" + FilestoreKey ServiceKey = "filestore" + ClusterKey ServiceKey = "cluster" + PostKey ServiceKey = "post" + TeamKey ServiceKey = "team" + PermissionsKey ServiceKey = "permissions" ) type Server struct {