Преглед на файлове

处理字符串==。equals

CrazyIter_Bin преди 3 години
родител
ревизия
42245aa575

+ 1 - 1
TEAMModelAPI/ApiTokenAttribute.cs

@@ -46,7 +46,7 @@ namespace TEAMModelOS.Filter
                     id = jwt.Payload.Sub;
                     school = jwt.Payload.Azp;
                     jti = jwt.Payload.Jti;
-                    name = jwt.Claims.FirstOrDefault(claim => claim.Type == "name")?.Value;
+                    name = jwt.Claims.FirstOrDefault(claim => claim.Type.Equals("name"))?.Value;
                     //处理限流问题
                     if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(school) && !string.IsNullOrEmpty(name)&& !string.IsNullOrEmpty(jti))
                     {

+ 2 - 2
TEAMModelAPI/Startup.cs

@@ -53,8 +53,8 @@ namespace TEAMModelAPI
                     //options.Events.OnAuthenticationFailed = async context => { await Task.FromResult(0); };
                     options.Events.OnTokenValidated = async context =>
                     {
-                        if (!context.Principal.Claims.Any(x => x.Type == "http://schemas.microsoft.com/identity/claims/scope") //ClaimConstants.Scope
-                        && !context.Principal.Claims.Any(y => y.Type == "roles")) //ClaimConstants.Roles //http://schemas.microsoft.com/ws/2008/06/identity/claims/role
+                        if (!context.Principal.Claims.Any(x => x.Type.Equals("http://schemas.microsoft.com/identity/claims/scope")) //ClaimConstants.Scope
+                        && !context.Principal.Claims.Any(y => y.Type .Equals("roles"))) //ClaimConstants.Roles //http://schemas.microsoft.com/ws/2008/06/identity/claims/role
                         {
                             //TODO 需處理額外授權非角色及範圍的訪問異常紀錄
                             throw new UnauthorizedAccessException("Neither scope or roles claim was found in the bearer token.");

+ 1 - 1
TEAMModelFunction/TriggerCorrect.cs

@@ -27,7 +27,7 @@ namespace TEAMModelFunction
             var adid = tdata.id;
             var adcode = "";
             string blobcntr = null;
-            if (tdata.scope == "school")
+            if (tdata.scope.Equals("school"))
             {
                 adcode = $"Activity-{tdata.school}";
                 blobcntr = tdata.school;

+ 2 - 2
TEAMModelFunction/TriggerSurvey.cs

@@ -34,12 +34,12 @@ namespace TEAMModelFunction
                 var adid = tdata.id;
                 var adcode = "";
                 string blobcntr = null;
-                if (tdata.scope == "school")
+                if (tdata.scope .Equals("school") )
                 {
                     adcode = $"Activity-{tdata.school}";
                     blobcntr = tdata.school;
                 }
-                else if (tdata.scope == "private")
+                else if (tdata.scope .Equals("private"))
                 {
                     adcode = $"Activity-{tdata.creatorId}";
                     blobcntr = tdata.creatorId;

+ 2 - 2
TEAMModelFunction/TriggerVote.cs

@@ -32,12 +32,12 @@ namespace TEAMModelFunction
                 var adid = tdata.id;
                 var adcode = "";
                 string blobcntr = null;
-                if (tdata.scope == "school")
+                if (tdata.scope .Equals("school"))
                 {
                     adcode = $"Activity-{tdata.school}";
                     blobcntr = tdata.school;
                 }
-                else if (tdata.scope == "private")
+                else if (tdata.scope.Equals("private"))
                 {
                     adcode = $"Activity-{tdata.creatorId}";
                     blobcntr = tdata.creatorId;

+ 1 - 1
TEAMModelOS.SDK/DI/AzureStorage/AzureStorageFactory.cs

@@ -137,7 +137,7 @@ namespace TEAMModelOS.SDK.DI
                 var accountname = keys["AccountName"];
                 var accountkey = keys["AccountKey"];
                 var endpoint = keys["EndpointSuffix"];
-                if (blobSas.role == "system")
+                if (blobSas.role.Equals("system"))
                 {
                     containerName = "teammodelos";
                 }

+ 3 - 3
TEAMModelOS/Controllers/Client/HiScanController.cs

@@ -92,7 +92,7 @@ namespace TEAMModelOS.Controllers.Core
                     {
                         string statusNow = obj.GetProperty("status").ToString();
                         //正式加入才会有
-                        if (statusNow == "join")
+                        if (statusNow .Equals("join"))
                         {
                             //dynamic schoolExtobj = new ExpandoObject();
                             var schoolJson = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync($"{obj.GetProperty("schoolId")}", new PartitionKey("Base"));
@@ -192,7 +192,7 @@ namespace TEAMModelOS.Controllers.Core
                 List<SheetConfig> configsN = new List<SheetConfig>();
                 foreach (var config in configs)
                 {
-                    if (config.scope == "school")
+                    if (config.scope .Equals("school"))
                     {
                         try
                         {
@@ -297,7 +297,7 @@ namespace TEAMModelOS.Controllers.Core
                 {
                     if (!string.IsNullOrEmpty(pap.sheet))
                     {
-                        if (exam.scope == "school")
+                        if (exam.scope .Equals("school"))
                         {
                             SheetConfig config = new SheetConfig { id = pap.sheet, scope = exam.scope, code = $"SheetConfig-{exam.school}" };
                             dys.Add(new PaperRcd { name = pap.name, answers = pap.answers, point = pap.point, sheet = config });

+ 10 - 10
TEAMModelOS/Controllers/Client/HiTeachController.cs

@@ -610,12 +610,12 @@ namespace TEAMModelOS.Controllers.Client
                 string queryWhere = " WHERE 1=1 ";
                 string queryOption = string.Empty;
                 //學段
-                if (request.TryGetProperty("periodId", out JsonElement periodId) && container == "School")
+                if (request.TryGetProperty("periodId", out JsonElement periodId) && container .Equals("School") )
                 {
                     queryWhere += $" AND c.periodId = '{periodId}'";
                 }
                 //年級
-                if (request.TryGetProperty("gradeId", out JsonElement gradeIds) && gradeIds.GetArrayLength() > 0 && container == "School")
+                if (request.TryGetProperty("gradeId", out JsonElement gradeIds) && gradeIds.GetArrayLength() > 0 && container .Equals("School"))
                 {
                     string queryOptionForGrade = string.Empty;
                     for (int i = 0; i < gradeIds.GetArrayLength(); i++)
@@ -629,7 +629,7 @@ namespace TEAMModelOS.Controllers.Client
                     queryWhere += $" AND ( {queryOptionForGrade} )"; 
                 }
                 //科目ID
-                if (request.TryGetProperty("subjectId", out JsonElement subjectId) && container == "School")
+                if (request.TryGetProperty("subjectId", out JsonElement subjectId) && container .Equals("School"))
                 {
                     queryWhere += $" AND c.subjectId = '{subjectId}'";
                 }
@@ -715,7 +715,7 @@ namespace TEAMModelOS.Controllers.Client
                 if (!request.TryGetProperty("grant_type", out JsonElement grant_type)) return BadRequest();
                 string partitionid = string.Empty;
                 string container = string.Empty;
-                if (grant_type.ToString() == "school")
+                if (grant_type.ToString().Equals("school"))
                 {
                     if (!request.TryGetProperty("school_code", out JsonElement school_code_json))
                     {
@@ -737,12 +737,12 @@ namespace TEAMModelOS.Controllers.Client
                 string queryWhere = " WHERE 1=1 ";
                 string queryOption = string.Empty;
                 //學段
-                if (request.TryGetProperty("periodId", out JsonElement periodId) && container == "School")
+                if (request.TryGetProperty("periodId", out JsonElement periodId) && container .Equals("School"))
                 {
                     queryWhere += $" AND c.periodId = '{periodId}'";
                 }
                 //年級
-                if (request.TryGetProperty("gradeId", out JsonElement gradeIds) && gradeIds.GetArrayLength() > 0 && container == "School")
+                if (request.TryGetProperty("gradeId", out JsonElement gradeIds) && gradeIds.GetArrayLength() > 0 && container .Equals("School"))
                 {
                     string queryOptionForGrade = string.Empty;
                     for (int i = 0; i < gradeIds.GetArrayLength(); i++)
@@ -795,7 +795,7 @@ namespace TEAMModelOS.Controllers.Client
                 string order = "createTime"; //排序項目
                 if (request.TryGetProperty("order", out JsonElement order_json))
                 {
-                    if (order_json.ToString() == "useCount")
+                    if (order_json.ToString() .Equals("useCount"))
                     {
                         order = order_json.ToString();
                     }
@@ -920,13 +920,13 @@ namespace TEAMModelOS.Controllers.Client
             string stulist = Convert.ToString(stulist_id);
             if(string.IsNullOrWhiteSpace(classId) && string.IsNullOrWhiteSpace(stulist)) return BadRequest();
             request.TryGetProperty("school_code", out JsonElement school_code);
-            if (grant_type.GetString() == "school" && string.IsNullOrWhiteSpace(Convert.ToString(school_code))) return BadRequest();
+            if (grant_type.GetString() .Equals("school") && string.IsNullOrWhiteSpace(Convert.ToString(school_code))) return BadRequest();
 
             var client = _azureCosmos.GetCosmosClient();
             List<object> students = new List<object>();
-            string container = (grant_type.GetString() == "school") ? "School" : "Teacher";
+            string container = (grant_type.GetString() .Equals("school")) ? "School" : "Teacher";
             //Case 1 取得stulist成員 (有stulist_id則優先取)
-            if (grant_type.GetString() == "private" && string.IsNullOrWhiteSpace(stulist) && !string.IsNullOrWhiteSpace(classId)) //若private,且classId不為空,stulist為空,有可能HiTeach無法判別是若classId還是stulist
+            if (grant_type.GetString().Equals("private")  && string.IsNullOrWhiteSpace(stulist) && !string.IsNullOrWhiteSpace(classId)) //若private,且classId不為空,stulist為空,有可能HiTeach無法判別是若classId還是stulist
             {
                 stulist = classId;
             }

+ 2 - 0
TEAMModelOS/Controllers/Core/ImportController.cs

@@ -122,6 +122,7 @@ namespace TEAMModelOS.Controllers
                 if (ext.ToLower() == "pptx" || ext.ToLower() == "xml")
                 {
                     string index = await PPTXTranslator(containerid, FileName, stream);
+                    await _azureStorage.GetBlobServiceClient().DeleteBlobs(containerid, new List<string>() { FileName });
                     return Ok(new { index = index });
                 }
                 else if (ext.ToLower() == "docx" || ext.ToLower() == "doc")
@@ -131,6 +132,7 @@ namespace TEAMModelOS.Controllers
                 else if (ext.ToLower() == "htex")
                 {
                     var index = await HTEXTranslator(containerid, FileName, stream);
+                    await _azureStorage.GetBlobServiceClient().DeleteBlobs(containerid, new List<string>() { FileName });
                     return Ok(new { index = index });
                 }
                 else

+ 2 - 2
TEAMModelOS/Startup.cs

@@ -73,8 +73,8 @@ namespace TEAMModelOS
                     //options.Events.OnAuthenticationFailed = async context => { await Task.FromResult(0); };
                     options.Events.OnTokenValidated = async context =>
                     {
-                        if (!context.Principal.Claims.Any(x => x.Type == "http://schemas.microsoft.com/identity/claims/scope") //ClaimConstants.Scope
-                        && !context.Principal.Claims.Any(y => y.Type == "roles")) //ClaimConstants.Roles //http://schemas.microsoft.com/ws/2008/06/identity/claims/role
+                        if (!context.Principal.Claims.Any(x => x.Type .Equals("http://schemas.microsoft.com/identity/claims/scope")) //ClaimConstants.Scope
+                        && !context.Principal.Claims.Any(y => y.Type .Equals("roles"))) //ClaimConstants.Roles //http://schemas.microsoft.com/ws/2008/06/identity/claims/role
                         {
                             //TODO 需處理額外授權非角色及範圍的訪問異常紀錄
                             throw new UnauthorizedAccessException("Neither scope or roles claim was found in the bearer token.");