Ejemplo n.º 1
0
        /// <summary>
        /// Changes the permissions of a Realm.
        /// </summary>
        /// <returns>
        /// An awaitable task, that, upon completion, indicates that the permissions have been successfully applied by the server.
        /// </returns>
        /// <param name="condition">A <see cref="PermissionCondition"/> that will be used to match existing users against.</param>
        /// <param name="realmUrl">The Realm URL whose permissions settings should be changed. Use <c>*</c> to change the permissions of all Realms managed by this <see cref="User"/>.</param>
        /// <param name="accessLevel">
        /// The access level to grant matching users. Note that the access level setting is absolute, i.e. it may revoke permissions for users that
        /// previously had a higher access level. To revoke all permissions, use <see cref="AccessLevel.None" />
        /// </param>
        public Task ApplyPermissionsAsync(PermissionCondition condition, string realmUrl, AccessLevel accessLevel)
        {
            if (string.IsNullOrEmpty(realmUrl))
            {
                throw new ArgumentNullException(nameof(realmUrl));
            }

            var mayRead   = accessLevel >= AccessLevel.Read;
            var mayWrite  = accessLevel >= AccessLevel.Write;
            var mayManage = accessLevel >= AccessLevel.Admin;

            PermissionChange change = null;

            if (condition is UserIdCondition userIdCondition)
            {
                change = new PermissionChange(userIdCondition.UserId, realmUrl, mayRead, mayWrite, mayManage);
            }
            else if (condition is KeyValueCondition keyValueCondition)
            {
                change = new PermissionChange(keyValueCondition.Key, keyValueCondition.Value, realmUrl, mayRead, mayWrite, mayManage);
            }
            else
            {
                throw new NotSupportedException("Invalid PermissionCondition.");
            }

            return(WriteToManagementRealmAsync(change));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Changes the permissions of a Realm.
        /// </summary>
        /// <returns>
        /// An awaitable task, that, upon completion, indicates that the permissions have been successfully applied by the server.
        /// </returns>
        /// <param name="condition">A <see cref="PermissionCondition"/> that will be used to match existing users against.</param>
        /// <param name="realmPath">The Realm path whose permissions settings should be changed. Use <c>*</c> to change the permissions of all Realms managed by this <see cref="User"/>.</param>
        /// <param name="accessLevel">
        /// The access level to grant matching users. Note that the access level setting is absolute, i.e. it may revoke permissions for users that
        /// previously had a higher access level. To revoke all permissions, use <see cref="AccessLevel.None" />
        /// </param>
        public async Task ApplyPermissionsAsync(PermissionCondition condition, string realmPath, AccessLevel accessLevel)
        {
            if (string.IsNullOrEmpty(realmPath))
            {
                throw new ArgumentNullException(nameof(realmPath));
            }

            var payload = new Dictionary <string, object>
            {
                ["condition"]   = condition.ToJsonObject(),
                ["realmPath"]   = realmPath,
                ["accessLevel"] = accessLevel.ToString().ToLower()
            };

            await MakePermissionRequestAsync(HttpMethod.Post, "permissions/apply", payload);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Changes the permissions of a Realm.
 /// </summary>
 /// <returns>
 /// An awaitable task, that, upon completion, indicates that the permissions have been successfully applied by the server.
 /// </returns>
 /// <param name="condition">A <see cref="PermissionCondition"/> that will be used to match existing users against.</param>
 /// <param name="realmUrl">The Realm URL whose permissions settings should be changed. Use <c>*</c> to change the permissions of all Realms managed by this <see cref="User"/>.</param>
 /// <param name="accessLevel">
 /// The access level to grant matching users. Note that the access level setting is absolute, i.e. it may revoke permissions for users that
 /// previously had a higher access level. To revoke all permissions, use <see cref="AccessLevel.None" />
 /// </param>
 public Task ApplyPermissionsAsync(PermissionCondition condition, string realmUrl, AccessLevel accessLevel)
 {
     RealmPCLHelpers.ThrowProxyShouldNeverBeUsed();
     return(null);
 }