How to implement an admin approval system for posting blogs in node.js and express application? - node.js

Okay. I might look silly to ask this question, but hold on and help me out.
I have made a Blog app using Node.js, Express, and MongoDB. The user has to sign in to create a blog and post it on the site. But, now I want to design a system so that an admin has to approve the user's post before actually publishing that particular blog on the site.
I want to create an admin panel where he/she can see all the user's posts with username and userid. And, I want an approval button or such thing on every post, so that only after admin approves the user's post, it is published on the actual site.
Please suggest me the solution to achieve this.
PS: I do not know how to create the admin panel at all.

I understand you are new in Node.js. So you should know some basic knowledge like the basic API call, how to render a page, creating a Model and also Save, Update And Delete.
If you know about Model, View, Controller, and Routes. Then you can understand the following methodology.
First of all, the Admin Panel is a page like other pages that can only access Admin. For this, you can make a field in the USER model name isAdmin which probably by default False. If isAdmin == True then you can render those Admin Page. You can put a button on the home page which can only show when isAdmin == True. After clicking the button it will take you to that Admin page.
Then, you have to make a field named isApproved in the POST model which also by default False.
In Admin Page you can make a button Approve Post with other information when you click on that button isApproved field of the post will become True.
Finally, A post will show when isApproved == True. You can comment for further solution.

Related

Handle multiple users in Node js Express application

I am new to NodeJs, and as a practice I am trying to build a blogging API using node and express. I am looking for a way to implement the following tasks :
Any user should be able to look at other user's profile, but not edit it.
Any user should be able to view any blog but edit only their own blogs
The way I was thinking of doing this is :
When a user logs in, store the user's id in a cookie (either a JWT token or something else), and whenever a profile / blog is to be displayed, check if the author of the blog / profile has the same Id as the one stored in cookie, if it is then allow the option to edit, else don't.
Would like to know if this is correct way to do it, also are there any better ways to achieve this ?
A better approach is to use an authentication middleware:
This blog post briefed it: https://medium.com/quick-code/handling-authentication-and-authorization-with-node-7f9548fedde8
The explanation of the concept is that you do not need to add the auth middleware to the user's profile GET endpoint (i.e the endpoints that gets user profile).
To edit a blog you need to do some checks if the id of the one who created the blog post matches.
I have a project you can check: https://github.com/razaqfatiu/Teamwork/blob/develop/api/controllers/article.js
The editArticle function on line 41 should be of help

Is it possible to check whether a button has been clicked or not in actions on google?

At the end of the conversation I am creating a basic card which asks for a review. If the user does give a review I don't want to ask them again the next time. So what would be the best way to do so ? At the moment I am wondering whether I can track whether they have clicked on the button which leads to the review link provided in the BasicCard or not.
The link button does not report anything back to your fulfillment, so there is no direct way to know if the link has been clicked.
One possible workaround is a little convoluted, but would let you track if the link has been followed. It assumes, however, that you are storing a unique userid in the user storage (and that this is allowed in your jurisdiction). In this case what you can do is
When you generate the card, the link would go to another URL that you control - not the review URL directly.
The link would also include a parameter that includes the userid you've generated for them.
At the code running at this link, you get the userid parameter, mark in the database that they've been sent to the review page, then redirect them to the review page.
In future conversations, you can get the userid from their user storage and check your own records to see if they've been sent to the review page. From here, you can decide if you want to show the card, include the link, etc.

Kentico 8.2 Newsletter Link and unsubscribe link

I have created a contact form under Forms with first name, last name, and email that is designed to sign up people for a newsletter. I then created a page so when people click on the link placed on the home page it takes them to a page with the contact form.
Right now when I test the subscribe form out, the data does to to the "back office" where it can be retrieved. However, the information I entered is still in the text fields and, unless you notice the small flash of the web page, one might think nothing happened.
I'd like to know how (or be directed to somewhere in the Kentico 8.2 Documentation) I can make it so that the fields clear and a message appears saying "You have been subscribed to the newsletter." That message can either appear on a separate page on the web site, or send a message to the user email, or both. In the Email Marketing part under the templates there are Subscribe and Unsubscribe templates, but I don't know how to use those.
The other issue is creating an Unsubscribe link. Ideally that will open up to a new page saying "You have been unsubscribed." Kentico 8.2 has an unsubscribe page you can create where the user enters in an email address and then hits the Unsubscribe Request button, but I'd rather not do that. As it stands, I did create a page with that form and tested it, but it doesn't seem to work.
When you edit your form, under general tab, there are settings for what will happen after the form is submitted:
Display Text
Redirect to URL
Clear Form
Continue Editing.
Currently you're using the standard Forms application for something which can be managed through the Newsletter/Email Campaign module. Read the documentation more on how to configure this vs. using the Forms application.
Essentially the steps you will do are:
Create your newsletter following the directions in the linked documentation.
Place a newsletter subscription webpart on your page template and configure it to the newsletter you want them to subscribe to.
Use the out of the box unsubscribe feature to allow users to unsubscribe to your newsletter. No need to add any page to the content tree but you can if you want OR just use the OOTB functionality.
If you follow the documentation you should be able to get it setup properly vs. using an online form.

Facebook Like button that posts to page wall as well?

I have a online shop. On the home page there are products, with a like button. When a person clicks on the button, it goes to their profile and it says that they liked it. However, I also want when the user clicks like, that it is posted to my BUSINESS FACEBOOK PAGE as well.
1. Is this possible?
2. Is this possible using the standard facebook like button?
I am implementing this on a site with Drupal which is using the FBConnect module.
Yes
No
We can't do anything with that standard facebook like button. That's the way it is. However, we can achieve what you want by other means.
Since you're the owner of the business page, you can get the access_token for it, preferably with publish_stream permission. Then you can use edge.create event on the pages with the like button and detect that to publish on your business wall.
Check the links. For the access_token / authentication link, look for "Page Login".

Wordpress - Allow a userclass to save a page as a draft - but not publish w/o admin approval

I want to make a user class that can edit pages, and save them as a draft without being able to publish it. An admin would have to go in and publish the draft once they approve it.
The idea is similar to TDO Mini Forms except this will be done within the Wordpress admin panel, not be a form, and they must be a registered user in a specific class to do this.
Thanks!
Install the Members Plugin, create a role for these users (or reuse the author role) and do not give them the publish_posts capability.
Here is a screenshot of how I handle this case on one of my clients site:
Update
To forbid publishing of edits you have to hook into the action transition_post_status and watch for changes. This actions tells you the old and the new post status and the post id:
add_action('transition_post_status', 'my_watcher', 10, 3);
function my_watcher($new_status, $old_status, $postid)
{
// Get post content etc.
$post = &get_post( $postid );
// Compare the content and/or the status, do something.
}
In my case, this was overelaborate, plus we were afraid, users would feel patronized too much.
I just made a dashboard widget¹ to list all changes for admins an editors. Now the users see their edits immediately live. The editors clean things up if needed. Works great. The users learn how to make good edits, that aren’t touched again, and the work for the editors declines over time. :)
¹ Be aware: All text strings are in German, you may have to edit them. I didn’t had the time for I18n, sorry.

Resources