Structure of a Comment System - sql

I want to manage a n-label comment system and design a data base structure like this.
I am trying to design a database which supports comment moderation for unregistered users. The functionality I require is such that when a comment is posted
If the user is registered it appears directly. otherwise;
The post must be checked by a moderator before it appears.
Please suggest the possible changes to my database schema above to support this functionality.

It appears that you have more-or-less what you require in order to do what you want. The process when a user creates a new comment is as follows
if the user is registered, and not blocked
create BlogComment record with:
IsApproved=true
IsBlocked=false
UserId=registered userId
UserName = null
if the user is registered and blocked
create BlogComment record with
IsApproved=false
IsBlocked=true
UserId=registered userId
UserName = null
if the user is unregistered
create BlogComment record with
IsApproved=false
IsBlocked=false
UserId=null
UserName=user's name
When you pull out comments to show below a post you want a query like
SELECT Comment, ISNULL(bc.UserName, ru.UserName) AS UserName
FROM BlogComment bc
LEFT JOIN RegisteredUser ru
ON bc.UserId = ru.Id
WHERE postId=<current PostId>
AND IsApproved=1
This will pull out all approved comments (those from registered users, or from unregistered users which have been moderated), along with their username (for registered users this will be their username from the RegisteredUser table, for unregistered it will be what is saved alongside their comment in the BlogComment table)
Lastly, when you want to pull out a list of posts for the moderator to moderate
SELECT *
FROM BlogComment
WHERE IsApproved=0
AND IsBlocked=0
You can then update the records they accept to IsApproved=1.

Related

Wordpress SQL request to delete all user subscriber without publication

I have 3000 users and 2800 user without publication, so i want to delete all spam user with sql. thanks
Your question isn't very clear -
But if you mean "delete all users who have never posted anything" - Then
DELETE FROM `wp_users`
WHERE ID NOT IN
(SELECT DISTINCT post_author FROM `wp_posts`);
would do it... remember to back up your data first.
This will run through all the posts, make a list of the user IDs that ARE authors and then delete anyone who isn’t on the list from your wordpress users. Since custom post types are stored in wp_posts, it’ll be checking the author against all of those too.

JIRA Api for 'Find users with browse permission ' not working

I am trying to get a list of users who have access to a particular issue.
I tried using GET /rest/api/2/user/viewissue/search for this . But it asks for username and issueKey query parameters. Also it is returning only one user.
How does this api work?
I refered to the documentation here: https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-user-viewissue-search-get
EDIT to the below: If you query with username=% (i.e. a wildcard) then it returns
every user with permission
As the documentation you've linked to states, you do need to provide an issueKey and a username or it won't return any results:
username
string
the username filter, no users returned if left blank
This is saying, find all the users who have permission to see the specified issue, where their username matches this specific filter value I'm providing, i.e. not all users that have permission.
It's filtering on some combination of username, display name and email (I think).
I have a JIRA Cloud site with three users:
admin, which has a display name of Mike Jones and an email of mike.jones#...
mike, which has a display name of Mike Jones and an email of mike.jones#...
mike.jones, which has a display name of Mike Smith and an email of mike.jones#...
If I run this query, I see all three users returned:
https://<url>/rest/api/2/user/viewissue/search?issueKey=DD-1&username=mike
If I change the last query parameter to be username=smith then I see just the third user with a display name of Mike Smith, which suggests it's querying the Display Name field:
https://<url>/rest/api/2/user/viewissue/search?issueKey=DD-1&username=smith
But if I use the parameter username=jones, then I see all three users, which suggests it's querying the Email field:
https://<url>/rest/api/2/user/viewissue/search?issueKey=DD-1&username=jones
And if I use the parameter username=admin, then I only see the admin user, which suggests it's querying on the Username field:
https://<url>/rest/api/2/user/viewissue/search?issueKey=DD-1&username=admin

Ldap User - Group Sync

I'm using Sun Directory server v5.2.
I have three attributes: designation, role.
I am using a tool using which when i create a create/modify user entry with designation filled, a unique member is added to a group 'Members'.
Now, there are circumstances where
Scenario1:
* Creating/ Modifying user entry is not done via the tool and so unique member for this user entry is not added to the group 'Members'.
Scenario2:
* When user the designation attribute is deleted, group entry is not deleted.
This is causing inconsistency in the users and the group.
How can i resolve this?
Thanks,
Sash.

MySQL joins for friend feed

I'm currently logging all actions of users and want to display their actions for the people following them to see - kind of like Facebook does it for friends.
I'm logging all these actions in a table with the following structure:
id - PK
userid - id of the user whose action gets logged
actiondate - when the action happened
actiontypeid - id of the type of action (actiontypes stored in a different table - i.e. following other users, writing on people's profiles, creating new content, commenting on existing content, etc.)
objectid - id of the object they just created (i.e. comment id)
onobjectid - id of the object they did the action to (i.e. id of the content that they commented on)
Now the problem is there are several types of actions that get logged (actiontypeid).
What would be the best way of retrieving the data to display to the user?
The easiest way out would be gabbing the people the user follows dataset and then just go from there and grab all other info from the other tables (i.e. the names of the users the people you're following just started following, names of the user profiles they wrote on, etc.). This however would create a a huge amount of small queries and trips to the database in a while loop. Not a good idea.
I could use joins to retrieve everything in one massive data set, but how would I know where to grab the data from in just one query? - there's different types of actions that require me to look into several different tables to retrieve data, based on the actiontypeid...
i.e. To get User X is now following User Y I'd have to get my data (User Y's username) from the followers table, whereas User X commented on content Y would need me to look in the content table to get the content's title and URL.
Any tips are welcome, thanks!
Consider creating several views for different actiontypeids. Union them to have one full history.

How should I handle entries when the user is deleted?

I run a forum which I built myself. Ok so all users have the opportunity to delete themselves.
But all their threads and posts will remain. But right now where it should say their username it's just blank.
How should I handle this?
Should I make a new user and call it e.g. "deleted user" and assign all threads/posts to that ID when they delete themselves?
Or should I just check if the user ID exist if not print e.g. "deleted user" as username?
What's the smartest way? Any other ways tell me.
Thanks!
p.s (i'm not a native english speaker, looked up some fancy words on a online dictionary)
I would suggest not actually deleting the user. You could simply add a column to the users table such as:
ALTER TABLE users ADD COLUMN (is_active TINYINT(1) NOT NULL DEFAULT 1);
Then when you "delete" a user, simply mark them as inactive:
UPDATE users SET is_active = 0 WHERE users.id = 7;
For user listings, and account access you would check the is_active status. For displaying of data such as posts and what not, you'd not care about their active status, youd just grab the name from the table.