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

[1/2]: Add campaign news functionality #1446

Merged

Conversation

sashko9807
Copy link
Member

Closes #1445 #1352

Motivation and context

This is a desired feature.

Screenshots:

image
image
image

Testing

  1. News article can be added/removed by admins in admin panel
  2. News article can be added/removed by admins or campaign organizer by visiting campaign's URL page
  3. Only admins can change article's state(published or draft)
  4. As long as news article is in draft, campaign's organizer can edit or delete it as wished(as long he or she is the one who published the article in the first place)
  5. Once article is published campaign organizer needs to contact the coordinator, to make any edits to the article

Steps to test

Affected urls

ADDED - campaigns/news
ADDED - campaigns/:slug/news
ADDED - campaigns/:slug/news/admin-panel

Environment

New environment variables:

New or updated dependencies:

Dependency name Previous version Updated version Details
dompurify latest latest To sanitize the HTML content coming from article's description.

@sashko9807 sashko9807 changed the title Add campaign news functionality [1/2]: Add campaign news functionality Jun 14, 2023
@github-actions
Copy link

github-actions bot commented Jun 14, 2023

✅ Tests will run for this PR. Once they succeed it can be merged.

Needed to accomodate latest db changes
DOMpurify needs window object to work which is not available when rendering the component in server, thus we are making sure CampaignNewsList is rendered only on client
We now send everything through the authorization header
@sashko9807 sashko9807 force-pushed the add-campaign-news-functionality branch from e593048 to ff9822b Compare June 18, 2023 13:18
The first and last name of the logged in user will be used as default values if the field is empty
@sashko9807 sashko9807 force-pushed the add-campaign-news-functionality branch from 94e93bb to 79f373a Compare June 27, 2023 12:58
@sashko9807 sashko9807 force-pushed the add-campaign-news-functionality branch from 79f373a to 5d1bd74 Compare June 27, 2023 14:02
@sashko9807 sashko9807 force-pushed the add-campaign-news-functionality branch from 5d1bd74 to afebc6a Compare June 27, 2023 14:18
@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Jun 28, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Jun 28, 2023
{articles?.map((article, index) => {
const documents = GetArticleDocuments(article.newsFiles)
const images = GetArticleGalleryPhotos(article.newsFiles)
const sanitizedDescription = sanitizeHTML(article.description)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well done with introducing secure coding practices to sanitize the HTML!

Comment on lines +132 to +136
<Typography
component={'div'}
className={classes.articleDescription}
dangerouslySetInnerHTML={{
__html: sanitizedDescription.slice(0, CHARACTER_LIMIT) + '...',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you needed to set the html from Quill via dangerouslySetInnerHTML so that you can limit the length of the description.
A safer would be to do with the Quill editor in readonly mode but I don't know how to limit the text size, so unitl we find how, this way is ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quill editor seems to use innerHTML under the hood to display the HTML contents, which is the exact same thing as setting dangerouslySetInnerHTML in react. Not quite sure if it is any safer, in regards of outputting HTML, but the HTML content is being sanitized anyway.

Using dangerouslySetInnerHTML also should be tad a bit faster, as the HTML content is displayed directly, rather than having to wait for the React Quill editor to load.

paddingTop: theme.spacing(0),
paddingLeft: theme.spacing(0),
maxWidth: theme.spacing(18),
marginTop: theme.spacing(-0.5),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK negative margins should be avoided

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this negative margin there is a slight offset between the beginning of the content and the beginning of the timeline component(the dot). Adding any sort of margin to the Timeline component breaks it, thus the need to adjust the content, through negative margin.

I could remove the negative margin if that offset doesn't bother anyone, but so far it doesn't seem to cause any conflict with other DOM elements, in either desktop or mobile viewports.

@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Jul 3, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Jul 3, 2023
@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Jul 3, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Jul 3, 2023
@sashko9807 sashko9807 force-pushed the add-campaign-news-functionality branch from 3913ecb to 6eef16a Compare July 3, 2023 12:56
@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Jul 3, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Jul 3, 2023
@igoychev igoychev merged commit bf6fd67 into podkrepi-bg:master Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Implement a full fledged blog for campaigns related news
2 participants