mirror of
https://github.com/dotnet/skills.git
synced 2026-09-20 09:49:54 +08:00
9f531203ec
Move assertion-quality, test-gap-analysis, test-smell-detection, and test-tagging from dotnet-experimental to dotnet-test. These skills have demonstrated sufficient eval coverage, unique value beyond baseline model capabilities, and are already integrated into the test-quality-auditor agent pipeline. Changes: - Move skills and tests, dropping the exp- prefix - Update all cross-references in skill descriptions and routing tables - Update test-quality-auditor agent and eval scenarios - Update CODEOWNERS for the moved paths - Delete duplicate exp-dotnet-test-frameworks (identical to dotnet-test-frameworks) - Fix stale exp-dotnet-test-frameworks reference in exp-test-maintainability Skills held back for further iteration: - exp-mock-usage-analysis: baseline model scores 5/5 on key scenarios - exp-test-maintainability: quality gains offset by token overhead
62 lines
2.1 KiB
C#
62 lines
2.1 KiB
C#
namespace AccessControl;
|
|
|
|
public enum Role { Guest, User, Editor, Admin }
|
|
|
|
public class Permission
|
|
{
|
|
public string Resource { get; init; } = "";
|
|
public bool CanRead { get; init; }
|
|
public bool CanWrite { get; init; }
|
|
}
|
|
|
|
public class AccessChecker
|
|
{
|
|
/// <summary>
|
|
/// Checks if a user with the given role can access a resource.
|
|
/// Admins can access everything. Editors can read and write non-system resources.
|
|
/// Users can only read non-system resources. Guests have no access.
|
|
/// </summary>
|
|
public Permission GetPermission(Role role, string resource)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(resource);
|
|
|
|
bool isSystem = resource.StartsWith("sys/", StringComparison.OrdinalIgnoreCase);
|
|
|
|
return role switch
|
|
{
|
|
Role.Admin => new Permission { Resource = resource, CanRead = true, CanWrite = true },
|
|
Role.Editor when !isSystem => new Permission { Resource = resource, CanRead = true, CanWrite = true },
|
|
Role.Editor => new Permission { Resource = resource, CanRead = true, CanWrite = false },
|
|
Role.User when !isSystem => new Permission { Resource = resource, CanRead = true, CanWrite = false },
|
|
_ => new Permission { Resource = resource, CanRead = false, CanWrite = false },
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Returns true if the user can perform the requested action.
|
|
/// </summary>
|
|
public bool CanPerform(Role role, string resource, bool writeAccess)
|
|
{
|
|
var perm = GetPermission(role, resource);
|
|
return writeAccess ? perm.CanWrite : perm.CanRead;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elevates a user's effective role if they have a temporary elevation token.
|
|
/// Returns the elevated role, or the original role if the token is invalid.
|
|
/// </summary>
|
|
public Role ElevateRole(Role currentRole, string? token)
|
|
{
|
|
if (string.IsNullOrEmpty(token))
|
|
return currentRole;
|
|
|
|
if (token == "ELEVATE-ADMIN" && currentRole >= Role.Editor)
|
|
return Role.Admin;
|
|
|
|
if (token == "ELEVATE-EDITOR" && currentRole >= Role.User)
|
|
return Role.Editor;
|
|
|
|
return currentRole;
|
|
}
|
|
}
|