Challenge Overview
Messaging service relies on Discourse for providing the functionality for topics / posts. There are a couple of problems that need to be resolved
- Username sync
We create shadow user accounts in Discourse for all members. These accounts are created on-demand, when ..
1. When a user that doesn't exist in Discourse attempts to retrieve posts / topics and
2. Creating a topic if a project member doesn't already exist in discourse.
Discourse is very restrictive when it comes to usernames - special characters not are allowed, length needs to be b/w 2-15 characters and it must end with a letter or number. Topcoder usernames / handles are not as restrictive and this causes problems when creating users in Discourse. Our solution is to use userId instead of usernames when creating users in discourse. you are expected to go through all the code and ensure we are converting from username to userId where necessary. Following are the important pieces, but not limited to these.
1. For the apis, it needs to passing userId instead of username, the same for response. https://github.com/appirio-tech/tc-message-service/blob/dev/swagger.yaml
2. For sso logic (https://github.com/appirio-tech/tc-message-service/blob/dev/app/routes/sso/sso.js), you should switch the logic for using handle and userId. as we are using userId now.
3. Tests should be updated correspondingly.
- Handling @ mentions
Using user id instead of handles in discourse will cause problems with @mentions in posts and will need to be handled appropriately. When creating posts, parse through the post body and convert any @handle to the appropriate userId before creating the topic in discourse. When retrieving posts we will need to convert @userId back to @handle along with the link.
- One time script to update existing data
the script should be run one time to update the existing data.
1) rename the existing columns in message service DB (createdAt -> createdBy_old, updatedBy -> updatedBy_old)
2) create new columns createdBy, updatedBy
3) Lookup handles through an API call to member service
4) update PostgresDb as well as make an API call to Discourse to update the userid there
About Local Setup
Please check the local directory in the attached source code for detail steps to setup locally.
- Verification Steps
- Username sync
We create shadow user accounts in Discourse for all members. These accounts are created on-demand, when ..
1. When a user that doesn't exist in Discourse attempts to retrieve posts / topics and
2. Creating a topic if a project member doesn't already exist in discourse.
Discourse is very restrictive when it comes to usernames - special characters not are allowed, length needs to be b/w 2-15 characters and it must end with a letter or number. Topcoder usernames / handles are not as restrictive and this causes problems when creating users in Discourse. Our solution is to use userId instead of usernames when creating users in discourse. you are expected to go through all the code and ensure we are converting from username to userId where necessary. Following are the important pieces, but not limited to these.
1. For the apis, it needs to passing userId instead of username, the same for response. https://github.com/appirio-tech/tc-message-service/blob/dev/swagger.yaml
2. For sso logic (https://github.com/appirio-tech/tc-message-service/blob/dev/app/routes/sso/sso.js), you should switch the logic for using handle and userId. as we are using userId now.
3. Tests should be updated correspondingly.
- Handling @ mentions
Using user id instead of handles in discourse will cause problems with @mentions in posts and will need to be handled appropriately. When creating posts, parse through the post body and convert any @handle to the appropriate userId before creating the topic in discourse. When retrieving posts we will need to convert @userId back to @handle along with the link.
- One time script to update existing data
the script should be run one time to update the existing data.
1) rename the existing columns in message service DB (createdAt -> createdBy_old, updatedBy -> updatedBy_old)
2) create new columns createdBy, updatedBy
3) Lookup handles through an API call to member service
4) update PostgresDb as well as make an API call to Discourse to update the userid there
About Local Setup
Please check the local directory in the attached source code for detail steps to setup locally.
Final Submission Guidelines
- Code Changes For the fixes- Verification Steps