Inheritance: RealmObject, IPermissionObject
Beispiel #1
0
        /// <summary>
        /// Generates a token that can be used for sharing a Realm.
        /// </summary>
        /// <returns>
        /// A token that can be shared with another user, e.g. via email or message and then consumed by
        /// <see cref="AcceptPermissionOfferAsync"/> to obtain permissions to a Realm.</returns>
        /// <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>
        /// <param name="expiresAt">Optional expiration date of the offer. If set to <c>null</c>, the offer doesn't expire.</param>
        public async Task <string> OfferPermissionsAsync(string realmUrl, AccessLevel accessLevel, DateTimeOffset?expiresAt = null)
        {
            if (string.IsNullOrEmpty(realmUrl))
            {
                throw new ArgumentNullException(nameof(realmUrl));
            }

            if (expiresAt < DateTimeOffset.UtcNow)
            {
                throw new ArgumentException("The expiration date may not be in the past", nameof(expiresAt));
            }

            if (accessLevel == AccessLevel.None)
            {
                throw new ArgumentException("The access level may not be None", nameof(accessLevel));
            }

            var offer = new PermissionOffer(realmUrl,
                                            accessLevel >= AccessLevel.Read,
                                            accessLevel >= AccessLevel.Write,
                                            accessLevel >= AccessLevel.Admin,
                                            expiresAt);

            await WriteToManagementRealmAsync(offer);

            return(offer.Token);
        }
Beispiel #2
0
        /// <summary>
        /// Invalidates a permission offer.
        /// </summary>
        /// <remarks>
        /// Invalidating an offer prevents new users from consuming its token. It doesn't revoke any permissions that have
        /// already been granted.
        /// </remarks>
        /// <returns>
        /// An awaitable task, that, upon completion, indicates that the offer has been successfully invalidated by the server.
        /// </returns>
        /// <param name="offer">The offer that should be invalidated.</param>
        public Task InvalidateOfferAsync(PermissionOffer offer)
        {
            var tcs = new TaskCompletionSource <object>();

            ManagementRealm.Write(() =>
            {
                offer.ExpiresAt = DateTimeOffset.UtcNow;
            });

            var progressObservable = ManagementRealm.GetSession().GetProgressObservable(ProgressDirection.Upload, ProgressMode.ForCurrentlyOutstandingWork);
            var observer           = new Observer <SyncProgress>(onCompleted: () => tcs.TrySetResult(null), onError: ex => tcs.TrySetException(ex));

            progressObservable.Subscribe(observer);
            return(tcs.Task);
        }
Beispiel #3
0
        /// <summary>
        /// Invalidates a permission offer.
        /// </summary>
        /// <remarks>
        /// Invalidating an offer prevents new users from consuming its token. It doesn't revoke any permissions that have
        /// already been granted.
        /// </remarks>
        /// <returns>
        /// An awaitable task, that, upon completion, indicates that the offer has been successfully invalidated by the server.
        /// </returns>
        /// <param name="offer">The offer that should be invalidated.</param>
        public async Task InvalidateOfferAsync(PermissionOffer offer)
        {
            var tcs = new TaskCompletionSource <object>();

            ManagementRealm.Write(() => offer.ExpiresAt = DateTimeOffset.UtcNow);

            var session = ManagementRealm.GetSession();

            try
            {
                await session.WaitForUploadAsync();
            }
            finally
            {
                session.CloseHandle();
            }
        }
Beispiel #4
0
 /// <summary>
 /// Invalidates a permission offer.
 /// </summary>
 /// <remarks>
 /// Invalidating an offer prevents new users from consuming its token. It doesn't revoke any permissions that have
 /// already been granted.
 /// </remarks>
 /// <returns>
 /// An awaitable task, that, upon completion, indicates that the offer has been successfully invalidated by the server.
 /// </returns>
 /// <param name="offer">The offer that should be invalidated.</param>
 public Task InvalidateOfferAsync(PermissionOffer offer)
 {
     RealmPCLHelpers.ThrowProxyShouldNeverBeUsed();
     return(null);
 }
Beispiel #5
0
 public Task InvalidateOfferAsync(PermissionOffer offer) => InvalidateOfferAsync(offer.Token);