Пример #1
0
        public static string Save(RoleElementAccessModel model)
        {
            if (string.IsNullOrEmpty(model.RoleID) || string.IsNullOrEmpty(model.ElementID))
            {
                throw new Exception("RoleID and ElementID are both required.");
            }

            string key = KEY_PREFIX + model.RoleID + "-" + model.ElementID;

            //check if this is a new entry
            if (!client.KeyExists(key))
            {
                model.Created = DateTimeOffset.Now;
            }

            model.LastModified = DateTimeOffset.Now;

            if (client.StoreJson(Enyim.Caching.Memcached.StoreMode.Set, key, model))
            {
                return key;
            }

            Exceptions.CouchbaseSaveException ex =
                new Exceptions.CouchbaseSaveException(model.Type, model);

            throw (ex);
        }
Пример #2
0
        /// <summary>
        /// Initialize the global admin role. NOTE: you must sync all elements first!
        /// </summary>
        public static void SyncGlobalAdmin()
        {
            //check if the global admin role exists, if not create it
            if (!client.KeyExists(KEY_PREFIX + GlobalAdminRole))
            {
                RoleModel globalAdmin = new RoleModel()
                {
                    RoleID = GlobalAdminRole,
                    Created = DateTimeOffset.Now,
                    RoleName = "Global Admin"
                };

                Save(globalAdmin);
            }

            //make sure the global admin role has read/write access to all elements
            Couchbase.IView<ElementModel> allElements = ElementService.GetAllElements();

            foreach (ElementModel element in allElements)
            {
                RoleElementAccessModel model = new RoleElementAccessModel()
                {
                    AccessLevel = Enums.SecurityAccessLevels.ReadWrite,
                    ElementID = element.ElementID,
                    RoleID = GlobalAdminRole
                };

                RoleElementAccessService.Save(model);
            }
        }