<commit_before># Running the discussion service

## Instruction for Mac

## Installing Mongodb

If you haven't done so already:

    brew install mongodb

Make sure that you have mongodb running. You can simply open a new terminal tab and type:

    mongod

## Installing elasticsearch

    brew install elasticsearch

For debugging, it's often more convenient to have elasticsearch running in a terminal tab instead of in background. To do so, simply open a new terminal tab and then type:

    elasticsearch -f

## Setting up the discussion service

First, make sure that you have access to the [github repository](https://github.com/rll/cs_comments_service). If this were not the case, send an email to <EMAIL>.

First go into the mitx_all directory. Then type

    git clone git@github.com:rll/cs_comments_service.git
    cd cs_comments_service/

If you see a prompt asking "Do you wish to trust this .rvmrc file?", type "y"

Now if you see this error "Gemset 'cs_comments_service' does not exist," run the following command to create the gemset and then use the rvm environment manually:

    rvm gemset create 'cs_comments_service'
    rvm use 1.9.3@cs_comments_service

Now use the following command to install required packages:

    bundle install

The following command creates database indexes:

    bundle exec rake db:init

Now use the following command to generate seeds (basically some random comments in Latin):

    bundle exec rake db:seed

It's done! Launch the app now:

    ruby app.rb

## Running the delayed job worker

In the discussion service, notifications are handled asynchronously using a third party gem called delayed_job. If you want to test this functionality, run the following command in a separate tab:

    bundle exec rake jobs:work

## Initialize roles and permissions

To fully test the discussion forum, you might want to act as a moderator or an administrator. Currently, moderators can manage everything in the forum, and administrator can manage everything plus assigning and revoking moderator status of other users.

First make sure that the database is up-to-date:

    rake django-admin[syncdb]
    rake django-admin[migrate]

For convenience, add the following environment variables to the terminal (assuming that you're using configuration set lms.envs.dev):

    export DJANGO_SETTINGS_MODULE=lms.envs.dev
    export PYTHONPATH=.

Now initialzie roles and permissions, providing a course id eg.:

    django-admin.py seed_permissions_roles "MITx/6.002x/2012_Fall"

To assign yourself as a moderator, use the following command (assuming your username is "test", and the course id is "MITx/6.002x/2012_Fall"):

    django-admin.py assign_role test Moderator "MITx/6.002x/2012_Fall"

To assign yourself as an administrator, use the following command

    django-admin.py assign_role test Administrator "MITx/6.002x/2012_Fall"

## Some other useful commands

### generate seeds for a specific forum
The seed generating command above assumes that you have the following discussion tags somewhere in the course data:

    <discussion for="Welcome Video" id="video_1" discussion_category="Video"/>
    <discussion for="Lab 0: Using the Tools" id="lab_1" discussion_category="Lab"/>
    <discussion for="Lab Circuit Sandbox" id="lab_2" discussion_category="Lab"/>

For example, you can insert them into overview section as following:

    <chapter name="Overview">
      <section format="Video" name="Welcome">
        <vertical>
          <video youtube="0.75:izygArpw-Qo,1.0:p2Q6BrNhdh8,1.25:1EeWXzPdhSA,1.50:rABDYkeK0x8"/><commit_msg>Update discussion documentation<commit_after># Running the discussion service

## Instruction for Mac

## Installing Mongodb

If you haven't done so already:

    brew install mongodb

Make sure that you have mongodb running. You can simply open a new terminal tab and type:

    mongod

## Installing elasticsearch

    brew install elasticsearch

For debugging, it's often more convenient to have elasticsearch running in a terminal tab instead of in background. To do so, simply open a new terminal tab and then type:

    elasticsearch -f

## Setting up the discussion service

First, make sure that you have access to the [github repository](https://github.com/rll/cs_comments_service). If this were not the case, send an email to <EMAIL>.

First go into the mitx_all directory. Then type

    git clone git@github.com:rll/cs_comments_service.git
    cd cs_comments_service/

If you see a prompt asking "Do you wish to trust this .rvmrc file?", type "y"

Now if you see this error "Gemset 'cs_comments_service' does not exist," run the following command to create the gemset and then use the rvm environment manually:

    rvm gemset create 'cs_comments_service'
    rvm use 1.9.3@cs_comments_service

Now use the following command to install required packages:

    bundle install

The following command creates database indexes:

    bundle exec rake db:init

Now use the following command to generate seeds (basically some random comments in Latin):

    bundle exec rake db:seed

It's done! Launch the app now:

    ruby app.rb

## Running the delayed job worker

In the discussion service, notifications are handled asynchronously using a third party gem called delayed_job. If you want to test this functionality, run the following command in a separate tab:

    bundle exec rake jobs:work

## From the edx-platform django app, initialize roles and permissions

To fully test the discussion forum, you might want to act as a moderator or an administrator. Currently, moderators can manage everything in the forum, and administrator can manage everything plus assigning and revoking moderator status of other users.

First make sure that the database is up-to-date:

    rake resetdb

If you have created users in the edx-platform django apps when the comment service was not running, you will need to one-way sync the users into the comment service back end database:

    rake django-admin[sync_user_info]

For convenience, add the following environment variables to the terminal (assuming that you're using configuration set lms.envs.dev):

    export DJANGO_SETTINGS_MODULE=lms.envs.dev
    export PYTHONPATH=.

Now initialize roles and permissions, providing a course id. See the example below. Note that you do not need to do this for Studio-created courses, as the Studio application does this for you.

    django-admin.py seed_permissions_roles "MITx/6.002x/2012_Fall"

To assign yourself as a moderator, use the following command (assuming your username is "test", and the course id is "MITx/6.002x/2012_Fall"):

    django-admin.py assign_role test Moderator "MITx/6.002x/2012_Fall"

To assign yourself as an administrator, use the following command

    django-admin.py assign_role test Administrator "MITx/6.002x/2012_Fall"

## Some other useful commands

### generate seeds for a specific forum
The seed generating command above assumes that you have the following discussion tags somewhere in the course data:

    <discussion for="Welcome Video" id="video_1" discussion_category="Video"/>
    <discussion for="Lab 0: Using the Tools" id="lab_1" discussion_category="Lab"/>
    <discussion for="Lab Circuit Sandbox" id="lab_2" discussion_category="Lab"/>

For example, you can insert them into overview section as following:

    <chapter name="Overview">
      <section format="Video" name="Welcome">
        <vertical>
          <video youtube="0.75:izygArpw-Qo,1.0:p2Q6BrNhdh8,1.25:1EeWXzPdhSA,1.50:rABDYkeK0x8"/>
{'fraction_non_alphanumeric': 0.060348265319686296, 'fraction_numerical': 0.014887677788116442, 'mean_word_length': 4.291139240506329, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2593541', 'n_tokens_mistral': 2151, 'n_tokens_neox': 1983, 'n_words': 951}