Skip to content

Commit

Permalink
Make roles.creator optional
Browse files Browse the repository at this point in the history
  • Loading branch information
serefyarar committed Feb 12, 2024
1 parent a7c6508 commit 18fa0da
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 14 additions & 5 deletions api/src/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@ export const getIndexById = async (req, res, next) => {
const indexService = new IndexService().setSession(req.session);
const index = await indexService.getIndexById(req.params.id);

if(req.session){
const { roles } = req.query

if(req.session) {

Object.assign(index, {roles: {
owner: index.ownerDID.id === req.session.did.parent,
}});

if( roles ) {
const pkpSession = await getPKPSession(req.session, index);
if(pkpSession){
const roles = getRolesFromSession(pkpSession);
Object.assign(index, {roles});
}else{
Object.assign(index, {roles: {owner: false, creator: false}});
const userRoles = getRolesFromSession(pkpSession);
Object.assign(index, {roles: userRoles});
}
}
} else {
Object.assign(index, {roles: {owner: false, creator: false}});
}

res.status(200).json(index);
Expand Down
4 changes: 3 additions & 1 deletion api/src/packages/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ app.get('/dids/:did/profile', validator.params(Joi.object({
})), didController.getProfileByDID)

// Indexes
app.get('/indexes/:id', validator.params(Joi.object({
app.get('/indexes/:id', validator.query(Joi.object({
roles: Joi.boolean().default(false).optional(),
})), validator.params(Joi.object({
id: Joi.custom(isStreamID, "Index ID").required(),
})), indexController.getIndexById)

Expand Down

0 comments on commit 18fa0da

Please sign in to comment.