Ejemplo n.º 1
0
        /// <summary>
        /// Gets the permission a user has to access a resource.
        /// </summary>
        /// <param name="userSecret">The user secret.</param>
        /// <param name="paratextId">The paratext resource identifier.</param>
        /// <param name="userId">The user identifier.</param>
        /// <returns>
        /// A dictionary of permissions where the key is the user ID and the value is the permission
        /// </returns>
        /// <remarks>
        /// See <see cref="TextInfoPermission" /> for permission values.
        /// </remarks>
        public async Task <string> GetResourcePermissionAsync(UserSecret userSecret, string paratextId, string userId)
        {
            // See if the source is a resource
            if (paratextId.Length == SFInstallableDblResource.ResourceIdentifierLength)
            {
                // The resource id is a 41 character project id truncated to 16 characters
                UserSecret thisUserSecret;
                if (userId == userSecret.Id)
                {
                    thisUserSecret = userSecret;
                }
                else
                {
                    // Get the user secret
                    Attempt <UserSecret> userSecretAttempt = await this._userSecretRepository.TryGetAsync(userId);

                    if (!userSecretAttempt.TryResult(out thisUserSecret))
                    {
                        thisUserSecret = null;
                    }
                }

                bool canRead = false;
                if (thisUserSecret != null)
                {
                    if (!(thisUserSecret.ParatextTokens?.ValidateLifetime() ?? false))
                    {
                        await this.RefreshAccessTokenAsync(thisUserSecret);
                    }

                    canRead = SFInstallableDblResource.CheckResourcePermission(
                        paratextId,
                        thisUserSecret,
                        this._paratextOptions.Value,
                        this._restClientFactory,
                        this._fileSystemService,
                        this._jwtTokenHelper,
                        _exceptionHandler,
                        this._dblServerUri);
                }

                return(canRead ? TextInfoPermission.Read : TextInfoPermission.None);
            }
            else
            {
                // Default to no permissions for projects used as sources
                return(TextInfoPermission.None);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the permission a user has to access a resource.
 /// </summary>
 /// <param name="paratextId">The paratext resource identifier.</param>
 /// <param name="userId">The user identifier.</param>
 /// <returns>
 /// A dictionary of permissions where the key is the user ID and the value is the permission
 /// </returns>
 /// <remarks>
 /// See <see cref="TextInfoPermission" /> for permission values.
 /// </remarks>
 public async Task <string> GetResourcePermissionAsync(string paratextId, string userId)
 {
     // See if the source is a resource
     if (paratextId.Length != SFInstallableDblResource.ResourceIdentifierLength)
     {
         // Default to no permissions for projects used as sources
         return(TextInfoPermission.None);
     }
     using (ParatextAccessLock accessLock = await GetParatextAccessLock(userId))
     {
         bool canRead = SFInstallableDblResource.CheckResourcePermission(
             paratextId,
             accessLock.UserSecret,
             _paratextOptions.Value,
             _restClientFactory,
             _fileSystemService,
             _jwtTokenHelper,
             _exceptionHandler,
             _dblServerUri);
         return(canRead ? TextInfoPermission.Read : TextInfoPermission.None);
     }
 }