Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

...

Property

Sub-property

Values

Description

name

{category name}

name of the category.

pid

{parent category id}

under which parent category, this category should get created.

Context

Code Block
{
  "type": "course",
  "identifier": "$courseId"
}

or

Code Block
{
  "type": "batch",
  "identifier": "$batchId”
}
Code Block
{
  "type": "course",
  "identifier": "do_37819”
}

or

Code Block
{
  "type": "batch",
  "identifier": "0312047"
}

  • type: this is the sbType

  • identifier: this is the sbIdentifier

  • if you want to add different types we have to change the value of types
    ex: “Course”, “Batch”, “Group”, “GroupMember”

enbaleGroups
(to de discussed)

true / false

If set true then, It will be used to create groups to add privileges to a certain set of user (according to our requirement)

groups (optional)

Code Block
{
  "name": "<group name>",
  "privileges": [
    < set of privileges >
  ]
}

Code Block
{
  "name": "category owner",
  "privileges": [
    "groups:topics:reply",
    "groups:topics:create"
  ]
}

  • If this object is exist then create the group else don't create

  • It will be used to define certain set of privileges so that it can be used for the categories.

  • If copyFromCategory is defined, then this is optional. Because all the groups added for copyFromCategory will be adding to this category

privileges

  • To set some rules for the users, if we dont want to create the groups. That

copytoChildren

true/false

  • This is used to copy the groups to all sub-categories

  • The same group will be added to sub-categories with the privileges.

copyFromCategory

{category_id}

  • When we mention this property, groups object will become optional.

  • It will copy all the groups & privileges from the specified category & add it to the new category(with the same group name & privileges)

copytoChildren

true / false

If set, it will take the rules

from the given category.

copyFromCategory

category_id, from where it should take the privileges. groups are optional when category_id mention here. It will copy the group & privileges from category_id

subcategories

categories which is gonna be created under the parent category

name

Example: “Announcement“, “General discussion“

name of the subcategory

pid

parent category id under which the sub-category will be created

description

description of the sub-category

context

Code Block
{
    "type": "batch",
    "identifier": "$batchId"
}
Code Block
{
    "type": "batch",
    "identifier": "0123456"
}

this is to communicate with the mapping table.

privileges

This is to override the privileges given at category level for group or user

copyFromCategory

category_id, from where it should take the privileges.

groups

Code Block
{
  "groups": [
    {
      "name": "<group_name>",
      "privileges": [
        <privileges for the group>
      ]
    }
  ]
}
Code Block
{
  "groups": [
    {
      "name": "enrolled users group",
      "privileges": [
        "groups:topics:reply"
      ]
    }
  ]
}

It will be used to define certain set of privileges so that it can be used for the categories. this is optional.

users

Code Block
"users": [
    {
      "uid": "{nodebb_uid}",
      "privileges": [
        <previleges for given set of users>
      ]
    }
  ]
Code Block
"users": [
    {
      "uid": "test_df_1994",
      "privileges": [
       "groups:topics:reply"
      ]
    }
  ]

the set of users, the privilges gonaa be set for.

Generalization api for Update(If there is any mistakes)

Mandatory Parameters

...

2. Admin UID (adminUid)

Update Category Details

...

Postman collection

https://www.getpostman.com/collections/d0ee01a742409791dcc5

Geeralization of api

This api is for creating a context with mappig category and enablig groups ad adding users into groups.

Code Block
curl --location --request PUTPOST 'https://stagingdev.sunbirded.org/discussionsdiscussion/apiforum/v2/categories/{cid}?_uid={adminUid}v3/create' \
--header 'AuthorizationConnection: Bearer {masterToken}keep-alive' \
--header 'Access-Control-Allow-Origin: *' \
--header 'Content-TypeAccept: application/json' \
--header 'CookieX-App-Id: express.sid=s%3AqiNDVx5w84QRoUGABEkEdq1cqO7bXP_y.MMB8cjhTP19d9Zv%2B%2FxiBtqctd0M%2FY7eQk9Q0tQSLqqcdev.sunbird.portal' \
--data-raw '{
    "parentCid": 61
}'

...

Property

...

Type

...

cid

...

path parameter

...

adminUid

...

query parameter

...

Authorization

...

header

Required Parameters

Path Parameters: you need to pass cid (which category id you have to move forum one category to another category).

Query Parameters: You have to pass admin uid for this api (It is mandatory).

Headers: You need to pass nodebb master token as a authorization token (it is mandatory).

Body: In body all are optional parameters, If you pass any value for a particular field, it will update that field. if you are not passing any parameters it won’t update any thing.

Code Block
{
name: "New name", // optional
description: "New description", // optional
bgColor: "New bgColor", // optional
color: "New color", // optional
parentCid: "New parentCId", // optional
backgroundImage: "New backgroundImage" // optional
}

Update Group privileges For a category

If you want to update privileges for a particular group for a category follow this curl

Code Block
curl --location --request PUT 'https://staging.sunbirded.org/discussions/api/v2/categories/{cid}/privileges?_uid={adminUid}header 'User-Agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36' \
--header 'X-Device-Id: 6d20ec529bbe2081fbbd2ab80398e81c' \
--header 'X-Channel-Id: b00bc992ef25f1a9a8d63291e20efc8d' \
--header 'Content-Type: application/json' \
--header 'Origin: https://dev.sunbirded.org' \
--header 'Sec-Fetch-Site: same-origin' \
--header 'Sec-Fetch-Mode: cors' \
--header 'Sec-Fetch-Dest: empty' \
--header 'Referer: https://dev.sunbirded.org/my-groups/group-details/5bb0f6d6-58b8-4e90-8fa9-77c38901d8b4' \
--header 'ContentAccept-TypeLanguage: application/jsonen-US,en;q=0.9' \
--header 'AuthorizationCookie: Bearer {masterToken}' \
--header 'Cookie: express.sid=s%3AY3Utp3Ffto0AkXex1QAmAK5HWn60mVz6.8ev45%2FlFxF6Piaje2GZh%2BJaRpIjWXETd5Mah8w5bx3M_csrf=5E5KVAVALy__G4RVgzUGt7Za; connect.sid=s%3AztbChUZUWd1Ch8XpFtKm-8WMpqI8ojIq.kI9DLqKrBoTRyj%2FVknHYEgl8BEbaRnuqvyRIwtUL63U' \
--data-raw '{
    "privilegescategory": ["groups:topics:reply", "groups:topics:create"],{
        "name": "Test Generalization API - 2",
        "pid": "34",
        "groupsuid": ["guests1",
 "Category Owner"]
}'

...

Property

...

Type

...

cid

...

path parameter

...

adminUid

...

query parameter

...

Authorization

...

header

Required Parameters

Path Parameters: you need to pass cid (which category id you have to enable privileges).

Query Parameters: You have to pass admin uid for this api (It is mandatory).

Headers: You need to pass nodebb master token as a authorization token (it is mandatory).

Body:

  1. Privileges : what are the privileges you wnat to enable.

  2. Groups: To which group you have to add those privileges.

Code Block
{
    "privileges": ["groups:topics:reply", "groups:topics:create"],       "description": "",
        "context": [
           {
            "type": "course",
            "groupsidentifier": ["guests", "Category Owner"]
}

List of privileges

...

Privilege

...

Value

...

groups:find

...

true/false

...

groups:read

...

true/false

...

groups:topics:read

...

true/false

...

groups:topics:create

...

true/false

...

groups:topics:reply

...

true/false

...

groups:topics:tag

...

true/false

...

groups:posts:edit

...

true/false

...

groups:posts:history

...

true/false

...

groups:posts:delete

...

true/false

...

groups:posts:upvote

...

true/false

...

groups:posts:downvote

...

true/false

...

groups:topics:delete

...

true/false

...

groups:posts:view_deleted

...

true/false

...

groups:purge

...

true/false

...

groups:moderate

...

true/false

Get groups List

To get list of groups, follow the below CURL

Code Block
curl --location --request GET 'https://staging.sunbirded.org/discussions/api/groups' \
--header 'Cookie: express.sid=s%3AqiNDVx5w84QRoUGABEkEdq1cqO7bXP_y.MMB8cjhTP19d9Zv%2B%2FxiBtqctd0M%2FY7eQk9Q0tQSLqqc'

Add User into group

We can add user into a particular group manually, Followthis CURL

Code Block
curl --location --request PUT 'https://staging.sunbirded.org/discussions/api/v2/groups/{groupSlug}/membership/{uid}?_uid={adminUid}' \
--header 'Authorization: Bearer {masterToken}' \
--header 'Cookie: express.sid=s%3AqiNDVx5w84QRoUGABEkEdq1cqO7bXP_y.MMB8cjhTP19d9Zv%2B%2FxiBtqctd0M%2FY7eQk9Q0tQSLqqc'

...

Property

...

Type

...

groupslug

...

path parameter

...

uid

...

path parameter

...

adminUid

...

query parameter

...

Authorization

...

header

Required Parameters

Path Parameters: you need to pass group slug (which group we want to addthe user) and nodebb UID (Which user you wnatto add).

Query Parameters: You have to pass admin uid for this api (It is mandatory).

Headers: You need to pass nodebb master token as a authorization token (it is mandatory).

Body: NO

Getting Nodebb UID's By sending Sunbird Identifiers

As we don’t know nodebb uids and we have only sunbird identifiers.so the below api will give you nodebb uids by sending sunbird identifiers.

Code Block
curl --location --request POST 'http://localhost:4567/api/forum/v2/uids' \
--header 'Authorization: Bearer 550998a7-4036-4482-b152-03ff5dedcde0' \
--header 'Content-Type: application/json' \
--header 'Cookie: express.sid=s%3AafcKVNRDU5uKTnTDVIWvs1zZbtdfRYj9.2gZpGnKf6S8PhOk0GsDauciGdZ%2F%2BxPqNPTSy6wQ6WZU' \
--data-raw '{
    "request": {KP_FT_1602790320113"
          }
        ],
        "enbaleGroups": "true",
                "groups": [
          {
            "name": "Owner Group",
            "privileges": [
              "groups:topics:reply",
              "groups:topics:create"
            ],
              "sbUids" : ["8454cb21-3ce9-4e30-85b5-fade097880d8", "fca2925f-1eee-4654-9177-fece3fd6afc9"]
          },
          {
            "name": "enrolled users group",
            "privileges": [
              "groups:topics:reply"
            ],
              "sbIdentifierssbUids" : ["fca2925f8454cb21-1eee3ce9-46544e30-917785b5-fece3fd6afc9fade097880d8", "8454cb21fca2925f-3ce91eee-4e304654-85b59177-fade097880d8fece3fd6afc9"]
          }
        ],
         "privileges": {
          "copytoChildren": "false",
          "copyFromCategory": ""
        }
    }
}'

Generalization api for Update(If there is any mistakes)

Mandatory Parameters


1. Master Token(masterToken)

2. Admin UID (adminUid)

Update Category Details

If you want to update parent category for a particular child category. Follow this API curl

Code Block
curl --location --request PUT 'https://staging.sunbirded.org/discussions/api/v2/categories/{cid}?_uid={adminUid}' \
--header 'Authorization: Bearer {masterToken}' \
--header 'Content-Type: application/json' \
--header 'Cookie: express.sid=s%3AqiNDVx5w84QRoUGABEkEdq1cqO7bXP_y.MMB8cjhTP19d9Zv%2B%2FxiBtqctd0M%2FY7eQk9Q0tQSLqqc' \
--data-raw '{
    "parentCid": 61
}'

Property

Type

cid

path parameter

adminUid

query parameter

Authorization

header

Required Parameters

Path Parameters: you need to pass cid (which category id you have to move forum one category to another category).

Query Parameters: You have to pass admin uid for this api (It is mandatory).

Headers: You need to pass nodebb master token as a authorization token (it is mandatory).

Body: In body all are optional parameters, If you pass any value for a particular field, it will update that field. if you are not passing any parameters it won’t update any thing.

Code Block
{
name: "New name", // optional
description: "New description", // optional
bgColor: "New bgColor", // optional
color: "New color", // optional
parentCid: "New parentCId", // optional
backgroundImage: "New backgroundImage" // optional
}

Update Group privileges For a category

If you want to update privileges for a particular group for a category follow this curl

Code Block
curl --location --request PUT 'https://staging.sunbirded.org/discussions/api/v2/categories/{cid}/privileges?_uid={adminUid}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {masterToken}' \
--header 'Cookie: express.sid=s%3AY3Utp3Ffto0AkXex1QAmAK5HWn60mVz6.8ev45%2FlFxF6Piaje2GZh%2BJaRpIjWXETd5Mah8w5bx3M' \
--data-raw '{
    "privileges": ["groups:topics:reply", "groups:topics:create"],
    "groups": ["guests", "Category Owner"]
}'

Property

Type

cid

path parameter

adminUid

query parameter

Authorization

header

Required Parameters

Path Parameters: you need to pass cid (which category id you have to enable privileges).

Query Parameters: You have to pass admin uid for this api (It is mandatory).

Headers: You need to pass nodebb master token as a authorization token (it is mandatory).

Body:

  1. Privileges : what are the privileges you wnat to enable.

  2. Groups: To which group you have to add those privileges.

Code Block
{
    "privileges": ["groups:topics:reply", "groups:topics:create"],
    "groups": ["guests", "Category Owner"]
}

List of privileges

Privilege

Value

Description

groups:find

true/false

Allow the user get fetch category using api

groups:read

true/false

Allow the user to access category from UI

groups:topics:read

true/false

Access Topics

groups:topics:create

true/false

Create Topics

groups:topics:reply

true/false

Reply to Topics

groups:topics:tag

true/false

Can access Tag Topics

groups:posts:edit

true/false

User can edit the post

groups:posts:history

true/false

User can able to see edit history

groups:posts:delete

true/false

user can able to delete post

groups:posts:upvote

true/false

user can upvote to a post

groups:posts:downvote

true/false

user can down vote to a post

groups:topics:delete

true/false

user can delete the topic

groups:posts:view_deleted

true/false

user can see the deleted posts

groups:purge

true/false

user can able to remove

groups:moderate

true/false

user can be a moderator

Get groups List

To get list of groups, follow the below CURL

Code Block
curl --location --request GET 'https://staging.sunbirded.org/discussions/api/groups' \
--header 'Cookie: express.sid=s%3AqiNDVx5w84QRoUGABEkEdq1cqO7bXP_y.MMB8cjhTP19d9Zv%2B%2FxiBtqctd0M%2FY7eQk9Q0tQSLqqc'

Add User into group

We can add user into a particular group manually, Followthis CURL

Code Block
curl --location --request PUT 'https://staging.sunbirded.org/discussions/api/v2/groups/{groupSlug}/membership/{uid}?_uid={adminUid}' \
--header 'Authorization: Bearer {masterToken}' \
--header 'Cookie: express.sid=s%3AqiNDVx5w84QRoUGABEkEdq1cqO7bXP_y.MMB8cjhTP19d9Zv%2B%2FxiBtqctd0M%2FY7eQk9Q0tQSLqqc'

Property

Type

groupslug

path parameter

uid

path parameter

adminUid

query parameter

Authorization

header

Required Parameters

Path Parameters: you need to pass group slug (which group we want to addthe user) and nodebb UID (Which user you wnatto add).

Query Parameters: You have to pass admin uid for this api (It is mandatory).

Headers: You need to pass nodebb master token as a authorization token (it is mandatory).

Body: NO

Getting Nodebb UID's By sending Sunbird Identifiers

As we don’t know nodebb uids and we have only sunbird identifiers.so the below api will give you nodebb uids by sending sunbird identifiers.

Code Block
curl --location --request POST 'http://localhost:4567/api/forum/v2/uids' \
--header 'Authorization: Bearer 550998a7-4036-4482-b152-03ff5dedcde0' \
--header 'Content-Type: application/json' \
--header 'Cookie: express.sid=s%3AafcKVNRDU5uKTnTDVIWvs1zZbtdfRYj9.2gZpGnKf6S8PhOk0GsDauciGdZ%2F%2BxPqNPTSy6wQ6WZU' \
--data-raw '{
    "request": {
        "sbIdentifiers": ["fca2925f-1eee-4654-9177-fece3fd6afc9","8454cb21-3ce9-4e30-85b5-fade097880d8"]
    }
}'

Image Added

Form API config for generalization API

Group for course/batch/groups etc:


Code Block
groups: [
    {
        "name": "Group_name", // Group for all creators
        "sbIds": [$userIdentifier],
        "privileges": [group:topic:create, group:topic:reply]
    }
]


We are calling this api when the new course created from UI (can be sunbird/IGOT).

the payload looks like


Form Read

Code Block
{
    "id": "api.form.read",
    "params": {
        "resmsgid": "cbdc71cb-8c0f-4714-b164-1ee2c4f98125",
        "msgid": "74b0c5df-720d-4777-8d12-123d0c094ce1",
        "status": "successful"
    },
    "responseCode": "OK",
    "result": {
        "form": {
            "type": "global",
            "subtype": "forum",
            "action": "creation",
            "component": "*",
            "framework": "*",
            "data": {
                "templateName": "defaultTemplate",
                "action": "creation",
                "fields": [
                    {
                        "index": 0,
                        "type": "Course",
                        "title": "Course",
                        "primaryCategoryId": "2 ",
                        "groups": [
                            {
                                "name": "Course_Owner",
                                "permissions": [
                                    "read",
                                    "vote",
                                    "post",
                                    "moderate",
                                    "topic"
                                ],
                                "SbIds": ["$Sunbird_identifier"] // can be changed
                            }
                        ],
                        "subCategoris": [
]
                    }
                ]
            },
            "created_on": "2021-02-04T09:27:01.635Z",
            "last_modified_on": "2021-02-04T10:08:29.445Z",
            "rootOrgId": "*"
        }
    },
    "ts": "2021-03-16T15:20:46.990Z",
    "ver": "1.0"
}


Request Payload

Code Block
{
    "category": {
        "name": "Course Name",
        "pid": "120", // categoryId which holds all course categories
        "description": "Creators can start discussions", // can be change
        "context": [
            {
                "type": "course",
                "identifier": "course_013178064710950002"
            }
        ],
       "groups": [
            {
                "name": "Creator_Group", // group name
                "privileges": [          // what are the privileges that creator role has
                    "groups:topics:reply",
                    "groups:topics:create"
                ],
                "sbUids": [ // subbird identifiers
                    "8454cb21-3ce9-4e30-85b5-fade097880d8"
                ]
            }
       ]
    }
}



Batch

Code Block
groups: [
    {
      "name": "Group_name", // Group for all mentor
        "sbIds": [$userIdentifier],
        "privileges": [group:topic:create, group:topic:reply]
    }
]


We are calling this api when the new batch created from UI (can be sunbird/IGOT).

Note: sbIds batch mentors id's and this id's added into mentors groups

the payload looks like


Code Block
{
    "id": "api.form.read",
    "params": {
        "resmsgid": "cbdc71cb-8c0f-4714-b164-1ee2c4f98125",
        "msgid": "74b0c5df-720d-4777-8d12-123d0c094ce1",
        "status": "successful"
    },
    "responseCode": "OK",
    "result": {
        "form": {
            "type": "global",
            "subtype": "forum",
            "action": "creation",
            "component": "*",
            "framework": "*",
            "data": {
                "templateName": "defaultTemplate",
                "action": "creation",
                "fields": [
                    {
                        "index": 0,
                        "type": "Course",
                        "title": "Course",
                        "primaryCategoryId": "2 ",
                        "groups": [
                            {
                                "name": "Course_Owner",
                                "permissions": [
                                    "read",
                                    "vote",
                                    "post",
                                    "moderate",
                                    "topic"
                                ],
                                "SbIds": ["$Sunbird_identifier"] // can be changed
                            }
                        ],
                        "subCategories": [
                            {
                                "name": "Announcements",
                                "groups": [
                                    {
                                        "name": "Group_name",
                                        "sbIds": ["$userIdentifier"],
                                        "privileges": ["group:topic:create", "group:topic:reply"]
                                    }
                                ],
                                "privileges": {
                                    "copyFromParent": "true/false"
                                }
                            },
                            {
                                "name": "General Discussions",
                                "groups": [
                                    {
                                        "name": "Group_name",
                                        "sbIds": ["$userIdentifier"],
                                        "privileges": ["group:topic:create", "group:topic:reply"]
                                    }
                                ],
                                "privileges": {
                                    "copyFromParent": "true/false"
                                }
                            }
                        ]
                    }
                ]
            },
            "created_on": "2021-02-04T09:27:01.635Z",
            "last_modified_on": "2021-02-04T10:08:29.445Z",
            "rootOrgId": "*"
        }
    },
    "ts": "2021-03-16T15:20:46.990Z",
    "ver": "1.0"
}


Request payload

Code Block
{
    "category": {
        "name": "Batch Name",
        "pid": "120", // categoryId which holds all course categories
        "description": "Creators can start discussions", // can be change
        "context": [
            {
                "type": "batch",
                "identifier": "batch_013178064710950002"
            }
        ],
        "groups": [
                {
                    "name": "Creator_Group", // group name
                    "privileges": [          // what are the privileges that creator role has
                        "groups:topics:reply",
                        "groups:topics:create"
                    ],
                    "sbUids": [ // subbird identifiers
                        "8454cb21-3ce9-4e30-85b5-fade097880d8"
                    ]
                }
            ],
           "subCategories": [
                {
                    "name": "Announcements",
                    "groups": [
                        {
                            "name": "Group_name",
                            "sbIds": ["$userIdentifier"],
                            "privileges": ["group:topic:create", "group:topic:reply"]
                        }
                    ],
                    "privileges": {
                        "copyFromParent": "true/false"
                    }
                },
                {
                    "name": "General Discussions",
                    "groups": [
                        {
                            "name": "Group_name",
                            "sbIds": ["$userIdentifier"],
                            "privileges": ["group:topic:create", "group:topic:reply"]
                        }
                    ],
                    "privileges": {
                        "copyFromParent": "true/false"
                    }
                }
            ]
    }
}

Groups

Code Block
{
    "category": {
        "name": "Group Name",
        "pid": "120", // categoryId which holds all course categories
        "description": "Creators can start discussions", // can be change
        "context": [
            {
                "type": "group",
                "identifier": "group_013178064710950002"
            }
        ]
    }
}

Comments

MOM: Generalization of API

participents:

Rayulu Villa Vinu Kumar Venkatanarayana Kadiveti Sudip Mukherjee

  1. If a user passes both privileges object which contain copyFromCategory and groups object, it should throw error

req payload should contain either privileges or groups not both.

  1. Giving privileges to users directly instead of creating groups, adding privileges and adding him into groups.

  2. subcategories should have copyFromParent.

  3. Unenrolled users should have read access.

  4. We should think of a new way instead of depending on form api configuration(creating new component and there should handle all context configuration).