Skip to content

Commit

Permalink
Set AnalysisMode to Recommended, fix resulting warnings (#675)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinothamar authored Jun 11, 2024
1 parent 6a08e31 commit 3b7429d
Show file tree
Hide file tree
Showing 57 changed files with 269 additions and 130 deletions.
18 changes: 18 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ dotnet_diagnostic.CA1822.severity = suggestion
# IDE0080: Remove unnecessary suppression operator
dotnet_diagnostic.IDE0080.severity = error

# CA1716: Rename namespace "" so that it no longer conflicts with the reserved language keyword 'Interface'
# TODO: fixing this would be breaking
dotnet_diagnostic.CA1716.severity = suggestion

# CA1805: Do not initialize unnecessarily
dotnet_diagnostic.CA1805.severity = suggestion

# CA1711: Identifiers should not have incorrect suffix
# TODO: fixing this would be breaking
dotnet_diagnostic.CA1711.severity = suggestion

# CA2201: Do not raise reserved exception types
dotnet_diagnostic.CA2201.severity = suggestion

# CA1720: Identifier contains type name
# TODO: fixing this would be breaking
dotnet_diagnostic.CA1720.severity = suggestion

[Program.cs]
dotnet_diagnostic.CA1050.severity = none
dotnet_diagnostic.S1118.severity = none
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task<ActionResult<ApplicationMetadata>> GetAction(

string wantedAppId = $"{org}/{app}";

if (!checkOrgApp || application.Id.Equals(wantedAppId))
if (!checkOrgApp || application.Id.Equals(wantedAppId, StringComparison.Ordinal))
{
return Ok(application);
}
Expand All @@ -72,7 +72,7 @@ public async Task<ActionResult<string>> GetPolicy(string org, string app)
string policy = await _appMetadata.GetApplicationXACMLPolicy();
string wantedAppId = $"{org}/{app}";

if (application.Id.Equals(wantedAppId))
if (application.Id.Equals(wantedAppId, StringComparison.Ordinal))
{
return Content(policy, "text/xml", System.Text.Encoding.UTF8);
}
Expand Down Expand Up @@ -100,7 +100,7 @@ public async Task<ActionResult<string>> GetProcess(string org, string app)
string wantedAppId = $"{org}/{app}";
try
{
if (application.Id.Equals(wantedAppId))
if (application.Id.Equals(wantedAppId, StringComparison.Ordinal))
{
string process = await _appMetadata.GetApplicationBPMNProcess();
return Content(process, "text/xml", System.Text.Encoding.UTF8);
Expand Down
3 changes: 2 additions & 1 deletion src/Altinn.App.Api/Controllers/AuthorizationController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using Altinn.App.Core.Configuration;
using Altinn.App.Core.Helpers;
using Altinn.App.Core.Internal.Auth;
Expand Down Expand Up @@ -83,7 +84,7 @@ public async Task<ActionResult> GetCurrentParty(bool returnPartyObject = false)
{
Response.Cookies.Append(
_settings.GetAltinnPartyCookieName,
userContext.PartyId.ToString(),
userContext.PartyId.ToString(CultureInfo.InvariantCulture),
new CookieOptions { Domain = _settings.HostName }
);
}
Expand Down
40 changes: 26 additions & 14 deletions src/Altinn.App.Api/Controllers/DataController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.Net;
using System.Security.Claims;
using System.Text.Json;
Expand Down Expand Up @@ -133,7 +134,7 @@ [FromQuery] string dataType
Application application = await _appMetadata.GetApplicationMetadata();

DataType? dataTypeFromMetadata = application.DataTypes.First(e =>
e.Id.Equals(dataType, StringComparison.InvariantCultureIgnoreCase)
e.Id.Equals(dataType, StringComparison.OrdinalIgnoreCase)
);

if (dataTypeFromMetadata == null)
Expand Down Expand Up @@ -302,7 +303,9 @@ public async Task<ActionResult> Get(
return NotFound($"Did not find instance {instance}");
}

DataElement? dataElement = instance.Data.First(m => m.Id.Equals(dataGuid.ToString()));
DataElement? dataElement = instance.Data.First(m =>
m.Id.Equals(dataGuid.ToString(), StringComparison.Ordinal)
);

if (dataElement == null)
{
Expand Down Expand Up @@ -380,7 +383,9 @@ public async Task<ActionResult> Put(
);
}

DataElement? dataElement = instance.Data.First(m => m.Id.Equals(dataGuid.ToString()));
DataElement? dataElement = instance.Data.First(m =>
m.Id.Equals(dataGuid.ToString(), StringComparison.Ordinal)
);

if (dataElement == null)
{
Expand Down Expand Up @@ -459,7 +464,7 @@ public async Task<ActionResult<DataPatchResponse>> PatchFormData(
);
}

var dataElement = instance.Data.First(m => m.Id.Equals(dataGuid.ToString()));
var dataElement = instance.Data.First(m => m.Id.Equals(dataGuid.ToString(), StringComparison.Ordinal));

if (dataElement == null)
{
Expand Down Expand Up @@ -547,7 +552,9 @@ [FromRoute] Guid dataGuid
);
}

DataElement? dataElement = instance.Data.Find(m => m.Id.Equals(dataGuid.ToString()));
DataElement? dataElement = instance.Data.Find(m =>
m.Id.Equals(dataGuid.ToString(), StringComparison.Ordinal)
);

if (dataElement == null)
{
Expand Down Expand Up @@ -604,7 +611,7 @@ private async Task<ActionResult> CreateBinaryData(
Stream fileStream
)
{
int instanceOwnerPartyId = int.Parse(instanceBefore.Id.Split("/")[0]);
int instanceOwnerPartyId = int.Parse(instanceBefore.Id.Split("/")[0], CultureInfo.InvariantCulture);
Guid instanceGuid = Guid.Parse(instanceBefore.Id.Split("/")[1]);

DataElement dataElement = await _dataClient.InsertBinaryData(
Expand Down Expand Up @@ -655,7 +662,7 @@ private async Task<ActionResult> CreateAppModelData(string org, string app, Inst
await UpdatePresentationTextsOnInstance(instance, dataType, appModel);
await UpdateDataValuesOnInstance(instance, dataType, appModel);

int instanceOwnerPartyId = int.Parse(instance.InstanceOwner.PartyId);
int instanceOwnerPartyId = int.Parse(instance.InstanceOwner.PartyId, CultureInfo.InvariantCulture);

ObjectUtils.InitializeAltinnRowId(appModel);
ObjectUtils.PrepareModelForXmlStorage(appModel);
Expand Down Expand Up @@ -692,7 +699,7 @@ DataElement dataElement
if (dataStream != null)
{
string? userOrgClaim = User.GetOrg();
if (userOrgClaim == null || !org.Equals(userOrgClaim, StringComparison.InvariantCultureIgnoreCase))
if (userOrgClaim == null || !org.Equals(userOrgClaim, StringComparison.OrdinalIgnoreCase))
{
await _instanceClient.UpdateReadStatus(instanceOwnerPartyId, instanceGuid, "read");
}
Expand Down Expand Up @@ -822,7 +829,7 @@ await _dataClient.UpdateData(

// This is likely not required as the instance is already read
string? userOrgClaim = User.GetOrg();
if (userOrgClaim == null || !org.Equals(userOrgClaim, StringComparison.InvariantCultureIgnoreCase))
if (userOrgClaim == null || !org.Equals(userOrgClaim, StringComparison.OrdinalIgnoreCase))
{
await _instanceClient.UpdateReadStatus(instanceOwnerId, instanceGuid, "read");
}
Expand Down Expand Up @@ -860,7 +867,7 @@ private async Task<ActionResult> PutFormData(
string? language
)
{
int instanceOwnerPartyId = int.Parse(instance.InstanceOwner.PartyId);
int instanceOwnerPartyId = int.Parse(instance.InstanceOwner.PartyId, CultureInfo.InvariantCulture);

string classRef = dataType.AppLogic.ClassRef;
Guid instanceGuid = Guid.Parse(instance.Id.Split("/")[1]);
Expand Down Expand Up @@ -928,7 +935,7 @@ private async Task UpdatePresentationTextsOnInstance(Instance instance, string d
if (updatedValues.Count > 0)
{
await _instanceClient.UpdatePresentationTexts(
int.Parse(instance.Id.Split("/")[0]),
int.Parse(instance.Id.Split("/")[0], CultureInfo.InvariantCulture),
Guid.Parse(instance.Id.Split("/")[1]),
new PresentationTexts { Texts = updatedValues }
);
Expand All @@ -947,7 +954,7 @@ private async Task UpdateDataValuesOnInstance(Instance instance, string dataType
if (updatedValues.Count > 0)
{
await _instanceClient.UpdateDataValues(
int.Parse(instance.Id.Split("/")[0]),
int.Parse(instance.Id.Split("/")[0], CultureInfo.InvariantCulture),
Guid.Parse(instance.Id.Split("/")[1]),
new DataValues { Values = updatedValues }
);
Expand Down Expand Up @@ -996,7 +1003,7 @@ private static bool IsValidContributer(DataType dataType, ClaimsPrincipal user)
string key = item.Split(':')[0];
string value = item.Split(':')[1];

switch (key.ToLower())
switch (key.ToLowerInvariant())
{
case "org":
if (value.Equals(user.GetOrg(), StringComparison.OrdinalIgnoreCase))
Expand All @@ -1006,7 +1013,12 @@ private static bool IsValidContributer(DataType dataType, ClaimsPrincipal user)

break;
case "orgno":
if (value.Equals(user.GetOrgNumber().ToString()))
if (
value.Equals(
user.GetOrgNumber()?.ToString(CultureInfo.InvariantCulture),
StringComparison.Ordinal
)
)
{
return true;
}
Expand Down
12 changes: 9 additions & 3 deletions src/Altinn.App.Api/Controllers/DataTagsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ [FromRoute] Guid dataGuid
return NotFound($"Unable to find instance based on the given parameters.");
}

DataElement? dataElement = instance.Data.FirstOrDefault(m => m.Id.Equals(dataGuid.ToString()));
DataElement? dataElement = instance.Data.FirstOrDefault(m =>
m.Id.Equals(dataGuid.ToString(), StringComparison.Ordinal)
);

if (dataElement == null)
{
Expand Down Expand Up @@ -106,7 +108,9 @@ [FromBody] string tag
return NotFound("Unable to find instance based on the given parameters.");
}

DataElement? dataElement = instance.Data.FirstOrDefault(m => m.Id.Equals(dataGuid.ToString()));
DataElement? dataElement = instance.Data.FirstOrDefault(m =>
m.Id.Equals(dataGuid.ToString(), StringComparison.Ordinal)
);

if (dataElement == null)
{
Expand Down Expand Up @@ -160,7 +164,9 @@ [FromRoute] string tag
return NotFound("Unable to find instance based on the given parameters.");
}

DataElement? dataElement = instance.Data.FirstOrDefault(m => m.Id.Equals(dataGuid.ToString()));
DataElement? dataElement = instance.Data.FirstOrDefault(m =>
m.Id.Equals(dataGuid.ToString(), StringComparison.Ordinal)
);

if (dataElement == null)
{
Expand Down
47 changes: 32 additions & 15 deletions src/Altinn.App.Api/Controllers/InstancesController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Globalization;
using System.Net;
using System.Text;
using Altinn.App.Api.Helpers.RequestHandling;
Expand Down Expand Up @@ -146,7 +147,7 @@ [FromRoute] Guid instanceGuid

string? userOrgClaim = User.GetOrg();

if (userOrgClaim == null || !org.Equals(userOrgClaim, StringComparison.InvariantCultureIgnoreCase))
if (userOrgClaim == null || !org.Equals(userOrgClaim, StringComparison.OrdinalIgnoreCase))
{
await _instanceClient.UpdateReadStatus(instanceOwnerPartyId, instanceGuid, "read");
}
Expand Down Expand Up @@ -239,7 +240,10 @@ [FromQuery] int? instanceOwnerPartyId
// create minimum instance template
instanceTemplate = new Instance
{
InstanceOwner = new InstanceOwner { PartyId = instanceOwnerPartyId.Value.ToString() }
InstanceOwner = new InstanceOwner
{
PartyId = instanceOwnerPartyId.Value.ToString(CultureInfo.InvariantCulture)
}
};
}

Expand Down Expand Up @@ -331,7 +335,7 @@ [FromQuery] int? instanceOwnerPartyId
instance = await _instanceClient.GetInstance(
app,
org,
int.Parse(instance.InstanceOwner.PartyId),
int.Parse(instance.InstanceOwner.PartyId, CultureInfo.InvariantCulture),
Guid.Parse(instance.Id.Split("/")[1])
);

Expand Down Expand Up @@ -425,7 +429,11 @@ [FromBody] InstansiationInstance instansiationInstance
return NotFound($"Cannot lookup party: {partyLookupException.Message}");
}

if (copySourceInstance && party.PartyId.ToString() != instansiationInstance.SourceInstanceId.Split("/")[0])
if (
copySourceInstance
&& party.PartyId.ToString(CultureInfo.InvariantCulture)
!= instansiationInstance.SourceInstanceId.Split("/")[0]
)
{
return BadRequest("It is not possible to copy instances between instance owners.");
}
Expand Down Expand Up @@ -705,7 +713,7 @@ [FromBody] Substatus substatus
Instance instance = await _instanceClient.GetInstance(app, org, instanceOwnerPartyId, instanceGuid);

string? orgClaim = User.GetOrg();
if (!instance.Org.Equals(orgClaim))
if (!instance.Org.Equals(orgClaim, StringComparison.OrdinalIgnoreCase))
{
return Forbid();
}
Expand Down Expand Up @@ -783,7 +791,7 @@ int instanceOwnerPartyId
new()
{
{ "appId", $"{org}/{app}" },
{ "instanceOwner.partyId", instanceOwnerPartyId.ToString() },
{ "instanceOwner.partyId", instanceOwnerPartyId.ToString(CultureInfo.InvariantCulture) },
{ "status.isArchived", "false" },
{ "status.isSoftDeleted", "false" }
};
Expand Down Expand Up @@ -863,14 +871,17 @@ Instance sourceInstance
{
string org = application.Org;
string app = application.AppIdentifier.App;
int instanceOwnerPartyId = int.Parse(targetInstance.InstanceOwner.PartyId);
int instanceOwnerPartyId = int.Parse(targetInstance.InstanceOwner.PartyId, CultureInfo.InvariantCulture);

string[] sourceSplit = sourceInstance.Id.Split("/");
Guid sourceInstanceGuid = Guid.Parse(sourceSplit[1]);

List<DataType> dts = application
.DataTypes.Where(dt => dt.AppLogic?.ClassRef != null)
.Where(dt => dt.TaskId != null && dt.TaskId.Equals(targetInstance.Process.CurrentTask.ElementId))
.Where(dt =>
dt.TaskId != null
&& dt.TaskId.Equals(targetInstance.Process.CurrentTask.ElementId, StringComparison.Ordinal)
)
.ToList();
List<string> excludedDataTypes = application.CopyInstanceSettings.ExcludedDataTypes;

Expand All @@ -881,9 +892,9 @@ Instance sourceInstance
continue;
}

if (dts.Any(dts => dts.Id.Equals(de.DataType)))
if (dts.Any(dts => dts.Id.Equals(de.DataType, StringComparison.Ordinal)))
{
DataType dt = dts.First(dt => dt.Id.Equals(de.DataType));
DataType dt = dts.First(dt => dt.Id.Equals(de.DataType, StringComparison.Ordinal));

Type type;
try
Expand Down Expand Up @@ -913,7 +924,11 @@ Instance sourceInstance
DataHelper.ResetDataFields(application.CopyInstanceSettings.ExcludedDataFields, data);
}

await _prefillService.PrefillDataModel(instanceOwnerPartyId.ToString(), dt.Id, data);
await _prefillService.PrefillDataModel(
instanceOwnerPartyId.ToString(CultureInfo.InvariantCulture),
dt.Id,
data
);

await _instantiationProcessor.DataCreation(targetInstance, data, null);

Expand Down Expand Up @@ -998,7 +1013,9 @@ string action
{
try
{
return await _altinnPartyClientClient.GetParty(int.Parse(instanceOwner.PartyId));
return await _altinnPartyClientClient.GetParty(
int.Parse(instanceOwner.PartyId, CultureInfo.InvariantCulture)
);
}
catch (Exception e) when (e is not ServiceException)
{
Expand Down Expand Up @@ -1058,7 +1075,7 @@ string action
private async Task StorePrefillParts(Instance instance, ApplicationMetadata appInfo, List<RequestPart> parts)
{
Guid instanceGuid = Guid.Parse(instance.Id.Split("/")[1]);
int instanceOwnerIdAsInt = int.Parse(instance.InstanceOwner.PartyId);
int instanceOwnerIdAsInt = int.Parse(instance.InstanceOwner.PartyId, CultureInfo.InvariantCulture);
string org = instance.Org;
string app = instance.AppId.Split("/")[1];

Expand Down Expand Up @@ -1219,7 +1236,7 @@ object data
if (updatedValues.Count > 0)
{
await _instanceClient.UpdatePresentationTexts(
int.Parse(instance.Id.Split("/")[0]),
int.Parse(instance.Id.Split("/")[0], CultureInfo.InvariantCulture),
Guid.Parse(instance.Id.Split("/")[1]),
new PresentationTexts { Texts = updatedValues }
);
Expand All @@ -1238,7 +1255,7 @@ object data
if (updatedValues.Count > 0)
{
await _instanceClient.UpdateDataValues(
int.Parse(instance.Id.Split("/")[0]),
int.Parse(instance.Id.Split("/")[0], CultureInfo.InvariantCulture),
Guid.Parse(instance.Id.Split("/")[1]),
new DataValues { Values = updatedValues }
);
Expand Down
Loading

0 comments on commit 3b7429d

Please sign in to comment.