Discussion Forum: Generalisation of Course & Groups integration logic

Introduction

This document describes the key design problem statement and probable solutions for
Discussion-UI library integration with Sunbird Portal (or any partner application).

Background

  1. No API exists to create the forum, add privileges, create groups.

  2. As of now, We are using the admin panel to do so

Problem Statement

  • How to enable discussion forum from UI?

  • How can we create a forum without using the admin panel?

  • How to create sub-categories for a forum?

  • How to add privileges to the parent category and the sub-categories?

Key design problem:

  • Single API to create forum, categories, groups, privileges & adding users?

Solution:

Workflow Diagram: <diagram>

A form API will be created based on the action we are intending to add the Discussion for:

For courses:

Request:

{ "request": { "type": "global", "subType": "forum", "action": "course" // It will be varied like: "groups" etc. } }

Response:

{ "response": { "primaryCategory": "course", "SbRoles": { "creator": { "type": "course", "identifier": "$courseId" }, "mentor": { "type": "batch", "identifier": "$batchId" } }, "forum": { "category": { "name": "Cateogry name", "pid": "{parent_category_id}", "description": "...", "context": [ { "type": "course", "identifier": "$courseId" } ], "enbaleGroups": "true/false", "groups": [ { "name": "Owner Group", "privileges": [ "groups:topics:reply", "groups:topics:create" ] }, { "name": "enrolled users group", "privileges": [ "groups:topics:reply", "groups:topics:create" ] } ], "privileges": { "copytoChildren": "true/false", "copyFromCategory": "{category_id}" } }, "subcategories": [ { "name": "Annoucements", "pid": "{parent_category_id}", "description": "...", "context": [ { "type": "batch", "identifier": "$batchId" } ], "privileges": { "copyFromCategory": "{category_id}", "groups": [ { "name": "enrolled users group", "privileges": [ "groups:topics:reply" ] } ], "users": [ { "uid": "{nodebb_uid}", "privileges": [ "groups:topics:reply" ] } ] } }, { "name": "General discussions", "pid": "{parent_category_id}", "description": "...", "context": [ { "type": "batch", "identifier": "$batchId" } ] } ] } } }

 

For groups:

Create Form:

Endpoint:

POST: /data/v1/form/create

Request Body:

Fetching the form data:

Request:

Response:

 

 

As it is clear from the response, the form API will be used to perform the below tasks:

  1. To get forum ids mapped to sbIdentifier.

  2. To create a forum for a sbType. ( eg: “course“, “batch“, “group“ )

Fetch the attached category id for a particular sbType:

We will be using the below API to get the category_ids linked to a sbType:

Request:

Response:

Now you can see the payload used to fetch the category ids will be fetched from the above form API itself. We will be using the "SbRoles" attached for a particular type.

It will vary for other types. For example, groups don't have a creator or enrolled users roles that exist. so it will be different from the courses.

Create forum:

Table to explain all the properties/fields of API

Property

Sub-property

Values

Description

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

or

or

 

  • 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)

 

 

  • 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

 

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

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

users

 

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

 

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.

 

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

 

Property

Type

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.

 

Update Group privileges For a category

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

Property

Type

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.

List of privileges

Privilege

Value

Description

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

Add User into group

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

Property

Type

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.

 

 

Form API config for generalization API

Group for course/batch/groups etc:





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

the payload looks like



Form Read



Request Payload





Batch



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





Request payload

Groups

 

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).