diff options
| author | Danail Dimitrov <danaildimitrov321@gmail.com> | 2021-02-04 18:50:19 +0200 |
|---|---|---|
| committer | Danail Dimitrov <danaildimitrov321@gmail.com> | 2021-02-04 18:50:19 +0200 |
| commit | 7d288f0a353c0bf075f5bcb4d9fd44aac121c912 (patch) | |
| tree | 6f4e4ee8de64f015076b3e1005720300130c9b2b /src/DevHive.Services/Services/CommentService.cs | |
| parent | 5d6e3c5518fdbace4b049f9043fb140e150fdaa6 (diff) | |
| parent | ebf48cc5ad48199f0af9b8535c395b28f32b73a6 (diff) | |
| download | DevHive-7d288f0a353c0bf075f5bcb4d9fd44aac121c912.tar DevHive-7d288f0a353c0bf075f5bcb4d9fd44aac121c912.tar.gz DevHive-7d288f0a353c0bf075f5bcb4d9fd44aac121c912.zip | |
Merge branch 'dev' of https://github.com/Team-Kaleidoscope/DevHive into dev
Diffstat (limited to 'src/DevHive.Services/Services/CommentService.cs')
| -rw-r--r-- | src/DevHive.Services/Services/CommentService.cs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/DevHive.Services/Services/CommentService.cs b/src/DevHive.Services/Services/CommentService.cs index e6b0eb0..3584e3a 100644 --- a/src/DevHive.Services/Services/CommentService.cs +++ b/src/DevHive.Services/Services/CommentService.cs @@ -103,6 +103,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); @@ -110,6 +113,11 @@ namespace DevHive.Services.Services return user.Id == userId; } + /// <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) ?? @@ -126,6 +134,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)); @@ -139,7 +150,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(); |
