Finish server-side translations in controllers
This commit is contained in:
@@ -25,12 +25,12 @@ class AppController extends Controller {
|
||||
|
||||
if ( !application || !application.active )
|
||||
return res.status(404)
|
||||
.message(req.T('api:application_not_found'))
|
||||
.message(req.T('api.application_not_found'))
|
||||
.api()
|
||||
|
||||
if ( !req.user.can(`app:${application.id}:view`) )
|
||||
return res.status(401)
|
||||
.message(req.T('api:insufficient_permissions'))
|
||||
.message(req.T('api.insufficient_permissions'))
|
||||
.api()
|
||||
|
||||
return res.api(await application.to_api())
|
||||
@@ -41,28 +41,28 @@ class AppController extends Controller {
|
||||
|
||||
if ( !req.user.can('app:create') )
|
||||
return res.status(401)
|
||||
.message(req.T('api:insufficient_permissions'))
|
||||
.message(req.T('api.insufficient_permissions'))
|
||||
.api()
|
||||
|
||||
const required_fields = ['name', 'identifier']
|
||||
for ( const field of required_fields ) {
|
||||
if ( !req.body[field] )
|
||||
return res.status(400)
|
||||
.message(`${req.T('api:missing_field')} ${field}`)
|
||||
.message(`${req.T('api.missing_field')} ${field}`)
|
||||
.api()
|
||||
}
|
||||
|
||||
// Make sure the identifier is properly formatted
|
||||
if ( !(new RegExp('^[a-zA-Z0-9_]*$')).test(req.body.identifier) )
|
||||
return res.status(400)
|
||||
.message(`${req.T('api:improper_field')} identifier ${req.T('api:alphanum_underscores')}`)
|
||||
.message(`${req.T('api.improper_field')} identifier ${req.T('api.alphanum_underscores')}`)
|
||||
.api()
|
||||
|
||||
// Make sure the identifier is unique
|
||||
const existing_app = await Application.findOne({ identifier: req.body.identifier })
|
||||
if ( existing_app )
|
||||
return res.status(400)
|
||||
.message(req.T('api:application_already_exists'))
|
||||
.message(req.T('api.application_already_exists'))
|
||||
.api()
|
||||
|
||||
const application = new Application({
|
||||
@@ -80,7 +80,7 @@ class AppController extends Controller {
|
||||
const client = await LDAPClient.findById(id)
|
||||
if ( !client || !client.active || !req.user.can(`ldap:client:${client.id}:view`) )
|
||||
return res.status(400)
|
||||
.message(`${req.T('api:invalid_ldap_client_id')} ${id}`)
|
||||
.message(`${req.T('api.invalid_ldap_client_id')} ${id}`)
|
||||
.api()
|
||||
|
||||
const other_assoc_app = await Application.findOne({ ldap_client_ids: client.id })
|
||||
@@ -102,7 +102,7 @@ class AppController extends Controller {
|
||||
const client = await OAuthClient.findById(id)
|
||||
if ( !client || !client.active || !req.user.can(`oauth:client:${client.id}:view`) )
|
||||
return res.status(400)
|
||||
.message(`${req.T('api:invalid_oauth_client_id')} ${id}`)
|
||||
.message(`${req.T('api.invalid_oauth_client_id')} ${id}`)
|
||||
.api()
|
||||
|
||||
const other_assoc_app = await Application.findOne({ oauth_client_ids: client.id })
|
||||
@@ -124,7 +124,7 @@ class AppController extends Controller {
|
||||
const provider = await ServiceProvider.findById(id)
|
||||
if ( !provider || !provider.active || !req.user.can(`saml:provider:${provider.id}:view`) )
|
||||
return res.status(400)
|
||||
.message(`${req.T('api:invalid_saml_service_provider_id')} ${id}`)
|
||||
.message(`${req.T('api.invalid_saml_service_provider_id')} ${id}`)
|
||||
.api()
|
||||
|
||||
const other_assoc_app = await Application.findOne({ saml_service_provider_ids: provider.id })
|
||||
@@ -147,33 +147,33 @@ class AppController extends Controller {
|
||||
|
||||
if ( !application || !application.active )
|
||||
return res.status(404)
|
||||
.message(req.T('api:application_not_found'))
|
||||
.message(req.T('api.application_not_found'))
|
||||
.api()
|
||||
|
||||
if ( !req.user.can(`app:${application.id}:update`) )
|
||||
return res.status(401)
|
||||
.message(req.T('api:insufficient_permissions'))
|
||||
.message(req.T('api.insufficient_permissions'))
|
||||
.api()
|
||||
|
||||
const required_fields = ['name', 'identifier']
|
||||
for ( const field of required_fields ) {
|
||||
if ( !req.body[field] )
|
||||
return res.status(400)
|
||||
.message(`${req.T('api:missing_field')} ${field}`)
|
||||
.message(`${req.T('api.missing_field')} ${field}`)
|
||||
.api()
|
||||
}
|
||||
|
||||
// Make sure the identifier is properly formatted
|
||||
if ( !(new RegExp('^[a-zA-Z0-9_]*$')).test(req.body.identifier) )
|
||||
return res.status(400)
|
||||
.message(`${req.T('api:improper_field')} identifier ${req.T('api:alphanum_underscores')}`)
|
||||
.message(`${req.T('api.improper_field')} identifier ${req.T('api.alphanum_underscores')}`)
|
||||
.api()
|
||||
|
||||
// Make sure the identifier is unique
|
||||
const existing_app = await Application.findOne({ identifier: req.body.identifier })
|
||||
if ( existing_app && existing_app.id !== application.id )
|
||||
return res.status(400)
|
||||
.message(req.T('api:application_already_exists'))
|
||||
.message(req.T('api.application_already_exists'))
|
||||
.api()
|
||||
|
||||
// Verify LDAP client IDs
|
||||
@@ -185,7 +185,7 @@ class AppController extends Controller {
|
||||
const client = await LDAPClient.findById(id)
|
||||
if ( !client || !client.active || !req.user.can(`ldap:client:${client.id}:view`) )
|
||||
return res.status(400)
|
||||
.message(`${req.T('api:invalid_ldap_client_id')} ${id}`)
|
||||
.message(`${req.T('api.invalid_ldap_client_id')} ${id}`)
|
||||
.api()
|
||||
|
||||
const other_assoc_app = await Application.findOne({ ldap_client_ids: client.id })
|
||||
@@ -207,7 +207,7 @@ class AppController extends Controller {
|
||||
const client = await OAuthClient.findById(id)
|
||||
if ( !client || !client.active || !req.user.can(`oauth:client:${client.id}:view`) )
|
||||
return res.status(400)
|
||||
.message(`${req.T('api:invalid_oauth_client_id')} ${id}`)
|
||||
.message(`${req.T('api.invalid_oauth_client_id')} ${id}`)
|
||||
.api()
|
||||
|
||||
const other_assoc_app = await Application.findOne({ oauth_client_ids: client.id })
|
||||
@@ -229,7 +229,7 @@ class AppController extends Controller {
|
||||
const provider = await ServiceProvider.findById(id)
|
||||
if ( !provider || !provider.active || !req.user.can(`saml:provider:${provider.id}:view`) )
|
||||
return res.status(400)
|
||||
.message(`${req.T('api:invalid_saml_service_provider_id')} ${id}`)
|
||||
.message(`${req.T('api.invalid_saml_service_provider_id')} ${id}`)
|
||||
.api()
|
||||
|
||||
const other_assoc_app = await Application.findOne({ saml_service_provider_ids: provider.id })
|
||||
@@ -255,12 +255,12 @@ class AppController extends Controller {
|
||||
|
||||
if ( !application || !application.active )
|
||||
return res.status(404)
|
||||
.message(req.T('api:application_not_found'))
|
||||
.message(req.T('api.application_not_found'))
|
||||
.api()
|
||||
|
||||
if ( !req.user.can(`app:${application.id}:delete`) )
|
||||
return res.status(401)
|
||||
.message(req.T('api:insufficient_permissions'))
|
||||
.message(req.T('api.insufficient_permissions'))
|
||||
.api()
|
||||
|
||||
application.active = false
|
||||
|
||||
Reference in New Issue
Block a user