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

Conversation

mnassabain
Copy link
Contributor

@mnassabain mnassabain commented Feb 20, 2021

🚀 Features

This update contains the following features:

  • Possibility to share an article on social media (Facebook, Twitter) or via mail
  • Possibility to share an article with a fellow nextcloud user
  • Allow users to view articles that are shared with them
  • Tests validating the share functionality
  • UI/UX friendly design

🖱️ UI/UX implementation

  • Each article has now a share button next to the star and read buttons

image

  • Clicking on the button opens a dropdown menu, allowing users to either share the article on social media, or search for a user and share with them. Clicking on a user shares the article with them.

image

  • Each user can view articles that were shared with them by clicking on the "Shared" menu. Each available article can be starred, marked as read/unread, and even shared with someone else

image

💻 Code implementation

Sharing an article is implemented by duplicating it. Here's a detailed analysis of our decision.

❌ Idea 1: Sharing by reference

  • Firstly, we have considered to share by reference, adding a table with three fields : item_id, shared_by, and shared_with.
  • This idea avoids data redundancy
  • However, other functionalities, like starring, or marking an item as read, wouldn't work. starred and unread are columns of the news_items model, making it a one-on-one relation. This means that a shared article also shares its' starred and unread state between users, which is something we don't want.
  • We could implement the starred and unread fields into the share table, however, this would create a lot of code redundancy, since we would have to rewrite the same code, only for another object.

✅ Idea 2: Sharing by copying

  • This idea seems to work better.
  • Each item could be starred or read independently, since each user has his own copy.
  • This would come at a cost of some data duplication, however, it would save us from code redundancy.
  • Here's a step-by-step process of sharing an item:
    1. User "A" decides to share an item with user "B".
    2. We duplicate the item.
    3. We initialize the values of the duplicated item:
      • starred = false
      • unread = true
      • shared_by = "A"
      • shared_with = "B"
      • feed_id - same as the original article - a shared item is considered to be still "owned" by "A", and is in his feed. This allows us to track the origin of the shared article.
    4. The new item is inserted into the DB.
  • We needed to modify some existing code in order for a user to access items shared with them. A couple of functions in the ItemMapper have been modified, mostly with the following update:
// when fetching articles for a user

WHERE
(feeds.user_id = ? AND items.shared_by = '')
OR
items.shared_with = ?

// '?' being the user id

// either the article is in the users feed and not shared
// (a shared item is still in the sharers feed, however it's not really considered as theirs)
// or the article is shared with them

Share module integration

  • The share functions and more specifically find shared items functions are separated from the findAllItems functions. We weren't really sure if we should add a switch case to the findAllItems checking if the item is shared.
  • However we've eventually decided to separate the share module from those functions. We don't really have any strong arguments for this, other than saving us from joining tables and module separation.
  • If you find the alternative as a better solution, we could work on that. It seems to be a more compact solution, which allows us to avoid code duplication

🧪 Tests

All of our functions are tested to work properly, and existing tests were modified to take into account the share data.

🛑 Known issues - FIXED

  • When searching for a user, when writing their full username, the sharee api will not return the user. We're not sure if it's a problem in our code, in the sharee API, or in our dev environments. We are still looking into this

👥 Team

We're a team of six students working on this project for our university. Here are the members:

  • Marco NASSABAIN
  • Nicolas WENDLING
  • Jimmy HUYNH
  • Aurélien DAVID
  • Hamza ELHADDAD
  • Ilyes CHERGUI-MALIH

We are from the University of Strasbourg. Special thanks for M. Julien GOSSA for giving us this subject and helping us getting started.

🗓️ Future updates

We are currently starting to work on the addition of three new functionalities for the next part of our project :

  • Adding an excerpt of the article to the social media post
  • Automatic hashtag finding for the social media post
  • Allowing admins to share feeds with their group (discussion)

🙏 Final words

We have been working on this project for a while, and we have thoroughly studied the existing code before contributing. We have tried our best to write good and understandable code. We have ran manual and automatic tests which the functionality passes.

However, it is possible that we have a couple of bugs lying around. We're open to critisicm, and we'd like to hear what you think about our work.

I hope you like our contribution, as much as we liked contributing! Thank you.

@SMillerDev
Copy link
Contributor

There is 207 files changed and there are code conflicts. Please split this review into at the very least API and frontend changes and make sure it's actually mergable.

@Grotax
Copy link
Member

Grotax commented Feb 21, 2021

First good step would be to remove all the language file changes, we don't need those and it makes the overview difficult. But I appreciate the effort.
https://github.com/nextcloud/news/blob/master/CONTRIBUTING.md#translation

@mnassabain
Copy link
Contributor Author

Thank you for the feedback.
I have started by removing all the translation files.

We have just realised that we are actually way behind your recent changes, so we will take some time to adapt our code to make it match your updates.

@codecov-io
Copy link

codecov-io commented Feb 28, 2021

Codecov Report

Merging #1191 (dc4c101) into master (da61c93) will increase coverage by 0.51%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1191      +/-   ##
============================================
+ Coverage     86.43%   86.94%   +0.51%     
- Complexity      708      724      +16     
============================================
  Files            61       62       +1     
  Lines          2543     2620      +77     
============================================
+ Hits           2198     2278      +80     
+ Misses          345      342       -3     
Impacted Files Coverage Δ Complexity Δ
lib/Controller/ItemController.php 100.00% <100.00%> (ø) 25.00 <2.00> (+2.00)
lib/Db/Item.php 100.00% <100.00%> (ø) 88.00 <7.00> (+7.00)
lib/Service/ShareService.php 100.00% <100.00%> (ø) 7.00 <7.00> (?)
lib/Fetcher/FeedFetcher.php 88.57% <0.00%> (-0.17%) 37.00% <0.00%> (ø%)
lib/Service/FeedServiceV2.php 100.00% <0.00%> (ø) 28.00% <0.00%> (ø%)
lib/Command/Debug/ItemList.php 0.00% <0.00%> (ø) 6.00% <0.00%> (ø%)
lib/Command/Debug/FeedItemList.php 0.00% <0.00%> (ø) 6.00% <0.00%> (ø%)
lib/Command/Debug/FolderItemList.php 0.00% <0.00%> (ø) 8.00% <0.00%> (ø%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da61c93...dc4c101. Read the comment docs.

@SMillerDev
Copy link
Contributor

Like mentioned before:

Please split this review into at the very least API and frontend changes [...]

In addition to that we'll need all commits to have a sign off to comply with the DCO requirement for the nextcloud organisation.

@mnassabain
Copy link
Contributor Author

Yup, still working on it.
It's taking a bit more time than expected because rebasing/cherry-picking requires us to re-resolve old merge conflicts, and we're trying to configure git to remember the resolves and replay them.

Should be done soon, I'll leave a comment when it's ready for review :)

@mnassabain mnassabain force-pushed the feature-share branch 20 times, most recently from aa1bc7b to 0f4cffd Compare March 2, 2021 22:31
@mnassabain mnassabain changed the title Feature: share articles Feature: share articles (back-end part) Mar 2, 2021
@mnassabain
Copy link
Contributor Author

mnassabain commented Mar 2, 2021

Ok, I think we're ready for review!
This pull request now contains only back-end changes (tests included, please don't ask me to split those too haha it's hard work)
Pull request #1217 contains changes to the front-end.

We've tried to write clear code, and comment parts that were a bit complicated. Also I've put some details about our implementation in the pr description. I'll be watching for your questions or comments!

Thanks

mnassabain and others added 18 commits April 8, 2021 18:51
- added field + setters + getters
- include field in serialized Item

Signed-off-by: Marco Nassabain <[email protected]>
Signed-off-by: Marco Nassabain <[email protected]>
Signed-off-by: Marco Nassabain <[email protected]>
Co-authored-by: Sean Molenaar <[email protected]>
Signed-off-by: Marco Nassabain <[email protected]>
- Add mapSharedByDisplayNames in ShareService
- Update ItemController to call function on items

Signed-off-by: Marco Nassabain <[email protected]>
- added testMapSharedByDisplayNames
- updated ItemController tests to expect call to function

Signed-off-by: Marco Nassabain <[email protected]>
- setting sharedByDisplayName shouldn't mark it as updated

Signed-off-by: Marco Nassabain <[email protected]>
Signed-off-by: Marco Nassabain <[email protected]>
Signed-off-by: Marco Nassabain <[email protected]>
Signed-off-by: Marco Nassabain <[email protected]>
@mnassabain
Copy link
Contributor Author

Done!

@SMillerDev SMillerDev merged commit 391dd25 into nextcloud:master Apr 8, 2021
Grotax added a commit that referenced this pull request May 22, 2021
Changed
- News now requires a 64bit OS
- v2 API implementation (folder part)
- 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)
- Added sharing articles with nextcloud users (#1217)
- Added sharing articles on social media (Facebook, Twitter) or mail (#1217)

Signed-off-by: Benjamin Brahmer <[email protected]>
@Grotax Grotax mentioned this pull request May 22, 2021
Grotax added a commit that referenced this pull request May 22, 2021
Changed
- News now requires a 64bit OS
- v2 API implementation (folder part)
- 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)
- Added sharing articles with nextcloud users (#1217)
- Added sharing articles on social media (Facebook, Twitter) or mail (#1217)

Signed-off-by: Benjamin Brahmer <[email protected]>
@SMillerDev
Copy link
Contributor

#1375

Grotax added a commit that referenced this pull request Jul 1, 2021
There are no additional changes compared to the latest beta.

Changed
- News now requires a 64bit OS
- v2 API implementation (folder part)
- 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)
- Added sharing articles with nextcloud users (#1217)
- Added sharing articles on social media (Facebook, Twitter) or mail (#1217)
- Allow installation on Nextcloud v22
- Remove deprecated API endpoints and occ command (#935)
  - /api/v1-2/user
  - /api/v1-2/user/avatar
  - ./occ news:updater:all-feeds
- added feed search (#1402)

Fixed
- allow calling `/items?getRead=false` without a feed/folder (#1380 #1356)
- newestId does not return newest ID but last updated (#1339)
- removed reference for deleted repair-steps (#1399)
- Fix NotNullConstraintViolation when sharing news items with users (#1406)

Signed-off-by: Benjamin Brahmer <[email protected]>
@Grotax Grotax mentioned this pull request Jul 1, 2021
Grotax added a commit that referenced this pull request Jul 4, 2021
There are no additional changes compared to the latest beta.

Changed
- News now requires a 64bit OS
- v2 API implementation (folder part)
- 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)
- Added sharing articles with nextcloud users (#1217)
- Added sharing articles on social media (Facebook, Twitter) or mail (#1217)
- Allow installation on Nextcloud v22
- Remove deprecated API endpoints and occ command (#935)
  - /api/v1-2/user
  - /api/v1-2/user/avatar
  - ./occ news:updater:all-feeds
- added feed search (#1402)

Fixed
- allow calling `/items?getRead=false` without a feed/folder (#1380 #1356)
- newestId does not return newest ID but last updated (#1339)
- removed reference for deleted repair-steps (#1399)
- Fix NotNullConstraintViolation when sharing news items with users (#1406)

Signed-off-by: Benjamin Brahmer <[email protected]>
Neo11 pushed a commit to Neo11/news that referenced this pull request May 28, 2022
Changed
- News now requires a 64bit OS
- v2 API implementation (folder part)
- Implemented sharing news items between nextcloud users (nextcloud#1191)
- Updated the news items table in DB to include sharer data (nextcloud#1191)
- Added route for sharing news items (nextcloud#1191)
- Added share data in news items serialization (nextcloud#1191)
- Added tests for the news items share feature (nextcloud#1191)
- Added sharing articles with nextcloud users (nextcloud#1217)
- Added sharing articles on social media (Facebook, Twitter) or mail (nextcloud#1217)

Signed-off-by: Benjamin Brahmer <[email protected]>
Neo11 pushed a commit to Neo11/news that referenced this pull request May 28, 2022
There are no additional changes compared to the latest beta.

Changed
- News now requires a 64bit OS
- v2 API implementation (folder part)
- Implemented sharing news items between nextcloud users (nextcloud#1191)
- Updated the news items table in DB to include sharer data (nextcloud#1191)
- Added route for sharing news items (nextcloud#1191)
- Added share data in news items serialization (nextcloud#1191)
- Added tests for the news items share feature (nextcloud#1191)
- Added sharing articles with nextcloud users (nextcloud#1217)
- Added sharing articles on social media (Facebook, Twitter) or mail (nextcloud#1217)
- Allow installation on Nextcloud v22
- Remove deprecated API endpoints and occ command (nextcloud#935)
  - /api/v1-2/user
  - /api/v1-2/user/avatar
  - ./occ news:updater:all-feeds
- added feed search (nextcloud#1402)

Fixed
- allow calling `/items?getRead=false` without a feed/folder (nextcloud#1380 nextcloud#1356)
- newestId does not return newest ID but last updated (nextcloud#1339)
- removed reference for deleted repair-steps (nextcloud#1399)
- Fix NotNullConstraintViolation when sharing news items with users (nextcloud#1406)

Signed-off-by: Benjamin Brahmer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Impact API/Backend code enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants