Skip to content

Commit

Permalink
[mirotalkwebrtc] - add user rooms allwed endpoint, update dep
Browse files Browse the repository at this point in the history
  • Loading branch information
miroslavpejic85 committed Oct 18, 2024
1 parent cf3e238 commit 0e4c215
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 7 deletions.
47 changes: 45 additions & 2 deletions backend/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ paths:
description: Check if room allowed
operationId: isRoomAllowed
requestBody:
description: Check if user authenticate
description: Check if room allowed
content:
application/json:
schema:
Expand All @@ -109,7 +109,31 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/IsRoomAllowedRes'
$ref: '#/components/schemas/UserIsRoomAllowedRes'
'400':
description: Bad request

/user/roomsAllowed:
post:
tags:
- user
summary: Check the allowed rooms for user
description: Check the rooms allowed for user
operationId: roomsAllowed
requestBody:
description: Check rooms allowed
content:
application/json:
schema:
$ref: '#/components/schemas/UserRoomsAllowedReq'
required: true
responses:
'201':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/UserRoomsAllowedRes'
'400':
description: Bad request

Expand Down Expand Up @@ -440,6 +464,19 @@ components:
type: string
example: 'mirotalkweb_default_secret'

UserRoomsAllowedReq:
type: object
properties:
email:
type: string
example: '[email protected]'
username:
type: string
example: 'Miroslav Pejic'
api_secret_key:
type: string
example: 'mirotalkweb_default_secret'

UserRes:
type: object
properties:
Expand Down Expand Up @@ -491,6 +528,12 @@ components:
type: boolean
enum: [true, false]
example: true
UserRoomsAllowedRes:
type: object
properties:
message:
type: array
example: ['Room1', 'Room2']
RoomReq:
type: object
properties:
Expand Down
28 changes: 28 additions & 0 deletions backend/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,33 @@ async function userIsRoomAllowed(req, res) {
}
}

async function userRoomsAllowed(req, res) {
try {
log.debug('userRoomsAllowed query', req.body);

const { email, username } = req.body;

// Check by email (uuid) or username as indexed
const userFindOne = await User.findOne({
$or: [{ email: email }, { username: username ? username : email }],
});

if (Object.is(userFindOne, null) || !userFindOne.active) {
log.debug('user not found!', email);
return res.status(201).json({ message: false });
}

const roomsAllowedForUser = userFindOne.allowedRooms;

log.debug('userRoomsAllowed', roomsAllowedForUser);

res.status(201).json({ message: roomsAllowedForUser })
} catch (error) {
log.error('userRoomsAllowed', error);
res.status(400).json({ message: error.message });
}
}

async function userConfirmation(req, res) {
try {
log.debug('userConfirmation query', req.query);
Expand Down Expand Up @@ -355,6 +382,7 @@ module.exports = {
userCreate,
userLogin,
userIsAuth,
userRoomsAllowed,
userIsRoomAllowed,
userConfirmation,
userGet,
Expand Down
5 changes: 5 additions & 0 deletions backend/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ router.post('/user/isRoomAllowed', api, (req, res) => {
controllersUsers.userIsRoomAllowed(req, res);
});

//POST: /api/v1/user/allowedRooms/
router.post('/user/roomsAllowed', api, (req, res) => {
controllersUsers.userRoomsAllowed(req, res);
});

//GET: /api/v1/user/confirmation/?token=<token>
router.get('/user/confirmation', auth, (req, res) => {
controllersUsers.userConfirmation(req, res);
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mirotalkwebrtc",
"version": "1.1.10",
"version": "1.1.11",
"description": "MiroTalk WebRTC admin",
"main": "server.js",
"scripts": {
Expand Down Expand Up @@ -33,22 +33,22 @@
"license": "AGPL-3.0",
"homepage": "https://github.com/miroslavpejic85/mirotalkwebrtc",
"dependencies": {
"@sentry/node": "^8.33.1",
"@sentry/node": "^8.34.0",
"axios": "^1.7.7",
"bcryptjs": "^2.4.3",
"colors": "1.4.0",
"compression": "^1.7.4",
"cors": "^2.8.5",
"crypto-js": "^4.2.0",
"dotenv": "^16.4.5",
"express": "^4.21.0",
"express": "^4.21.1",
"jsonwebtoken": "^9.0.2",
"js-yaml": "^4.1.0",
"mongoose": "^8.7.0",
"mongoose": "^8.7.2",
"ngrok": "^5.0.0-beta.2",
"nodemailer": "^6.9.15",
"swagger-ui-express": "^5.0.1",
"twilio": "^5.3.3"
"twilio": "^5.3.4"
},
"devDependencies": {
"nodemon": "^3.1.7",
Expand Down

0 comments on commit 0e4c215

Please sign in to comment.