Skip to content

Commit

Permalink
Add project confidentiality
Browse files Browse the repository at this point in the history
  • Loading branch information
myieye committed Apr 30, 2024
1 parent 25bd218 commit 8101256
Show file tree
Hide file tree
Showing 40 changed files with 1,328 additions and 106 deletions.
19 changes: 19 additions & 0 deletions backend/LexBoxApi/GraphQL/ProjectMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,25 @@ public async Task<IQueryable<Project>> ChangeProjectDescription(ChangeProjectDes
return dbContext.Projects.Where(p => p.Id == input.ProjectId);
}

[Error<NotFoundException>]
[Error<DbError>]
[UseMutationConvention]
[UseFirstOrDefault]
[UseProjection]
public async Task<IQueryable<Project>> SetProjectConfidentiality(SetProjectConfidentialityInput input,
IPermissionService permissionService,
LexBoxDbContext dbContext)
{
permissionService.AssertCanManageProject(input.ProjectId);
var project = await dbContext.Projects.FindAsync(input.ProjectId);
NotFoundException.ThrowIfNull(project);

project.IsConfidential = input.IsConfidential;
project.UpdateUpdatedDate();
await dbContext.SaveChangesAsync();
return dbContext.Projects.Where(p => p.Id == input.ProjectId);
}

[Error<NotFoundException>]
[Error<LastMemberCantLeaveException>]
[UseMutationConvention]
Expand Down
2 changes: 2 additions & 0 deletions backend/LexBoxApi/Models/Project/ChangeProjectInputs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public record ChangeProjectNameInput(Guid ProjectId, string Name);

public record ChangeProjectDescriptionInput(Guid ProjectId, string Description);

public record SetProjectConfidentialityInput(Guid ProjectId, bool IsConfidential);

public record DeleteUserByAdminOrSelfInput(Guid UserId);

public record ResetProjectByAdminInput(string Code);
1 change: 1 addition & 0 deletions backend/LexBoxApi/Models/Project/CreateProjectInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public record CreateProjectInput(
string Code,
ProjectType Type,
RetentionPolicy RetentionPolicy,
bool IsConfidential,
Guid? ProjectManagerId
);
7 changes: 7 additions & 0 deletions backend/LexBoxApi/Services/ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public async Task<Guid> CreateProject(CreateProjectInput input)
{
await using var transaction = await dbContext.Database.BeginTransactionAsync();
var projectId = input.Id ?? Guid.NewGuid();
/* TODO #737 - Remove this draftProject/isConfidentialIsUntrustworthy stuff and just trust input.IsConfidential */
var draftProject = await dbContext.DraftProjects.FindAsync(projectId);
// There could be draft projects from before we introduced the IsConfidential field. (i.e. where draftProject.IsConfidential is null)
// In those cases we can't trust input.IsConfidential == false, because that is the default, but the user will never have had the chance to pick it.
var isConfidentialIsUntrustworthy = draftProject is not null && draftProject.IsConfidential is null && !input.IsConfidential;
dbContext.Projects.Add(
new Project
{
Expand All @@ -28,6 +33,7 @@ public async Task<Guid> CreateProject(CreateProjectInput input)
Type = input.Type,
LastCommit = null,
RetentionPolicy = input.RetentionPolicy,
IsConfidential = isConfidentialIsUntrustworthy ? null : input.IsConfidential,
Users = input.ProjectManagerId.HasValue ? [new() { UserId = input.ProjectManagerId.Value, Role = ProjectRole.Manager }] : [],
});
// Also delete draft project, if any
Expand Down Expand Up @@ -56,6 +62,7 @@ public async Task<Guid> CreateDraftProject(CreateProjectInput input)
Name = input.Name,
Description = input.Description,
Type = input.Type,
IsConfidential = input.IsConfidential,
RetentionPolicy = input.RetentionPolicy,
ProjectManagerId = input.ProjectManagerId,
});
Expand Down
1 change: 1 addition & 0 deletions backend/LexCore/Entities/DraftProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public class DraftProject : EntityBase
public required RetentionPolicy RetentionPolicy { get; set; }
public User? ProjectManager { get; set; }
public Guid? ProjectManagerId { get; set; }
public required bool? IsConfidential { get; set; }
}
1 change: 1 addition & 0 deletions backend/LexCore/Entities/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Project : EntityBase
public string? Description { get; set; }
public required RetentionPolicy RetentionPolicy { get; set; }
public required ProjectType Type { get; set; }
public required bool? IsConfidential { get; set; }
public FlexProjectMetadata? FlexProjectMetadata { get; set; }
public required List<ProjectUsers> Users { get; set; }
public required DateTimeOffset? LastCommit { get; set; }
Expand Down
Loading

0 comments on commit 8101256

Please sign in to comment.