Skip to content

Commit

Permalink
Merge pull request #890 from ignacionar/#554
Browse files Browse the repository at this point in the history
#554 Set correct owner .env values, new STF API owner endpoint
  • Loading branch information
dhreben authored Feb 21, 2024
2 parents e98364c + 0121a30 commit 96148db
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/db/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,16 @@ dbapi.getInstalledApplications = function(message) {
return db.run(r.table('devices').get(message.serial))
}

dbapi.setDeviceGroupOwner = function(message) {
return db.run(r.table('devices').get(message.serial).update({
group: {
owner: {
email: process.env.STF_ADMIN_EMAIL,
name: process.env.STF_ADMIN_NAME
}
}}))
}

dbapi.initializeIosDeviceState = function(publicIp, message) {
const screenWsUrlPattern =
message.provider.screenWsUrlPattern || `ws://${publicIp}:${message.ports.screenPort}/`
Expand Down Expand Up @@ -1678,6 +1688,8 @@ dbapi.initializeIosDeviceState = function(publicIp, message) {
})
}

dbapi.setDeviceGroupOwner(message)

return stats
})
}
Expand Down
21 changes: 21 additions & 0 deletions lib/units/api/controllers/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,26 @@ function getDeviceGroups(req, res) {
})
}

function getDeviceOwner (req, res) {
var serial = req.swagger.params.serial.value
dbapi.getDeviceGroupOwner(serial)
.then(response => {
if (!response) {
return res.status(404).json({
success: false,
description: 'Device not found'
})
}
return res.status(200).json(response)
})
.catch(function(err) {
log.info('Failed to get device owner: ', err.stack)
res.status(500).json({
success: false
})
})
}

function getDeviceBookings(req, res) {
const serial = req.swagger.params.serial.value
const fields = req.swagger.params.fields.value
Expand Down Expand Up @@ -576,6 +596,7 @@ module.exports = {
, putDeviceBySerial: putDeviceBySerial
, getDeviceBySerial: getDeviceBySerial
, getDeviceSize: getDeviceSize
, getDeviceOwner: getDeviceOwner
, getDeviceGroups: getDeviceGroups
, getDeviceBookings: getDeviceBookings
, addOriginGroupDevice: addOriginGroupDevice
Expand Down
35 changes: 35 additions & 0 deletions lib/units/api/swagger/api_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2031,6 +2031,32 @@ paths:
$ref: "#/definitions/UnexpectedErrorResponse"
security:
- accessTokenAuth: []
/devices/{serial}/owner:
x-swagger-router-controller: devices
get:
summary: Gets the group owner of a device
description: Gets the group owner of a device
operationId: getDeviceOwner
tags:
- user
parameters:
- name: serial
in: path
description: Device identifier (serial)
required: true
type: string
responses:
"200":
description: Device size information
schema:
$ref: "#/definitions/OwnerResponse"
default:
description: >
Unexpected Error:
* 404: Not Found => unknown device
* 500: Internal Server Error
schema:
$ref: "#/definitions/ErrorResponse"
/devices/{serial}/groups:
x-swagger-router-controller: devices
get:
Expand Down Expand Up @@ -2366,6 +2392,15 @@ definitions:
type: integer
width:
type: integer
OwnerResponse:
required:
- email
- name
properties:
email:
type: string
name:
type: string
DeviceResponse:
required:
- success
Expand Down

0 comments on commit 96148db

Please sign in to comment.