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
6 changes: 4 additions & 2 deletions app/GraphQL/Mutations/AbstractMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ abstract class AbstractMutation
/**
* @param array<string,mixed> $args
*/
final public function __invoke(null $_, array $args): self
public function __invoke(null $_, array $args): self
{
try {
$this->mutate($args);
Expand All @@ -30,5 +30,7 @@ final public function __invoke(null $_, array $args): self
*
* @param array<string,mixed> $args
*/
abstract protected function mutate(array $args): void;
protected function mutate(array $args): void
{
}
}
31 changes: 31 additions & 0 deletions app/GraphQL/Mutations/UpdateProject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\GraphQL\Mutations;

use App\Models\Project;
use Illuminate\Support\Facades\Gate;

final class UpdateProject extends AbstractMutation
{
public ?Project $project = null;

/**
* @param array<string,mixed> $args
*/
public function __invoke(null $_, array $args): self
{
$project = Project::find((int) $args['id']);

Gate::authorize('update', $project);

unset($args['id']);

$project?->update($args);

$this->project = $project;

return $this;
}
}
36 changes: 36 additions & 0 deletions app/GraphQL/Validators/UpdateProjectInputValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\GraphQL\Validators;

use App\Models\Project;
use App\Rules\ProjectAuthenticateSubmissionsRule;
use App\Rules\ProjectNameRule;
use App\Rules\ProjectVisibilityRule;
use Illuminate\Validation\Rule;
use Nuwave\Lighthouse\Validation\Validator;

final class UpdateProjectInputValidator extends Validator
{
public function rules(): array
{
return [
'name' => [
Rule::unique(Project::class, 'name'),
new ProjectNameRule(),
],
'visibility' => [
new ProjectVisibilityRule(),
],
'authenticateSubmissions' => [
new ProjectAuthenticateSubmissionsRule(),
],
];
}

public function messages(): array
{
return [
'name.unique' => 'A project with this name already exists.',
];
}
}
2 changes: 2 additions & 0 deletions app/cdash/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ add_feature_test_in_transaction(/Feature/Mail/AuthTokenExpiredTest)

add_feature_test_in_transaction(/Feature/GraphQL/Mutations/CreateProjectTest)

add_feature_test_in_transaction(/Feature/GraphQL/Mutations/UpdateProjectTest)

add_feature_test_in_transaction(/Feature/GraphQL/Mutations/UpdateSiteDescriptionTest)

add_feature_test_in_transaction(/Feature/GraphQL/Mutations/InviteToProjectTest)
Expand Down
82 changes: 82 additions & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ type Mutation {
"Create a new project."
createProject(input: CreateProjectInput! @spread): Project @field(resolver: "CreateProject")

updateProject(input: UpdateProjectInput! @spread): UpdateProjectMutationPayload! @field(resolver: "UpdateProject")

"Subscribe the current user to the specified site."
claimSite(input: ClaimSiteInput! @spread): ClaimSiteMutationPayload! @field(resolver: "ClaimSite")

Expand Down Expand Up @@ -376,6 +378,77 @@ input CreateProjectInput @validator {
}


input UpdateProjectInput @validator {
id: ID!

name: String

description: String

homeUrl: Url @rename(attribute: "homeurl")

vcsViewer: VcsViewer @rename(attribute: "cvsviewertype")

vcsUrl: Url @rename(attribute: "cvsurl")

bugTracker: BugTracker @rename(attribute: "bugtrackertype")

bugTrackerUrl: Url @rename(attribute: "bugtrackerurl")

bugTrackerNewIssueUrl: Url @rename(attribute: "bugtrackernewissueurl")

documentationUrl: Url @rename(attribute: "documentationurl")

testDataUrl: Url @rename(attribute: "testingdataurl")

visibility: ProjectVisibility @rename(attribute: "public")

authenticateSubmissions: Boolean @rename(attribute: "authenticatesubmissions")

ldapFilter: String @rename(attribute: "ldapfilter")

coverageThreshold: Int @rename(attribute: "coveragethreshold")

nightlyTime: Time @rename(attribute: "nightlytime")

emailLowCoverage: Boolean @rename(attribute: "emaillowcoverage")

emailTestTimingChanged: Boolean @rename(attribute: "emailtesttimingchanged")

emailBrokenSubmissions: Boolean @rename(attribute: "emailbrokensubmission")

emailRedundantFailures: Boolean @rename(attribute: "emailredundantfailures")

testTimeStdMultiplier: Float @rename(attribute: "testtimestd")

testTimeStdThreshold: Float @rename(attribute: "testtimestdthreshold")

enableTestTiming: Boolean @rename(attribute: "showtesttime")

timeStatusFailureThreshold: Int @rename(attribute: "testtimemaxstatus")

emailMaxItems: Int @rename(attribute: "emailmaxitems")

emailMaxCharacters: Int @rename(attribute: "emailmaxchars")

displayLabels: Boolean @rename(attribute: "displaylabels")

autoRemoveTimeFrame: Int @rename(attribute: "autoremovetimeframe")

autoRemoveMaxBuilds: Int @rename(attribute: "autoremovemaxbuilds")

fileUploadLimit: Int @rename(attribute: "uploadquota")

showCoverageCode: Boolean @rename(attribute: "showcoveragecode")

shareLabelFilters: Boolean @rename(attribute: "sharelabelfilters")

showViewSubProjectsLink: Boolean @rename(attribute: "viewsubprojectslink")

banner: String
}


type ProjectInvitation {
id: ID!

Expand Down Expand Up @@ -917,6 +990,15 @@ type Site {
): [User!]! @belongsToMany(type: CONNECTION) @orderBy(column: "id")
}


type UpdateProjectMutationPayload implements MutationPayloadInterface {
"Optional error message."
message: String

project: Project
}


input ClaimSiteInput {
siteId: ID!
}
Expand Down
12 changes: 12 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,12 @@ parameters:
count: 1
path: app/GraphQL/Mutations/UpdatePinnedTestMeasurementOrder.php

-
rawMessage: Cannot cast mixed to int.
identifier: cast.int
count: 1
path: app/GraphQL/Mutations/UpdateProject.php

-
rawMessage: 'Parameter #1 $args (array{siteId: int, description: string}) of method App\GraphQL\Mutations\UpdateSiteDescription::mutate() should be contravariant with parameter $args (array<string, mixed>) of method App\GraphQL\Mutations\AbstractMutation::mutate()'
identifier: method.childParameterType
Expand Down Expand Up @@ -27153,6 +27159,12 @@ parameters:
count: 1
path: tests/Feature/GraphQL/Mutations/RevokeProjectInvitationTest.php

-
rawMessage: 'Parameter #1 $user of method Illuminate\Foundation\Testing\TestCase::actingAs() expects Illuminate\Contracts\Auth\Authenticatable, App\Models\User|null given.'
identifier: argument.type
count: 2
path: tests/Feature/GraphQL/Mutations/UpdateProjectTest.php

-
rawMessage: 'Method Tests\Feature\GraphQL\ProjectInvitationTypeTest::testAdminCanViewInvitations() throws checked exception OverflowException but it''s missing from the PHPDoc @throws tag.'
identifier: missingType.checkedException
Expand Down
Loading