-
Notifications
You must be signed in to change notification settings - Fork 3
Make API Endpoint to set the ReadOnly status of a Wiki #1009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
696ea5e
[WIP]: Make API Endpoint to set the ReadOnly status of a Wiki
rosalieper f92967a
fix linting
rosalieper c5b00ef
Add tests
rosalieper 1594ba3
Use PUT method instead of POST
rosalieper a5356a8
Add readOnly parameter
rosalieper 7154e05
Minor improvements
outdooracorn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Controllers\Backend; | ||
|
|
||
| use App\Http\Controllers\Controller; | ||
| use App\Wiki; | ||
| use Illuminate\Http\Request; | ||
|
|
||
| class WikiReadOnlyController extends Controller { | ||
| public function setWikiReadOnly(Request $request) { | ||
|
|
||
| $validated = $request->validate([ | ||
| 'domain' => 'required|string', | ||
| ]); | ||
|
|
||
| $domain = $validated['domain']; | ||
| $wiki = Wiki::where('domain', $domain)->first(); | ||
|
|
||
| if (!$wiki) { | ||
| return response()->json([ | ||
| 'error' => 'Wiki not found for domain: ' . $domain, | ||
|
outdooracorn marked this conversation as resolved.
Outdated
|
||
| ], 404); | ||
| } | ||
|
|
||
| $wiki->setSetting('wgReadOnly', 'This wiki is currently read-only.'); | ||
|
outdooracorn marked this conversation as resolved.
Outdated
|
||
|
|
||
| return response()->json([ | ||
| 'success' => true, | ||
| 'domain' => $domain, | ||
| 'message' => 'Wiki set to read-only successfully.', | ||
| ]); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\Routes\Backend; | ||
|
|
||
| use App\Wiki; | ||
| use App\WikiSetting; | ||
| use Illuminate\Foundation\Testing\RefreshDatabase; | ||
| use Tests\TestCase; | ||
|
|
||
| class WikiReadOnlyControllerTest extends TestCase { | ||
| use RefreshDatabase; | ||
|
|
||
| protected string $route = '/backend/setWikiReadOnly'; | ||
|
|
||
| public function testItReturns404WhenWikiNotFound() { | ||
| $response = $this->postJson($this->route, [ | ||
| 'domain' => 'nonexistent.wikibase.cloud', | ||
| ]); | ||
|
|
||
| $response->assertStatus(404) | ||
| ->assertJson([ | ||
| 'error' => 'Wiki not found for domain: nonexistent.wikibase.cloud', | ||
| ]); | ||
| } | ||
|
|
||
| public function testSetWikiToReadOnly() { | ||
| $wiki = Wiki::factory()->create([ | ||
| 'domain' => 'somewiki.wikibase.cloud', | ||
| ]); | ||
|
|
||
| $response = $this->postJson($this->route, [ | ||
| 'domain' => 'somewiki.wikibase.cloud', | ||
| ]); | ||
|
|
||
| $response->assertStatus(200) | ||
| ->assertJson([ | ||
| 'success' => true, | ||
| 'domain' => 'somewiki.wikibase.cloud', | ||
| 'message' => 'Wiki set to read-only successfully.', | ||
| ]); | ||
|
|
||
| $this->assertSame( | ||
| 'This wiki is currently read-only.', | ||
| WikiSetting::whereWikiId($wiki->id)->whereName('wgReadOnly')->first()->value | ||
| ); | ||
|
|
||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.