summaryrefslogtreecommitdiffstats
path: root/store/local_cache_supplier_roles.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2018-02-06 15:34:08 +0000
committerGitHub <noreply@github.com>2018-02-06 15:34:08 +0000
commite1cd64613591cf5a990442a69ebf188258bd0cb5 (patch)
treead9f247a2c75b0bc03de93dbbfc038afb6b69545 /store/local_cache_supplier_roles.go
parent1c7f25773a77ceb9e84feabe3907e7f93f6870e4 (diff)
downloadchat-e1cd64613591cf5a990442a69ebf188258bd0cb5.tar.gz
chat-e1cd64613591cf5a990442a69ebf188258bd0cb5.tar.bz2
chat-e1cd64613591cf5a990442a69ebf188258bd0cb5.zip
XYZ-37: Advanced Permissions Phase 1 Backend. (#8159)
* XYZ-13: Update Permission and Role structs to new design. * XYZ-10: Role store. * XYZ-9/XYZ-44: Roles API endpoints and WebSocket message. * XYZ-8: Switch server permissions checks to store backed roles. * XYZ-58: Proper validation of roles where required. * XYZ-11/XYZ-55: Migration to store backed roles from policy config. * XYZ-37: Update unit tests to work with database roles. * XYZ-56: Remove the "guest" role. * Changes to SetDefaultRolesFromConfig. * Short-circuit the store if nothing has changed. * Address first round of review comments. * Address second round of review comments.
Diffstat (limited to 'store/local_cache_supplier_roles.go')
-rw-r--r--store/local_cache_supplier_roles.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/store/local_cache_supplier_roles.go b/store/local_cache_supplier_roles.go
new file mode 100644
index 000000000..a9cbda017
--- /dev/null
+++ b/store/local_cache_supplier_roles.go
@@ -0,0 +1,68 @@
+// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package store
+
+import (
+ "context"
+
+ "github.com/mattermost/mattermost-server/model"
+)
+
+func (s *LocalCacheSupplier) handleClusterInvalidateRole(msg *model.ClusterMessage) {
+ if msg.Data == CLEAR_CACHE_MESSAGE_DATA {
+ s.roleCache.Purge()
+ } else {
+ s.roleCache.Remove(msg.Data)
+ }
+}
+
+func (s *LocalCacheSupplier) RoleSave(ctx context.Context, role *model.Role, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
+ if len(role.Id) != 0 {
+ defer s.doInvalidateCacheCluster(s.roleCache, role.Name)
+ }
+ return s.Next().RoleSave(ctx, role, hints...)
+}
+
+func (s *LocalCacheSupplier) RoleGet(ctx context.Context, roleId string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
+ return s.Next().RoleGet(ctx, roleId, hints...)
+}
+
+func (s *LocalCacheSupplier) RoleGetByName(ctx context.Context, name string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
+ if result := s.doStandardReadCache(ctx, s.roleCache, name, hints...); result != nil {
+ return result
+ }
+
+ result := s.Next().RoleGetByName(ctx, name, hints...)
+
+ s.doStandardAddToCache(ctx, s.roleCache, name, result, hints...)
+
+ return result
+}
+
+func (s *LocalCacheSupplier) RoleGetByNames(ctx context.Context, roleNames []string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult {
+ var foundRoles []*model.Role
+ var rolesToQuery []string
+
+ for _, roleName := range roleNames {
+ if result := s.doStandardReadCache(ctx, s.roleCache, roleName, hints...); result != nil {
+ foundRoles = append(foundRoles, result.Data.(*model.Role))
+ } else {
+ rolesToQuery = append(rolesToQuery, roleName)
+ }
+ }
+
+ result := s.Next().RoleGetByNames(ctx, rolesToQuery, hints...)
+
+ if result.Data != nil {
+ rolesFound := result.Data.([]*model.Role)
+ for _, role := range rolesFound {
+ res := NewSupplierResult()
+ res.Data = role
+ s.doStandardAddToCache(ctx, s.roleCache, role.Name, res, hints...)
+ }
+ result.Data = append(foundRoles, result.Data.([]*model.Role)...)
+ }
+
+ return result
+}