Merge pull request #280 from nextcloud/bugfix/noid/delete-on-object-id

get item by Id and delete it
pull/273/head
Julius Härtl 2019-01-02 16:51:49 +01:00 zatwierdzone przez GitHub
commit 9be2302834
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
4 zmienionych plików z 44 dodań i 13 usunięć

Wyświetl plik

@ -32,6 +32,7 @@ namespace OCA\Social\Interfaces\Activity;
use OCA\Social\AP;
use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Exceptions\UnknownItemException;
use OCA\Social\Interfaces\IActivityPubInterface;
@ -58,15 +59,29 @@ class DeleteInterface implements IActivityPubInterface {
/**
* @param ACore $item
*
* @throws \OCA\Social\Exceptions\InvalidOriginException
* @throws InvalidOriginException
*/
public function processIncomingRequest(ACore $item) {
$item->checkOrigin($item->getId());
if (!$item->gotObject()) {
// // TODO - manage objectId (in case object is missing) -> find the right object and delete it
// if ($item->getObjectId() !== '') {
// }
if ($item->getObjectId() !== '') {
$item->checkOrigin($item->getObjectId());
$types = ['Note', 'Person'];
foreach ($types as $type) {
try {
$interface = AP::$activityPub->getInterfaceForItem($type);
$object = $interface->getItemById($item->getObjectId());
$interface->delete($object);
return;
} catch (UnknownItemException $e) {
} catch (ItemNotFoundException $e) {
}
}
}
return;
}

Wyświetl plik

@ -33,6 +33,8 @@ namespace OCA\Social\Interfaces\Actor;
use daita\MySmallPhpTools\Traits\TArrayTools;
use OCA\Social\Db\CacheActorsRequest;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
@ -107,7 +109,11 @@ class PersonInterface implements IActivityPubInterface {
* @throws ItemNotFoundException
*/
public function getItemById(string $id): ACore {
throw new ItemNotFoundException();
try {
return $this->cacheActorsRequest->getFromId($id);
} catch (CacheActorDoesNotExistException $e) {
throw new ItemNotFoundException();
}
}
@ -134,9 +140,16 @@ class PersonInterface implements IActivityPubInterface {
/**
* @param ACore $item
*
* @throws InvalidOriginException
*/
public function delete(ACore $item) {
$item->checkOrigin(($item->getId()));
/** @var Person $item */
$this->cacheActorsRequest->deleteFromId($item->getId());
}
}

Wyświetl plik

@ -31,6 +31,7 @@ declare(strict_types=1);
namespace OCA\Social\Interfaces;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Model\ActivityPub\ACore;
@ -61,7 +62,7 @@ interface IActivityPubInterface {
/**
* @param string $id
*
* @throw ItemNotFoundException
* @throws ItemNotFoundException
* @return ACore
*/
public function getItemById(string $id): ACore;

Wyświetl plik

@ -101,7 +101,11 @@ class NoteInterface implements IActivityPubInterface {
* @throws ItemNotFoundException
*/
public function getItemById(string $id): ACore {
throw new ItemNotFoundException();
try {
return $this->notesRequest->getNoteById($id);
} catch (NoteNotFoundException $e) {
throw new ItemNotFoundException();
}
}
@ -134,20 +138,18 @@ class NoteInterface implements IActivityPubInterface {
$this->save($item);
}
if ($activity->getType() === Update::TYPE) {
$activity->checkOrigin($item->getId());
$activity->checkOrigin($item->getAttributedTo());
// TODO - check time and update.
// $this->save($item);
}
}
/**
* @param ACore $item
*
* @throws InvalidOriginException
*/
public function delete(ACore $item) {
$item->checkOrigin(($item->getId()));
/** @var Note $item */
$this->notesRequest->deleteNoteById($item->getId());
}