Skip to content

Commit

Permalink
GQL mutation to update project repo size
Browse files Browse the repository at this point in the history
This one is open to anyone who can view the project, so that frontend
code can automatically look up the project size if it's missing, with no
manual button clicks necessary.
  • Loading branch information
rmunn committed Nov 11, 2024
1 parent bfa8683 commit 64938af
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
18 changes: 18 additions & 0 deletions backend/LexBoxApi/GraphQL/ProjectMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,24 @@ public async Task<IQueryable<Project>> SetRetentionPolicy(
return dbContext.Projects.Where(p => p.Id == input.ProjectId);
}

[Error<NotFoundException>]
[Error<DbError>]
[Error<UnauthorizedAccessException>]
[UseMutationConvention]
[UseFirstOrDefault]
[UseProjection]
public async Task<IQueryable<Project>> UpdateProjectRepoSizeInKb(string code,
IPermissionService permissionService,
ProjectService projectService,
LexBoxDbContext dbContext)
{
var projectId = await projectService.LookupProjectId(code);
await permissionService.AssertCanViewProject(projectId);
if (projectId == default) throw NotFoundException.ForType<Project>();
await projectService.UpdateRepoSizeInKb(code);
return dbContext.Projects.Where(p => p.Id == projectId);
}

[Error<NotFoundException>]
[Error<DbError>]
[Error<UnauthorizedAccessException>]
Expand Down
10 changes: 10 additions & 0 deletions backend/LexBoxApi/Services/ProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ public async Task UpdateProjectMetadata(Project project)
// Caller is responsible for caling dbContext.SaveChangesAsync()
}

public async Task<int?> UpdateRepoSizeInKb(string projectCode)
{
var project = await dbContext.Projects.FirstOrDefaultAsync(p => p.Code == projectCode);
if (project is null) return null;
var size = await hgService.GetRepoSizeInKb(projectCode);
project.RepoSizeInKb = size;
await dbContext.SaveChangesAsync();
return size;
}

public async Task ResetLexEntryCount(string projectCode)
{
var project = await dbContext.Projects
Expand Down
15 changes: 15 additions & 0 deletions frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ type Mutation {
changeProjectDescription(input: ChangeProjectDescriptionInput!): ChangeProjectDescriptionPayload! @cost(weight: "10")
setProjectConfidentiality(input: SetProjectConfidentialityInput!): SetProjectConfidentialityPayload! @cost(weight: "10")
setRetentionPolicy(input: SetRetentionPolicyInput!): SetRetentionPolicyPayload! @cost(weight: "10")
updateProjectRepoSizeInKb(input: UpdateProjectRepoSizeInKbInput!): UpdateProjectRepoSizeInKbPayload! @cost(weight: "10")
updateProjectLexEntryCount(input: UpdateProjectLexEntryCountInput!): UpdateProjectLexEntryCountPayload! @cost(weight: "10")
updateProjectLanguageList(input: UpdateProjectLanguageListInput!): UpdateProjectLanguageListPayload! @cost(weight: "10")
updateLangProjectId(input: UpdateLangProjectIdInput!): UpdateLangProjectIdPayload! @cost(weight: "10")
Expand Down Expand Up @@ -384,6 +385,7 @@ type Project {
flexProjectMetadata: FlexProjectMetadata
organizations: [Organization!]!
lastCommit: DateTime
repoSizeInKb: Int
deletedDate: DateTime
resetStatus: ResetStatus!
projectOrigin: ProjectMigrationStatus!
Expand Down Expand Up @@ -512,6 +514,11 @@ type UpdateProjectLexEntryCountPayload {
errors: [UpdateProjectLexEntryCountError!]
}

type UpdateProjectRepoSizeInKbPayload {
project: Project
errors: [UpdateProjectRepoSizeInKbError!]
}

type User {
email: String @authorize(policy: "AdminRequiredPolicy")
emailVerified: Boolean! @authorize(policy: "AdminRequiredPolicy")
Expand Down Expand Up @@ -619,6 +626,8 @@ union UpdateProjectLanguageListError = NotFoundError | DbError | UnauthorizedAcc

union UpdateProjectLexEntryCountError = NotFoundError | DbError | UnauthorizedAccessError

union UpdateProjectRepoSizeInKbError = NotFoundError | DbError | UnauthorizedAccessError

input AddProjectMemberInput {
projectId: UUID!
usernameOrEmail: String
Expand Down Expand Up @@ -930,6 +939,7 @@ input ProjectFilterInput {
users: ListFilterInputTypeOfProjectUsersFilterInput
organizations: ListFilterInputTypeOfOrganizationFilterInput
lastCommit: DateTimeOperationFilterInput
repoSizeInKb: IntOperationFilterInput
deletedDate: DateTimeOperationFilterInput
resetStatus: ResetStatusOperationFilterInput
projectOrigin: ProjectMigrationStatusOperationFilterInput
Expand Down Expand Up @@ -964,6 +974,7 @@ input ProjectSortInput {
isConfidential: SortEnumType @cost(weight: "10")
flexProjectMetadata: FlexProjectMetadataSortInput @cost(weight: "10")
lastCommit: SortEnumType @cost(weight: "10")
repoSizeInKb: SortEnumType @cost(weight: "10")
deletedDate: SortEnumType @cost(weight: "10")
resetStatus: SortEnumType @cost(weight: "10")
projectOrigin: SortEnumType @cost(weight: "10")
Expand Down Expand Up @@ -1093,6 +1104,10 @@ input UpdateProjectLexEntryCountInput {
code: String!
}

input UpdateProjectRepoSizeInKbInput {
code: String!
}

input UserFilterInput {
and: [UserFilterInput!]
or: [UserFilterInput!]
Expand Down

0 comments on commit 64938af

Please sign in to comment.