Skip to content

Commit

Permalink
Finish 5.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Schlaefer committed Sep 21, 2019
2 parents 6ded556 + 7b979ba commit a0b6506
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Lib/Saito/Posting/UserPosting/UserPostingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ protected function _isEditingAllowed(BasicPostingInterface $posting, CurrentUser
}

if ($User->permission('saito.core.posting.edit.restricted')) {
if ($posting->isPinned()) {
if (!$isOwn || $posting->isPinned()) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lib/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$config = [
'Saito' =>
[
'v' => '5.3.2',
'v' => '5.3.3',
'saitoHomepage' => 'https://saito.siezi.com/'
]
];
Expand Down
2 changes: 2 additions & 0 deletions src/Model/Behavior/PostingBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ public function updatePosting(Entry $posting, array $data, CurrentUserInterface

/// must be set for validation
$data['locked'] = $posting->get('locked');
$data['fixed'] = $posting->get('fixed');

$data['pid'] = $posting->get('pid');
$data['time'] = $posting->get('time');
$data['user_id'] = $posting->get('user_id');
Expand Down
3 changes: 2 additions & 1 deletion tests/Fixture/EntryFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ class EntryFixture extends TestFixture
'time' => '2000-01-01 10:59:00',
'last_answer' => '2000-01-01 10:59:00',
'category_id' => 4, // accession = 1
'user_id' => 7
'user_id' => 7,
'fixed' => true,
],
// thread 6
// -------------------------------------
Expand Down
45 changes: 45 additions & 0 deletions tests/TestCase/Lib/Saito/Posting/UserPostingTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,32 @@ public function testIsEditingForbiddenModToLateNotFixed()
$this->assertFalse($result);
}

/**
* Mods don't mod themself.
*/
public function testIsEditingForbiddenModToLateNotFixedOwnPosting()
{
$editPeriod = Configure::read('Saito.Settings.edit_period') * 60;
$entry = [
'user_id' => 1,
'time' => new Time(time() - $editPeriod - 1),
'fixed' => false,
];
$user = [
'id' => 1,
'user_type' => 'mod',
];
$this->Mock->set($entry);
$SaitoUser = new CurrentUser($user);
$SaitoUser->setCategories(new Categories($SaitoUser));
$this->Mock->setCurrentUser($SaitoUser);
$result = $this->Mock->isEditingAllowed();
$this->assertFalse($result);
}

/**
* Mods don't mod themself except for pinned postings.
*/
public function testIsEditingForbiddenModToLateFixed()
{
$editPeriod = Configure::read('Saito.Settings.edit_period') * 60;
Expand All @@ -210,6 +236,25 @@ public function testIsEditingForbiddenModToLateFixed()
$this->assertTrue($result);
}

public function testIsEditingForbiddenModsModOtherUsers()
{
$entry = [
'user_id' => 2,
'time' => new Time(0),
'fixed' => false,
];
$user = [
'id' => 1,
'user_type' => 'mod',
];
$this->Mock->set($entry);
$SaitoUser = new CurrentUser($user);
$SaitoUser->setCategories(new Categories($SaitoUser));
$this->Mock->setCurrentUser($SaitoUser);
$result = $this->Mock->isEditingAllowed();
$this->assertTrue($result);
}

public function testIsEditingForbiddenAdminToLateNotFixed()
{
$entry = [
Expand Down
33 changes: 33 additions & 0 deletions tests/TestCase/Model/Behavior/PostingBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,39 @@ public function testCreateNewThreadButNoCategoryProvided()
$this->assertArrayHasKey('_required', $errors['category_id']);
}

public function testUpdateSuccesModOnPinnedPosting()
{
$now = (string)time();
$edit = ['subject' => $now];

$entity = $this->table->findById(11)->first();

$user = ['id' => 7, 'user_type' => 'mod', 'username' => 'bar'];
$user = CurrentUserFactory::createLoggedIn($user);

$result = $this->table->updatePosting($entity, $edit, $user);

$this->assertEmpty($result->getErrors());
$this->assertEquals($now, $result->get('subject'));
}

public function testUpdateFailureModOnOwnPosting()
{
$now = (string)time();
$edit = ['subject' => $now];

$entity = $this->table->findById(11)->first();
$entity->set('fixed', false);

$user = ['id' => 7, 'user_type' => 'mod', 'username' => 'bar'];
$user = CurrentUserFactory::createLoggedIn($user);

$result = $this->table->updatePosting($entity, $edit, $user);

$errors = $result->getErrors();
$this->assertArrayHasKey('isEditingAllowed', $errors['edited_by']);
}

public function testPrepareChildPosting()
{
$parent = [
Expand Down

0 comments on commit a0b6506

Please sign in to comment.