Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ export class RbacAddAssignmentComponent implements OnDestroy {
const request: CreateRoleAssignmentEndpointRequest = {
scopeId: this.targetScopeId,
role: this.selectedRole,
description: null, // TODO
apiKeyId: this.selectedPrincipalKind === PrincipalKind.ApiKey ? this.searchPrincipalInput.trim() : null,
userEmail: this.selectedPrincipalKind === PrincipalKind.User ? this.searchPrincipalInput.trim() : null
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Turnierplan.Core.Tournament;
using Turnierplan.Core.User;
using Turnierplan.Core.Venue;
using Turnierplan.Dal;

namespace Turnierplan.App.Endpoints.RoleAssignments;

Expand Down Expand Up @@ -104,7 +103,7 @@ private static async Task<IResult> CreateRoleAssignmentAsync<T>(
return Results.Conflict("There already exists a role assignment for the specified principal/role combination.");
}

var roleAssignment = entity.AddRoleAssignment(request.Role, principal, request.Description);
var roleAssignment = entity.AddRoleAssignment(request.Role, principal);

await roleAssignmentRepository.CreateAsync(roleAssignment).ConfigureAwait(false);
await repository.UnitOfWork.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -143,8 +142,6 @@ public sealed record CreateRoleAssignmentEndpointRequest
public required PublicId? ApiKeyId { get; init; }

public required string? UserEmail { get; init; }

public required string? Description { get; init; }
}

private sealed class Validator : AbstractValidator<CreateRoleAssignmentEndpointRequest>
Expand All @@ -162,11 +159,6 @@ private Validator()
RuleFor(x => x)
.Must(x => x.ApiKeyId is null ^ x.UserEmail is null)
.WithMessage($"Exactly only one of {nameof(CreateRoleAssignmentEndpointRequest.ApiKeyId)} and {nameof(CreateRoleAssignmentEndpointRequest.UserEmail)} must be specified.");

RuleFor(x => x.Description)
.NotEmpty()
.MaximumLength(ValidationConstants.RoleAssignment.MaxDescriptionLength)
.When(x => x.Description is not null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ protected override RoleAssignmentDto Map(IMapper mapper, MappingContext context,
Kind = source.Principal.Kind,
PrincipalId = source.Principal.PrincipalId
},
Description = source.Description,
IsInherited = false
};
}
Expand Down
2 changes: 0 additions & 2 deletions src/Turnierplan.App/Models/RoleAssignmentDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,5 @@ public sealed record RoleAssignmentDto

public required PrincipalDto Principal { get; init; }

public required string Description { get; init; }

public required bool IsInherited { get; init; }
}
4 changes: 2 additions & 2 deletions src/Turnierplan.Core/ApiKey/ApiKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
IsActive = true;
}

internal ApiKey(long id, Guid principalId, PublicId.PublicId publicId, string name, string description, string secretHash, DateTime createdAt, DateTime expiryDate, bool isActive)

Check warning on line 27 in src/Turnierplan.Core/ApiKey/ApiKey.cs

View workflow job for this annotation

GitHub Actions / Validate

Constructor has 9 parameters, which is greater than the 7 authorized. (https://rules.sonarsource.com/csharp/RSPEC-107)
{
Id = id;
PrincipalId = principalId;
Expand Down Expand Up @@ -63,9 +63,9 @@

public IReadOnlyList<ApiKeyRequest> Requests => _requests.AsReadOnly();

public RoleAssignment<ApiKey> AddRoleAssignment(Role role, Principal principal, string? description = null)
public RoleAssignment<ApiKey> AddRoleAssignment(Role role, Principal principal)
{
var roleAssignment = new RoleAssignment<ApiKey>(this, role, principal, description);
var roleAssignment = new RoleAssignment<ApiKey>(this, role, principal);
_roleAssignments.Add(roleAssignment);

return roleAssignment;
Expand Down
4 changes: 2 additions & 2 deletions src/Turnierplan.Core/Folder/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ internal Folder(long id, PublicId.PublicId publicId, DateTime createdAt, string

public IReadOnlyList<Tournament.Tournament> Tournaments => _tournaments.AsReadOnly();

public RoleAssignment<Folder> AddRoleAssignment(Role role, Principal principal, string? description = null)
public RoleAssignment<Folder> AddRoleAssignment(Role role, Principal principal)
{
var roleAssignment = new RoleAssignment<Folder>(this, role, principal, description);
var roleAssignment = new RoleAssignment<Folder>(this, role, principal);
_roleAssignments.Add(roleAssignment);

return roleAssignment;
Expand Down
4 changes: 2 additions & 2 deletions src/Turnierplan.Core/Image/Image.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Height = height;
}

internal Image(long id, Guid resourceIdentifier, PublicId.PublicId publicId, DateTime createdAt, string name, ImageType type, string fileType, long fileSize, ushort width, ushort height)

Check warning on line 30 in src/Turnierplan.Core/Image/Image.cs

View workflow job for this annotation

GitHub Actions / Validate

Constructor has 10 parameters, which is greater than the 7 authorized. (https://rules.sonarsource.com/csharp/RSPEC-107)
{
Id = id;
ResourceIdentifier = resourceIdentifier;
Expand Down Expand Up @@ -65,9 +65,9 @@

public ushort Height { get; }

public RoleAssignment<Image> AddRoleAssignment(Role role, Principal principal, string? description = null)
public RoleAssignment<Image> AddRoleAssignment(Role role, Principal principal)
{
var roleAssignment = new RoleAssignment<Image>(this, role, principal, description);
var roleAssignment = new RoleAssignment<Image>(this, role, principal);
_roleAssignments.Add(roleAssignment);

return roleAssignment;
Expand Down
4 changes: 2 additions & 2 deletions src/Turnierplan.Core/Organization/Organization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ internal Organization(long id, PublicId.PublicId publicId, DateTime createdAt, s

public IReadOnlyList<Venue.Venue> Venues => _venues.AsReadOnly();

public RoleAssignment<Organization> AddRoleAssignment(Role role, Principal principal, string? description = null)
public RoleAssignment<Organization> AddRoleAssignment(Role role, Principal principal)
{
var roleAssignment = new RoleAssignment<Organization>(this, role, principal, description);
var roleAssignment = new RoleAssignment<Organization>(this, role, principal);
_roleAssignments.Add(roleAssignment);

return roleAssignment;
Expand Down
8 changes: 2 additions & 6 deletions src/Turnierplan.Core/RoleAssignment/RoleAssignment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ namespace Turnierplan.Core.RoleAssignment;
public sealed class RoleAssignment<T> : Entity<Guid>
where T : Entity<long>, IEntityWithRoleAssignments<T>
{
internal RoleAssignment(T scope, Role role, Principal principal, string? description = null)
internal RoleAssignment(T scope, Role role, Principal principal)
{
Id = Guid.NewGuid();
Scope = scope;
CreatedAt = DateTime.UtcNow;
Role = role;
Principal = principal;
Description = description ?? string.Empty;
}

internal RoleAssignment(Guid id, DateTime createdAt, Role role, Principal principal, string description)
internal RoleAssignment(Guid id, DateTime createdAt, Role role, Principal principal)
{
Id = id;
CreatedAt = createdAt;
Role = role;
Principal = principal;
Description = description;
}

public override Guid Id { get; protected set; }
Expand All @@ -33,6 +31,4 @@ internal RoleAssignment(Guid id, DateTime createdAt, Role role, Principal princi
public Role Role { get; }

public Principal Principal { get; }

public string Description { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface IEntityWithRoleAssignments<T> : IEntityWithPublicId

IReadOnlyList<RoleAssignment<T>> RoleAssignments { get; }

RoleAssignment<T> AddRoleAssignment(Role role, Principal principal, string? description = null);
RoleAssignment<T> AddRoleAssignment(Role role, Principal principal);

void RemoveRoleAssignment(RoleAssignment<T> roleAssignment);
}
4 changes: 2 additions & 2 deletions src/Turnierplan.Core/Tournament/Tournament.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@
}
}

public RoleAssignment<Tournament> AddRoleAssignment(Role role, Principal principal, string? description = null)
public RoleAssignment<Tournament> AddRoleAssignment(Role role, Principal principal)
{
var roleAssignment = new RoleAssignment<Tournament>(this, role, principal, description);
var roleAssignment = new RoleAssignment<Tournament>(this, role, principal);
_roleAssignments.Add(roleAssignment);

return roleAssignment;
Expand Down Expand Up @@ -267,7 +267,7 @@

public void ShiftToTimezone(TimeZoneInfo timeZone)
{
foreach (var match in _matches)

Check warning on line 270 in src/Turnierplan.Core/Tournament/Tournament.cs

View workflow job for this annotation

GitHub Actions / Validate

Loops should be simplified using the "Where" LINQ method (https://rules.sonarsource.com/csharp/RSPEC-3267)
{
if (match.Kickoff is not null)
{
Expand Down Expand Up @@ -433,7 +433,7 @@
}
}

public List<RefereeCard> GenerateRefereeCards()

Check warning on line 436 in src/Turnierplan.Core/Tournament/Tournament.cs

View workflow job for this annotation

GitHub Actions / Validate

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
var cards = new List<RefereeCard>();
var groupRefereeMap = new Dictionary<Group, Group>();
Expand Down Expand Up @@ -529,7 +529,7 @@
}
}

private void ComputeGroupPhaseResults()

Check warning on line 532 in src/Turnierplan.Core/Tournament/Tournament.cs

View workflow job for this annotation

GitHub Actions / Validate

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
foreach (var group in _groups)
{
Expand Down Expand Up @@ -560,7 +560,7 @@
}
}

private void ComputeRanking()

Check warning on line 563 in src/Turnierplan.Core/Tournament/Tournament.cs

View workflow job for this annotation

GitHub Actions / Validate

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
var matchesWithRankingInfluence = new HashSet<Match>();
var undefinedRankings = Enumerable.Range(1, _teams.Count).ToList();
Expand Down Expand Up @@ -751,7 +751,7 @@
}
}

private void GenerateFinalsMatches(FinalsRoundConfig? config, int matchIndexOffset)

Check warning on line 754 in src/Turnierplan.Core/Tournament/Tournament.cs

View workflow job for this annotation

GitHub Actions / Validate

Refactor this method to reduce its Cognitive Complexity from 21 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
if (config is null)
{
Expand Down Expand Up @@ -894,7 +894,7 @@
}
}

private void GenerateSchedule(ScheduleConfig? config)

Check warning on line 897 in src/Turnierplan.Core/Tournament/Tournament.cs

View workflow job for this annotation

GitHub Actions / Validate

Refactor this method to reduce its Cognitive Complexity from 16 to the 15 allowed. (https://rules.sonarsource.com/csharp/RSPEC-3776)
{
if (config is null)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Turnierplan.Core/Venue/Venue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ internal Venue(long id, PublicId.PublicId publicId, DateTime createdAt, string n

public IReadOnlyList<Tournament.Tournament> Tournaments => _tournaments.AsReadOnly();

public RoleAssignment<Venue> AddRoleAssignment(Role role, Principal principal, string? description = null)
public RoleAssignment<Venue> AddRoleAssignment(Role role, Principal principal)
{
var roleAssignment = new RoleAssignment<Venue>(this, role, principal, description);
var roleAssignment = new RoleAssignment<Venue>(this, role, principal);
_roleAssignments.Add(roleAssignment);

return roleAssignment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,5 @@ public void Configure(EntityTypeBuilder<RoleAssignment<T>> builder)
builder.Property(x => x.Principal)
.IsRequired()
.HasConversion<PrincipalConverter>();

builder.Property(x => x.Description)
.IsRequired()
.HasMaxLength(ValidationConstants.RoleAssignment.MaxDescriptionLength);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Turnierplan.Dal.Migrations
{
/// <inheritdoc />
public partial class Add_RBAC : Migration
public partial class Add_Rbac : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
Expand Down Expand Up @@ -65,8 +65,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
ApiKeyId = table.Column<long>(type: "bigint", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false),
Principal = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "character varying(250)", maxLength: 250, nullable: false)
Principal = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
Expand All @@ -89,8 +88,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
FolderId = table.Column<long>(type: "bigint", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false),
Principal = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "character varying(250)", maxLength: 250, nullable: false)
Principal = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
Expand All @@ -113,8 +111,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
ImageId = table.Column<long>(type: "bigint", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false),
Principal = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "character varying(250)", maxLength: 250, nullable: false)
Principal = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
Expand All @@ -137,8 +134,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
OrganizationId = table.Column<long>(type: "bigint", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false),
Principal = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "character varying(250)", maxLength: 250, nullable: false)
Principal = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
Expand All @@ -161,8 +157,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
TournamentId = table.Column<long>(type: "bigint", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false),
Principal = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "character varying(250)", maxLength: 250, nullable: false)
Principal = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
Expand All @@ -185,8 +180,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
VenueId = table.Column<long>(type: "bigint", nullable: false),
CreatedAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Role = table.Column<int>(type: "integer", nullable: false),
Principal = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "character varying(250)", maxLength: 250, nullable: false)
Principal = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
Expand Down Expand Up @@ -261,8 +255,8 @@ protected override void Up(MigrationBuilder migrationBuilder)
// 1000 is the numerical value for the "Owner" role

migrationBuilder.Sql("""
INSERT INTO turnierplan."IAM_Organization" ("Id", "OrganizationId", "CreatedAt", "Role", "Principal", "Description")
SELECT gen_random_uuid(), "Organizations"."Id", NOW(), 1000, ('User:' || "Users"."PrincipalId"), ''
INSERT INTO turnierplan."IAM_Organization" ("Id", "OrganizationId", "CreatedAt", "Role", "Principal")
SELECT gen_random_uuid(), "Organizations"."Id", NOW(), 1000, ('User:' || "Users"."PrincipalId")
FROM turnierplan."Organizations"
INNER JOIN turnierplan."Users" ON "Organizations"."OwnerId" = "Users"."Id";
""");
Expand Down
Loading
Loading