-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feat/update-fusion-urls
- Loading branch information
Showing
3 changed files
with
219 additions
and
146 deletions.
There are no files selected for viewing
41 changes: 38 additions & 3 deletions
41
src/backend/api/Fusion.Resources.Domain/Models/QueryOrgUnitReason.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,44 @@ | ||
namespace Fusion.Resources.Domain.Models | ||
using System.Collections.Generic; | ||
using System; | ||
|
||
namespace Fusion.Resources.Domain.Models | ||
{ | ||
internal class QueryOrgUnitReason | ||
{ | ||
public QueryOrgUnitReason(string fullDepartment, string reason) | ||
{ | ||
IsWildCard = fullDepartment.Trim().EndsWith('*'); | ||
Reason = reason; | ||
FullDepartment = fullDepartment.Replace("*", "").Trim(); | ||
Level = FullDepartment.Split(" ").Length; | ||
IsGlobalRole = string.IsNullOrEmpty(fullDepartment); | ||
|
||
} | ||
|
||
public string FullDepartment { get; set; } = null!; | ||
public string Reason { get; set; } = null!; | ||
public bool IsWildCard => FullDepartment.Contains('*') ; | ||
public bool IsWildCard { get; set; } | ||
public int Level { get; set; } | ||
public bool IsGlobalRole { get; set; } | ||
} | ||
} | ||
|
||
internal struct OrgUnitComparer | ||
{ | ||
public OrgUnitComparer(string FullDepartment) | ||
{ | ||
this.FullDepartment = FullDepartment; | ||
Level = FullDepartment.Split(" ").Length; | ||
} | ||
|
||
public string FullDepartment { get; } | ||
public int Level { get; set; } | ||
|
||
public bool IsChildOf(OrgUnitComparer other, int maxDistance) | ||
{ | ||
var isChild = other.FullDepartment.StartsWith(FullDepartment + " ", StringComparison.OrdinalIgnoreCase); | ||
var distance = Level - other.Level; | ||
|
||
return isChild && distance <= maxDistance; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.