diff options
Diffstat (limited to 'src/DevHive.Services/Services/PostService.cs')
| -rw-r--r-- | src/DevHive.Services/Services/PostService.cs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index 3f98333..51f4d00 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -138,6 +138,9 @@ namespace DevHive.Services.Services #endregion #region Validations + /// <summary> + /// Checks whether the user Id in the token and the given user Id match + /// </summary> public async Task<bool> ValidateJwtForCreating(Guid userId, string rawTokenData) { User user = await this.GetUserForValidation(rawTokenData); @@ -145,6 +148,11 @@ namespace DevHive.Services.Services return user.Id == userId; } + /// <summary> + /// Checks whether the post, gotten with the postId, + /// is made by the user in the token + /// or if the user in the token is an admin + /// </summary> public async Task<bool> ValidateJwtForPost(Guid postId, string rawTokenData) { Post post = await this._postRepository.GetByIdAsync(postId) ?? @@ -161,6 +169,11 @@ namespace DevHive.Services.Services return false; } + /// <summary> + /// Checks whether the comment, gotten with the commentId, + /// is made by the user in the token + /// or if the user in the token is an admin + /// </summary> public async Task<bool> ValidateJwtForComment(Guid commentId, string rawTokenData) { Comment comment = await this._commentRepository.GetByIdAsync(commentId) ?? @@ -177,6 +190,9 @@ namespace DevHive.Services.Services return false; } + /// <summary> + /// Returns the user, via their Id in the token + /// </summary> private async Task<User> GetUserForValidation(string rawTokenData) { JwtSecurityToken jwt = new JwtSecurityTokenHandler().ReadJwtToken(rawTokenData.Remove(0, 7)); @@ -190,6 +206,9 @@ namespace DevHive.Services.Services return user; } + /// <summary> + /// Returns all values from a given claim type + /// </summary> private List<string> GetClaimTypeValues(string type, IEnumerable<Claim> claims) { List<string> toReturn = new(); |
