From 1200e6ed7b8a854a98e62f1e619204c89a1dce20 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vojt=C4=9Bch=20Barti=C4=8Dka?= <aitakaitov@gmail.com>
Date: Sun, 10 Apr 2022 11:35:57 +0200
Subject: [PATCH 1/6] Moved Enums to Models project

---
 Backend/Backend/Controllers/DocumentController.cs  | 4 ++--
 Backend/Core/Entities/Annotation.cs                | 2 +-
 Backend/Core/Entities/User.cs                      | 2 +-
 Backend/Core/Seeding/Seeder.cs                     | 2 +-
 Backend/Core/Services/UserService/IUserService.cs  | 2 +-
 Backend/Core/Services/UserService/UserServiceEF.cs | 2 +-
 Backend/Models/Authentication/LoginResponse.cs     | 3 +++
 Backend/{Core => Models}/Enums/ERole.cs            | 2 +-
 Backend/{Core => Models}/Enums/EState.cs           | 2 +-
 9 files changed, 12 insertions(+), 9 deletions(-)
 rename Backend/{Core => Models}/Enums/ERole.cs (90%)
 rename Backend/{Core => Models}/Enums/EState.cs (90%)

diff --git a/Backend/Backend/Controllers/DocumentController.cs b/Backend/Backend/Controllers/DocumentController.cs
index 6a465f5..64a731b 100644
--- a/Backend/Backend/Controllers/DocumentController.cs
+++ b/Backend/Backend/Controllers/DocumentController.cs
@@ -35,7 +35,7 @@ public class DocumentController : Common.CommonControllerBase
             return Problem();
         }
 
-        if (clientInfo.LoggedUser.Role != Core.Enums.ERole.ADMINISTRATOR)
+        if (clientInfo.LoggedUser.Role != Models.Enums.ERole.ADMINISTRATOR)
         {
             return Forbid("User is not administrator");
         }
@@ -56,7 +56,7 @@ public class DocumentController : Common.CommonControllerBase
             return Problem();
         }
 
-        if (clientInfo.LoggedUser.Role != Core.Enums.ERole.ADMINISTRATOR)
+        if (clientInfo.LoggedUser.Role != Models.Enums.ERole.ADMINISTRATOR)
         {
             return Forbid("User is not administrator");
         }
diff --git a/Backend/Core/Entities/Annotation.cs b/Backend/Core/Entities/Annotation.cs
index 88867ac..2128354 100644
--- a/Backend/Core/Entities/Annotation.cs
+++ b/Backend/Core/Entities/Annotation.cs
@@ -1,4 +1,4 @@
-using Core.Enums;
+using Models.Enums;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
diff --git a/Backend/Core/Entities/User.cs b/Backend/Core/Entities/User.cs
index 3ef23e3..4e60155 100644
--- a/Backend/Core/Entities/User.cs
+++ b/Backend/Core/Entities/User.cs
@@ -5,7 +5,7 @@ using System.Linq;
 using System.Text;
 using System.Text.Json.Serialization;
 using System.Threading.Tasks;
-using Core.Enums;
+using Models.Enums;
 
 namespace Core.Entities
 {
diff --git a/Backend/Core/Seeding/Seeder.cs b/Backend/Core/Seeding/Seeder.cs
index d6fb105..1b1e954 100644
--- a/Backend/Core/Seeding/Seeder.cs
+++ b/Backend/Core/Seeding/Seeder.cs
@@ -1,6 +1,6 @@
 using Core.Contexts;
 using Core.Entities;
-using Core.Enums;
+using Models.Enums;
 using Microsoft.EntityFrameworkCore;
 using System;
 using System.Collections.Generic;
diff --git a/Backend/Core/Services/UserService/IUserService.cs b/Backend/Core/Services/UserService/IUserService.cs
index 7bacc6d..96b3457 100644
--- a/Backend/Core/Services/UserService/IUserService.cs
+++ b/Backend/Core/Services/UserService/IUserService.cs
@@ -1,5 +1,5 @@
 using Core.Entities;
-using Core.Enums;
+using Models.Enums;
 using System;
 using System.Collections.Generic;
 using System.Linq;
diff --git a/Backend/Core/Services/UserService/UserServiceEF.cs b/Backend/Core/Services/UserService/UserServiceEF.cs
index 35103dc..c3ca409 100644
--- a/Backend/Core/Services/UserService/UserServiceEF.cs
+++ b/Backend/Core/Services/UserService/UserServiceEF.cs
@@ -1,6 +1,6 @@
 using Core.Contexts;
 using Core.Entities;
-using Core.Enums;
+using Models.Enums;
 using System;
 using System.Collections.Generic;
 using System.Linq;
diff --git a/Backend/Models/Authentication/LoginResponse.cs b/Backend/Models/Authentication/LoginResponse.cs
index 4fe0068..5ce4aab 100644
--- a/Backend/Models/Authentication/LoginResponse.cs
+++ b/Backend/Models/Authentication/LoginResponse.cs
@@ -1,3 +1,5 @@
+using Models.Enums;
+
 namespace Models.Authentication;
 
 public class LoginResponse
@@ -17,4 +19,5 @@ public class LoginResponse
     public bool Ok { get; set; }
     public string Token { get; set; }
     public DateTime Expiration { get; set; }
+    public ERole Role { get; set; }
 }
\ No newline at end of file
diff --git a/Backend/Core/Enums/ERole.cs b/Backend/Models/Enums/ERole.cs
similarity index 90%
rename from Backend/Core/Enums/ERole.cs
rename to Backend/Models/Enums/ERole.cs
index 2a5d70d..ea130a0 100644
--- a/Backend/Core/Enums/ERole.cs
+++ b/Backend/Models/Enums/ERole.cs
@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace Core.Enums
+namespace Models.Enums
 {
     public enum ERole : int
     {
diff --git a/Backend/Core/Enums/EState.cs b/Backend/Models/Enums/EState.cs
similarity index 90%
rename from Backend/Core/Enums/EState.cs
rename to Backend/Models/Enums/EState.cs
index 61977e5..69ab18a 100644
--- a/Backend/Core/Enums/EState.cs
+++ b/Backend/Models/Enums/EState.cs
@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace Core.Enums
+namespace Models.Enums
 {
     public enum EState
     {
-- 
GitLab


From b782f829d692bf99f213ad6ddba46e95c3a31053 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vojt=C4=9Bch=20Barti=C4=8Dka?= <aitakaitov@gmail.com>
Date: Sun, 10 Apr 2022 11:38:17 +0200
Subject: [PATCH 2/6] Authentication controller now returns user role

---
 Backend/Core/Services/AuthService/AuthService.cs | 2 +-
 Backend/Models/Authentication/LoginResponse.cs   | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/Backend/Core/Services/AuthService/AuthService.cs b/Backend/Core/Services/AuthService/AuthService.cs
index 9ddc136..4189b7a 100644
--- a/Backend/Core/Services/AuthService/AuthService.cs
+++ b/Backend/Core/Services/AuthService/AuthService.cs
@@ -28,7 +28,7 @@ public class AuthService : IAuthService
         var expiration = DateTime.Now.AddHours(12);
         var token = jwtUtils.GenerateJwtToken(user, expiration);
 
-        var loginResult = new LoginResponse(true, token, expiration);
+        var loginResult = new LoginResponse(true, token, expiration, user.Role);
 
         return loginResult;
     }
diff --git a/Backend/Models/Authentication/LoginResponse.cs b/Backend/Models/Authentication/LoginResponse.cs
index 5ce4aab..aa0248a 100644
--- a/Backend/Models/Authentication/LoginResponse.cs
+++ b/Backend/Models/Authentication/LoginResponse.cs
@@ -4,11 +4,12 @@ namespace Models.Authentication;
 
 public class LoginResponse
 {
-    public LoginResponse(bool ok, string token, DateTime expiration)
+    public LoginResponse(bool ok, string token, DateTime expiration, ERole role)
     {
         Ok = ok;
         Token = token;
         Expiration = expiration;
+        Role = role;
     }
 
     public LoginResponse()
-- 
GitLab


From cd91f8413868690fc6813d9f867e41266e82ddd1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vojt=C4=9Bch=20Barti=C4=8Dka?= <aitakaitov@gmail.com>
Date: Sun, 10 Apr 2022 11:35:57 +0200
Subject: [PATCH 3/6] Moved Enums to Models project

---
 Backend/Core/Entities/Annotation.cs                | 2 +-
 Backend/Core/Entities/User.cs                      | 2 +-
 Backend/Core/Seeding/Seeder.cs                     | 2 +-
 Backend/Core/Services/UserService/IUserService.cs  | 2 +-
 Backend/Core/Services/UserService/UserServiceEF.cs | 2 +-
 Backend/Models/Authentication/LoginResponse.cs     | 3 +++
 Backend/{Core => Models}/Enums/ERole.cs            | 2 +-
 Backend/{Core => Models}/Enums/EState.cs           | 2 +-
 8 files changed, 10 insertions(+), 7 deletions(-)
 rename Backend/{Core => Models}/Enums/ERole.cs (90%)
 rename Backend/{Core => Models}/Enums/EState.cs (90%)

diff --git a/Backend/Core/Entities/Annotation.cs b/Backend/Core/Entities/Annotation.cs
index 88867ac..2128354 100644
--- a/Backend/Core/Entities/Annotation.cs
+++ b/Backend/Core/Entities/Annotation.cs
@@ -1,4 +1,4 @@
-using Core.Enums;
+using Models.Enums;
 using System;
 using System.Collections.Generic;
 using System.ComponentModel.DataAnnotations;
diff --git a/Backend/Core/Entities/User.cs b/Backend/Core/Entities/User.cs
index 3ef23e3..4e60155 100644
--- a/Backend/Core/Entities/User.cs
+++ b/Backend/Core/Entities/User.cs
@@ -5,7 +5,7 @@ using System.Linq;
 using System.Text;
 using System.Text.Json.Serialization;
 using System.Threading.Tasks;
-using Core.Enums;
+using Models.Enums;
 
 namespace Core.Entities
 {
diff --git a/Backend/Core/Seeding/Seeder.cs b/Backend/Core/Seeding/Seeder.cs
index d6fb105..1b1e954 100644
--- a/Backend/Core/Seeding/Seeder.cs
+++ b/Backend/Core/Seeding/Seeder.cs
@@ -1,6 +1,6 @@
 using Core.Contexts;
 using Core.Entities;
-using Core.Enums;
+using Models.Enums;
 using Microsoft.EntityFrameworkCore;
 using System;
 using System.Collections.Generic;
diff --git a/Backend/Core/Services/UserService/IUserService.cs b/Backend/Core/Services/UserService/IUserService.cs
index 7bacc6d..96b3457 100644
--- a/Backend/Core/Services/UserService/IUserService.cs
+++ b/Backend/Core/Services/UserService/IUserService.cs
@@ -1,5 +1,5 @@
 using Core.Entities;
-using Core.Enums;
+using Models.Enums;
 using System;
 using System.Collections.Generic;
 using System.Linq;
diff --git a/Backend/Core/Services/UserService/UserServiceEF.cs b/Backend/Core/Services/UserService/UserServiceEF.cs
index 35103dc..c3ca409 100644
--- a/Backend/Core/Services/UserService/UserServiceEF.cs
+++ b/Backend/Core/Services/UserService/UserServiceEF.cs
@@ -1,6 +1,6 @@
 using Core.Contexts;
 using Core.Entities;
-using Core.Enums;
+using Models.Enums;
 using System;
 using System.Collections.Generic;
 using System.Linq;
diff --git a/Backend/Models/Authentication/LoginResponse.cs b/Backend/Models/Authentication/LoginResponse.cs
index 4fe0068..5ce4aab 100644
--- a/Backend/Models/Authentication/LoginResponse.cs
+++ b/Backend/Models/Authentication/LoginResponse.cs
@@ -1,3 +1,5 @@
+using Models.Enums;
+
 namespace Models.Authentication;
 
 public class LoginResponse
@@ -17,4 +19,5 @@ public class LoginResponse
     public bool Ok { get; set; }
     public string Token { get; set; }
     public DateTime Expiration { get; set; }
+    public ERole Role { get; set; }
 }
\ No newline at end of file
diff --git a/Backend/Core/Enums/ERole.cs b/Backend/Models/Enums/ERole.cs
similarity index 90%
rename from Backend/Core/Enums/ERole.cs
rename to Backend/Models/Enums/ERole.cs
index 2a5d70d..ea130a0 100644
--- a/Backend/Core/Enums/ERole.cs
+++ b/Backend/Models/Enums/ERole.cs
@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace Core.Enums
+namespace Models.Enums
 {
     public enum ERole : int
     {
diff --git a/Backend/Core/Enums/EState.cs b/Backend/Models/Enums/EState.cs
similarity index 90%
rename from Backend/Core/Enums/EState.cs
rename to Backend/Models/Enums/EState.cs
index 61977e5..69ab18a 100644
--- a/Backend/Core/Enums/EState.cs
+++ b/Backend/Models/Enums/EState.cs
@@ -4,7 +4,7 @@ using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 
-namespace Core.Enums
+namespace Models.Enums
 {
     public enum EState
     {
-- 
GitLab


From f0fde45c7ea4d694330daaa390db5e1affb30220 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vojt=C4=9Bch=20Barti=C4=8Dka?= <aitakaitov@gmail.com>
Date: Sun, 10 Apr 2022 11:38:17 +0200
Subject: [PATCH 4/6] Authentication controller now returns user role

---
 Backend/Core/Services/AuthService/AuthService.cs | 2 +-
 Backend/Models/Authentication/LoginResponse.cs   | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/Backend/Core/Services/AuthService/AuthService.cs b/Backend/Core/Services/AuthService/AuthService.cs
index 9ddc136..4189b7a 100644
--- a/Backend/Core/Services/AuthService/AuthService.cs
+++ b/Backend/Core/Services/AuthService/AuthService.cs
@@ -28,7 +28,7 @@ public class AuthService : IAuthService
         var expiration = DateTime.Now.AddHours(12);
         var token = jwtUtils.GenerateJwtToken(user, expiration);
 
-        var loginResult = new LoginResponse(true, token, expiration);
+        var loginResult = new LoginResponse(true, token, expiration, user.Role);
 
         return loginResult;
     }
diff --git a/Backend/Models/Authentication/LoginResponse.cs b/Backend/Models/Authentication/LoginResponse.cs
index 5ce4aab..aa0248a 100644
--- a/Backend/Models/Authentication/LoginResponse.cs
+++ b/Backend/Models/Authentication/LoginResponse.cs
@@ -4,11 +4,12 @@ namespace Models.Authentication;
 
 public class LoginResponse
 {
-    public LoginResponse(bool ok, string token, DateTime expiration)
+    public LoginResponse(bool ok, string token, DateTime expiration, ERole role)
     {
         Ok = ok;
         Token = token;
         Expiration = expiration;
+        Role = role;
     }
 
     public LoginResponse()
-- 
GitLab


From 52fe46f9b3ef7cff3a81c4d88c77415308a195fa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vojt=C4=9Bch=20Barti=C4=8Dka?= <aitakaitov@gmail.com>
Date: Mon, 11 Apr 2022 17:48:58 +0200
Subject: [PATCH 5/6] Minor fix

---
 Backend/Core/Services/DocumentService/DocumentServiceEF.cs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Backend/Core/Services/DocumentService/DocumentServiceEF.cs b/Backend/Core/Services/DocumentService/DocumentServiceEF.cs
index 5eee86c..3299579 100644
--- a/Backend/Core/Services/DocumentService/DocumentServiceEF.cs
+++ b/Backend/Core/Services/DocumentService/DocumentServiceEF.cs
@@ -42,7 +42,7 @@ namespace Core.Services.DocumentService
 
             foreach (var documentInfo in request.Documents)
             {
-                if (documentInfo.Format == Models.Enums.EAddDocumentFormat.PLAINTEXT)
+                if (documentInfo.Format == Models.Enums.EAddDocumentFormat.TEXTFILE)
                 {
                     // TODO hardcoded UTF-8 - maybe do something smarter
                     var documentContent = Encoding.UTF8.GetString(Convert.FromBase64String(documentInfo.Content));
-- 
GitLab


From 23165326186aab422b0f1050ac4e6ea93ab4942d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vojt=C4=9Bch=20Barti=C4=8Dka?= <aitakaitov@gmail.com>
Date: Mon, 11 Apr 2022 17:52:01 +0200
Subject: [PATCH 6/6] Fixed problems after a merge

---
 Backend/Backend/Authentication/AuthorizationAttribute.cs | 2 +-
 Backend/Backend/Controllers/DocumentController.cs        | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/Backend/Backend/Authentication/AuthorizationAttribute.cs b/Backend/Backend/Authentication/AuthorizationAttribute.cs
index 2c3f125..d058acb 100644
--- a/Backend/Backend/Authentication/AuthorizationAttribute.cs
+++ b/Backend/Backend/Authentication/AuthorizationAttribute.cs
@@ -1,5 +1,5 @@
 using Core.Entities;
-using Core.Enums;
+using Models.Enums;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.AspNetCore.Mvc.Filters;
diff --git a/Backend/Backend/Controllers/DocumentController.cs b/Backend/Backend/Controllers/DocumentController.cs
index 43ec53c..9596176 100644
--- a/Backend/Backend/Controllers/DocumentController.cs
+++ b/Backend/Backend/Controllers/DocumentController.cs
@@ -25,7 +25,7 @@ public class DocumentController : Common.CommonControllerBase
     }
 
     [HttpGet("/documents")]
-    [Authorize(Core.Enums.ERole.ADMINISTRATOR)]
+    [Authorize(Models.Enums.ERole.ADMINISTRATOR)]
     [ProducesResponseType((int)HttpStatusCode.OK)]
     [ProducesResponseType((int)HttpStatusCode.Forbidden)]
     public ActionResult<DocumentListResponse> GetDocuments([FromServices] ClientInfo clientInfo, [FromBody] DocumentListRequest documentListRequest)
@@ -40,7 +40,7 @@ public class DocumentController : Common.CommonControllerBase
     }
 
     [HttpPost("/documents")]
-    [Authorize(Core.Enums.ERole.ADMINISTRATOR)]
+    [Authorize(Models.Enums.ERole.ADMINISTRATOR)]
     [ProducesResponseType((int)HttpStatusCode.OK)]
     [ProducesResponseType((int)HttpStatusCode.Forbidden)]
     public ActionResult PostDocuments([FromServices] ClientInfo clientInfo, [FromBody] DocumentAddRequest documentAddRequest)
-- 
GitLab