Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
0
        public static string Save(RoleModel model)
        {
            if (string.IsNullOrEmpty(model.RoleID))
            {
                model.RoleID = GenerateDbKey(KEY_PREFIX);
                model.Created = DateTimeOffset.Now;
            }

            string key = KEY_PREFIX + model.RoleID;

            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);
        }