Skip to content
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

Feature: share articles (back-end part) #1191

Merged
merged 122 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
ab32db0
🗃 NewsItem: added share fields, feedId not null
mnassabain Jan 17, 2021
b3883bf
✨ NewsItem: add share functions (mapper + service)
mnassabain Jan 17, 2021
f5aae86
✨ NewsItem: add share routes + controller func
mnassabain Jan 17, 2021
4868274
add root for access shared items
aureliendvd Jan 26, 2021
73d1489
✨ Get all shared items with an user
Jan 26, 2021
69187cc
add function findAllShared in return
aureliendvd Jan 26, 2021
658ffb3
🔥 findAllShared: add table alias in sql statement
mnassabain Jan 26, 2021
ea1dca8
🔥 shareItem: set unread = true for shared article
mnassabain Jan 26, 2021
ad630ac
✨ Add count for unread items
Jan 26, 2021
80203cf
🎨 Fix function name to sharedCount
Jan 26, 2021
70b8ec9
🐛 sharedCount: fix sql statement bug `1` => 1
mnassabain Jan 26, 2021
ea68c20
✨ ItemController: return sharedCount in index req
mnassabain Jan 26, 2021
e0667b0
(+) Adding sharing_user names to EVERY articles + pre-condition if sh…
Jan 26, 2021
2b9f215
(*) fix: item Model
Jan 26, 2021
9e7a7f6
(*) fix: item Model
Jan 26, 2021
8e66dd8
🐛 Share Item: feed_id not nullable, copy feed_id
mnassabain Jan 27, 2021
630e5b0
Add function for avoid duplicate item (share)
aureliendvd Jan 28, 2021
7984108
✨ Sharing: update ownership in sql (sharedwith)
mnassabain Jan 28, 2021
29f8479
🚑 Fix bug - other user feeds show for shared item
mnassabain Jan 28, 2021
95180db
🐛 Added sharedCount to feedController index resp.
mnassabain Jan 29, 2021
826c036
🐛 Fix readAll: cannot read items we shared
mnassabain Feb 7, 2021
8ade6ea
🩹 Patch readAll: concerns items shared with user
mnassabain Feb 7, 2021
8cbe242
🩹 Patch getNewestItemId: include shared articles
mnassabain Feb 7, 2021
cb14672
🩹 ItemMapper->deleteUser: include shared items
mnassabain Feb 7, 2021
dbf3a5c
🩹 Return starredCount in newItems response params
mnassabain Feb 7, 2021
df197e3
✅ Update tests to contain share data
mnassabain Feb 7, 2021
4d4fca7
✅ Unary test for itemShare from itemService class
Feb 16, 2021
1a9db04
Add tests setSharedBy and setSharedWith
aureliendvd Feb 16, 2021
4ad48be
✅ Add tests: testFindAllShared, testShare + ...
mnassabain Feb 16, 2021
fe34696
💡 Added comments to ItemMapper share fncts
mnassabain Feb 18, 2021
890b3b4
🚧 ItemService, Controller: added basic sharing
mnassabain Feb 23, 2021
fb801b6
✨ ItemMapperV2: added findAllSharedWithUser funct
mnassabain Feb 24, 2021
bf4c8e4
✨ ItemMapperV2: include shared in functions
mnassabain Feb 24, 2021
0654c85
✨ ItemMapperV2: include shared in functions
mnassabain Feb 24, 2021
ffb1ead
✨ ItemMapperV2: exclude shared items in functions
mnassabain Feb 24, 2021
1136889
✨ ItemServiceV2: add findAllSharedWithUserWithFilters
mnassabain Feb 24, 2021
241b266
✨ ItemController (index): add case for shared items
mnassabain Feb 24, 2021
c0208e2
✨ Implementer shared getter + add count in request
mnassabain Feb 24, 2021
1d0e4ca
✨ Add findAllSharedAfter
mnassabain Feb 24, 2021
c9b664e
🩹 Remove traces of feed_id being nullable
mnassabain Feb 24, 2021
f7627fd
🔥 Remove old ItemMapper & ItemService
mnassabain Feb 24, 2021
11290ff
✅ Fix ItemController share tests
mnassabain Feb 25, 2021
b5d8c29
🗃 Change share migration version
mnassabain Feb 27, 2021
2c96197
✅ ItemControllerTest: added share tests (WIP)
mnassabain Feb 27, 2021
3165e06
🥅 ItemService: catch NotFoundException + cleanup
mnassabain Feb 27, 2021
e4ce0d6
✅ ItemServiceTest: test share function
mnassabain Feb 27, 2021
3292d00
✅ ItemServiceTest: test share functions
mnassabain Feb 27, 2021
e7b5820
✅ ItemMapperTest: test findAllSharedWithUser func
mnassabain Feb 27, 2021
f863a2c
✅ ItemMapperTest: add tests for findAllSharedAfter
mnassabain Feb 27, 2021
fa50791
fix test readAll
aureliendvd Feb 28, 2021
ac401f4
Fix test FindAllFolderSearchId
aureliendvd Feb 28, 2021
069e04a
Fix test findAllFolderHideReadInvertOrder
aureliendvd Feb 28, 2021
d8ed7e8
Fix test findAllFolderIdNull and findAllFolderHideRead
aureliendvd Feb 28, 2021
67651b4
Fix test findAllFeedSearch and findAllFeedHideRead
aureliendvd Feb 28, 2021
a8267c2
fix test findAllFeed
aureliendvd Feb 28, 2021
0cf7f55
Fix testFindAllItemsInvalid, testFindAllAfterInvalid, testFindAllAfte…
aureliendvd Feb 28, 2021
466f35c
Fix testFindAllItemsStarredSearch, testFindAllItemsStarred, testFind…
aureliendvd Feb 28, 2021
69ccd83
Fix tests testFindAllInFolderAfterHideRead, testFindAllInFolderAfter…
aureliendvd Feb 28, 2021
48dab07
Fix testNewest
aureliendvd Feb 28, 2021
42358a9
✅ Fix FeedControllerTest tests
Feb 28, 2021
484f97a
Fix testFindForUserByGUIDHash
aureliendvd Feb 28, 2021
016f42a
Fix findFromUser, testFindAllFromUserWithParams, testFindAllFromUser
aureliendvd Feb 28, 2021
50a0d76
✅ Fix those tests -> ItemControllerTest:
Feb 28, 2021
d46db75
🚨 Fix linter in those classes:
Feb 28, 2021
e20a4a0
🧹 Cleanup test files: added new lines
mnassabain Feb 28, 2021
34b536f
🔀 Resolving merge: moving shared tests
mnassabain Feb 28, 2021
d024f15
✅ Fix tests in ItemMapperAfterTest:
Feb 28, 2021
35dfc2e
✅ Fix tests in ItemMapperAfterTest:
Feb 28, 2021
93bb9f7
✅ Fix tests in ItemMapperPaginatedTest:
Feb 28, 2021
b82031f
✅ ItemMapperPaginatedTest: update tests
mnassabain Feb 28, 2021
6caf3e7
🎨 ItemMapperV2: add new offset code (findShared)
mnassabain Feb 28, 2021
5994b1f
✅ Update find shared items tests
mnassabain Feb 28, 2021
e2aa333
🗑 '!=' is discouraged, replaced by '!=='
Feb 28, 2021
d72ea2d
🗑 '!=' is discouraged, replaced by '!=='
NicoWend Feb 28, 2021
3152e05
✏️ Fix share test name typo
mnassabain Mar 1, 2021
dcdaed4
🔥 Remove changes from front-end for back-end pr
mnassabain Mar 2, 2021
179d407
🔥 Remove front-end edit from back-end pr
mnassabain Mar 2, 2021
aaf635d
📝 Update CHANGELOG and AUTHORS
mnassabain Mar 2, 2021
33d53a7
🎨 Update item share: add items to dummy feed
mnassabain Mar 3, 2021
945b674
🔥 Remove old share item logic & functions
mnassabain Mar 3, 2021
e66f809
🔥 Remove old share logic from tests & old tests
mnassabain Mar 3, 2021
174c6e8
✨ Add FeedServiceV2 DI into ItemServiceV2
mnassabain Mar 3, 2021
f51cd18
✨ Add FeedService DI into ItemService in tests
mnassabain Mar 3, 2021
62a8a0b
🎨 Item.php: Remove shared_with
mnassabain Mar 3, 2021
9823322
🎨 Item.php: make shared_by nullable
mnassabain Mar 3, 2021
329401c
🎨 Update share migration
mnassabain Mar 3, 2021
717393e
🚑 Fix circular inclusion: create ShareService
mnassabain Mar 3, 2021
d35a1b4
🩹 Patch ItemController + test to use ShareService
mnassabain Mar 3, 2021
761ffec
🩹 Patch ItemControllerTest to mock shareService
mnassabain Mar 3, 2021
5a669f9
🚑 Fix errors in ShareService
mnassabain Mar 4, 2021
bef9aa6
🚑 Fix ItemController::share
mnassabain Mar 4, 2021
d0f21ad
✅ Update ItemController share tests
mnassabain Mar 4, 2021
d35efa4
🚑 Fix exception handling in ShareService
mnassabain Mar 4, 2021
f653643
✅ Update ItemTest - remove sharedWith field
mnassabain Mar 4, 2021
e012eda
✅ WIP add ShareServiceTest
mnassabain Mar 4, 2021
4b953f2
✅ Update ItemServiceTest: remove share tests
mnassabain Mar 4, 2021
b1f17a0
🚑 Fix newsItem insert error
mnassabain Mar 5, 2021
d749972
🎨 Share migration: remove shared_by default value
mnassabain Mar 5, 2021
001da1e
🧹 Cleanup code, remove spaces, rename variables
mnassabain Mar 5, 2021
a8326e9
♻️ Item: Remove isShared
mnassabain Mar 5, 2021
bd19bac
🌐 ShareService: Localize dummy feed title
mnassabain Mar 6, 2021
357f6dd
🎨 ShareService: update dummy feed URL
mnassabain Mar 6, 2021
b74cbb5
✅ Update test to include localization
mnassabain Mar 6, 2021
b9e1eb4
🧹 ShareService: rename $url to $urlGenerator
mnassabain Mar 7, 2021
3c871ac
✨ Update Item model: add sharedByDisplayName
mnassabain Mar 18, 2021
08c78b0
✨ Item: add sharer display name in findEntities
mnassabain Mar 18, 2021
8d9a47e
✅ Item: update tests - include sharer display name
mnassabain Mar 18, 2021
d50da70
🗃 Update share migration version
mnassabain Mar 18, 2021
ef60dd9
🩹 Item: mark categoriesJson as updated in clone
mnassabain Mar 18, 2021
24dc08a
🩹 Fix issues after rebase
mnassabain Mar 18, 2021
3276f40
✏️ Fix phpcs indentation error
mnassabain Mar 18, 2021
42302b3
🎨 Type hint ItemController share function
mnassabain Mar 19, 2021
fb6bdc5
🔥 Remove UserManager code from ItemMapper & tests
mnassabain Mar 19, 2021
de7a6cd
✨ Add sharer display name into shared items
mnassabain Mar 19, 2021
ab907f2
✅ Add + update sharer display name tests
mnassabain Mar 19, 2021
b93058f
✏️ Fix comments in ShareService
mnassabain Mar 19, 2021
f4dbed2
🩹 Fix sharedByDisplayName bug:
mnassabain Mar 20, 2021
af1ecc2
✅ Added test for sharedByDisplayName field
mnassabain Mar 20, 2021
37dee85
🎨 Rename $l to $l10n
mnassabain Mar 29, 2021
7adcdac
🩹 Fix rebase errors
mnassabain Mar 29, 2021
3bc81f5
🩹 Item: change $sharedBy to string|null in annot.
mnassabain Mar 29, 2021
0d340aa
🩹 Fix rebase issues
mnassabain Apr 8, 2021
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
8 changes: 7 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,10 @@
* [waffshappen](mailto:[email protected])
* [wizdude](mailto:[email protected])
* [zero77](mailto:[email protected])
* [Éloi Rivard](mailto:[email protected])
* [Éloi Rivard](mailto:[email protected])
* [Marco Nassabain](mailto:[email protected])
* [Nicolas Wendling](mailto:[email protected])
* [Jimmy Huynh](mailto:[email protected])
* [Aurélien David](mailto:[email protected])
* [Hamza Elhaddad](mailto:[email protected])
* [Ilyes Chergui-Malih](mailto:[email protected])
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ The format is almost based on [Keep a Changelog](https://keepachangelog.com/en/1
- Search: Add folder search (#1215)
- Improve test coverage (#1263)
- Allow directly adding a feed without going through the discovery process (#1265)
- Implemented sharing news items between nextcloud users (#1191)
- Updated the news items table in DB to include sharer data (#1191)
- Added route for sharing news items (#1191)
- Added share data in news items serialization (#1191)
- Added tests for the news items share feature (#1191)

### Fixed
- Do not show deleted feeds in item list (#1214)
Expand Down
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
['name' => 'item#read', 'url' => '/items/{itemId}/read', 'verb' => 'POST'],
['name' => 'item#read_multiple', 'url' => '/items/read/multiple', 'verb' => 'POST'],
['name' => 'item#star', 'url' => '/items/{feedId}/{guidHash}/star', 'verb' => 'POST'],
['name' => 'item#share', 'url' => '/items/{itemId}/share/{shareRecipientId}', 'verb' => 'POST'],

// export
['name' => 'export#opml', 'url' => '/export/opml', 'verb' => 'GET'],
Expand Down
35 changes: 33 additions & 2 deletions lib/Controller/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use \OCA\News\Service\Exceptions\ServiceException;
use \OCA\News\Service\Exceptions\ServiceNotFoundException;
use \OCA\News\Service\ItemServiceV2;
use \OCA\News\Service\ShareService;
use OCP\IUserSession;

/**
Expand All @@ -43,6 +44,10 @@ class ItemController extends Controller
* @var FeedServiceV2
*/
private $feedService;
/**
* @var ShareService
*/
private $shareService;
/**
* @var IConfig
*/
Expand All @@ -52,12 +57,14 @@ public function __construct(
IRequest $request,
FeedServiceV2 $feedService,
ItemServiceV2 $itemService,
ShareService $shareService,
IConfig $settings,
?IUserSession $userSession
) {
parent::__construct($request, $userSession);
$this->itemService = $itemService;
$this->feedService = $feedService;
$this->shareService = $shareService;
$this->settings = $settings;
}

Expand Down Expand Up @@ -169,7 +176,8 @@ public function index(
);
break;
}
$return['items'] = $items;
// Map sharer display names onto shared items
$return['items'] = $this->shareService->mapSharedByDisplayNames($items);

// this gets thrown if there are no items
// in that case just return an empty array
Expand Down Expand Up @@ -229,7 +237,8 @@ public function newItems(int $type, int $id, $lastModified = 0): array
$return['newestItemId'] = $this->itemService->newest($this->getUserId())->getId();
$return['feeds'] = $this->feedService->findAllForUser($this->getUserId());
$return['starred'] = count($this->itemService->starred($this->getUserId()));
$return['items'] = $items;
// Map sharer display names onto shared items
$return['items'] = $this->shareService->mapSharedByDisplayNames($items);

// this gets thrown if there are no items
// in that case just return an empty array
Expand Down Expand Up @@ -318,4 +327,26 @@ public function readMultiple(array $itemIds): void
}
}
}


/**
* @NoAdminRequired
*
* @param int $itemId Item to share
* @param string $shareRecipientId User to share the item with
*/
public function share(int $itemId, string $shareRecipientId)
{
try {
$this->shareService->shareItemWithUser(
$this->getUserId(),
$itemId,
$shareRecipientId
);
} catch (ServiceNotFoundException $ex) {
return $this->error($ex, Http::STATUS_NOT_FOUND);
}

return [];
}
}
64 changes: 63 additions & 1 deletion lib/Db/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class Item extends Entity implements IAPI, \JsonSerializable
protected $starred = false;
/** @var string|null */
protected $categoriesJson;
/** @var string|null */
protected $sharedBy;
/** @var string|null */
protected $sharedByDisplayName;

public function __construct()
{
Expand All @@ -90,6 +94,33 @@ public function __construct()
$this->addType('unread', 'boolean');
$this->addType('starred', 'boolean');
$this->addType('categoriesJson', 'string');
$this->addType('sharedBy', 'string');
}

public function __clone()
{
$this->resetUpdatedFields();
$this->markFieldUpdated('contentHash');
$this->markFieldUpdated('guidHash');
$this->markFieldUpdated('guid');
$this->markFieldUpdated('url');
$this->markFieldUpdated('title');
$this->markFieldUpdated('author');
$this->markFieldUpdated('pubDate');
$this->markFieldUpdated('body');
$this->markFieldUpdated('enclosureMime');
$this->markFieldUpdated('enclosureLink');
$this->markFieldUpdated('mediaThumbnail');
$this->markFieldUpdated('mediaDescription');
$this->markFieldUpdated('feedId');
$this->markFieldUpdated('lastModified');
$this->markFieldUpdated('searchIndex');
$this->markFieldUpdated('rtl');
$this->markFieldUpdated('fingerprint');
$this->markFieldUpdated('unread');
$this->markFieldUpdated('starred');
$this->markFieldUpdated('categoriesJson');
$this->markFieldUpdated('sharedBy');
}

/**
Expand Down Expand Up @@ -285,6 +316,16 @@ public function isUnread(): bool
return $this->unread;
}

public function getSharedBy(): ?string
{
return $this->sharedBy;
}

public function getSharedByDisplayName(): ?string
{
return $this->sharedByDisplayName;
}

/**
* @return null|string
*/
Expand Down Expand Up @@ -327,7 +368,9 @@ public function jsonSerialize(): array
'rtl' => $this->getRtl(),
'intro' => $this->getIntro(),
'fingerprint' => $this->getFingerprint(),
'categories' => $this->getCategories()
'categories' => $this->getCategories(),
'sharedBy' => $this->getSharedBy(),
'sharedByDisplayName' => $this->getSharedByDisplayName()
];
}

Expand Down Expand Up @@ -509,6 +552,25 @@ public function setTitle(string $title = null): self
return $this;
}

public function setSharedBy(string $sharedBy = null): self
SMillerDev marked this conversation as resolved.
Show resolved Hide resolved
{
if ($this->sharedBy !== $sharedBy) {
$this->sharedBy = $sharedBy;
$this->markFieldUpdated('sharedBy');
}

return $this;
}

public function setSharedByDisplayName(string $sharedByDisplayName = null): self
{
if ($this->sharedByDisplayName !== $sharedByDisplayName) {
$this->sharedByDisplayName = $sharedByDisplayName;
}

return $this;
}

public function setUnread(bool $unread): self
{
if ($this->unread !== $unread) {
Expand Down
53 changes: 53 additions & 0 deletions lib/Migration/Version150400Date20210318215425.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

declare(strict_types=1);

namespace OCA\News\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Auto-generated migration step: Please modify to your needs!
*/
class Version150400Date20210318215425 extends SimpleMigrationStep {

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if ($schema->hasTable('news_items')) {
$table = $schema->getTable('news_items');
$table->addColumn('shared_by', 'string', [
'notnull' => false,
'length' => 64
]);
}

return $schema;
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}
Loading