Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vcmirko committed Jun 21, 2024
1 parent 5ec367c commit d634756
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 13 deletions.
1 change: 0 additions & 1 deletion docs/.htaccess

This file was deleted.

2 changes: 1 addition & 1 deletion server/src/auth/auth_azuread.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ exports.initialize = async () =>{
logger.info("Azure AD is not enabled")
}else{
azureConfig = await AzureAd.find()
settings = await Settings.find()
settings = await Settings.findUrl()
url = settings.url?.replace(/\/$/g,'')
if(!url){
logger.error("AnsibleForms Url is not set")
Expand Down
2 changes: 1 addition & 1 deletion server/src/auth/auth_oidc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ exports.initialize = async () =>{
logger.info("OIDC is not enabled")
}else{
oidcConfig = await OIDC.find()
settings = await Settings.find()
settings = await Settings.findUrl()
url = settings.url?.replace(/\/$/g,'')
if(!url){
logger.error("AnsibleForms Url is not set")
Expand Down
7 changes: 4 additions & 3 deletions server/src/controllers/schema.controller.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
'use strict';
const Schema = require('../models/schema.model');
var RestResult = require('../models/restResult.model');
var Helpers = require('../lib/common')
var helpers = require('../lib/common')
var util = require('util');

exports.hasSchema = function(req, res) {

Schema.hasSchema()
.then((result)=>{ res.json(new RestResult("success","schema and tables are ok",result.data?.success,result.data?.failed)) })
.catch((err)=>{
Expand All @@ -14,13 +15,13 @@ exports.hasSchema = function(req, res) {
}else{
res.json(new RestResult("error","schema and tables are not ok",result.data?.success,result.data?.failed))
}

})

};
exports.create = function(req, res) {
Schema.create()
.then((result)=>{ res.json(new RestResult("success",result,null,"")) })
.catch((err)=>{
res.json(new RestResult("error",Helpers.getError(err),null,null))
res.json(new RestResult("error",helpers.getError(err),null,null))
})
};
3 changes: 2 additions & 1 deletion server/src/db/create_schema_and_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ CREATE TABLE `settings` (
`mail_username` varchar(250) DEFAULT NULL,
`mail_password` text DEFAULT NULL,
`mail_from` varchar(250) DEFAULT NULL,
`url` varchar(250) DEFAULT NULL
`url` varchar(250) DEFAULT NULL,
`forms_yaml` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
USE `AnsibleForms`;
DROP TABLE IF EXISTS `azuread`;
Expand Down
4 changes: 2 additions & 2 deletions server/src/models/form.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ Form.load = async function() {
var forms=undefined
var rawdata=undefined

var settings = await Settings.find()
var settings = await Settings.findFormsYaml()
var appFormsPath=undefined
if(settings.forms_yaml){
if(settings.forms_yaml && appConfig.enableFormsYamlInDatabase){
logger.info(`Using forms yaml from database`)
appFormsPath = (await Repository.getFormsPath(false)) || appConfig.formsPath
}else{
Expand Down
4 changes: 2 additions & 2 deletions server/src/models/job.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ Job.approve = async function(user,id,next){
Job.sendApprovalNotification = async function(approval,extravars,jobid){
if(!approval?.notifications?.length>0)return false
try{
const config = await Settings.find()
const config = await Settings.findUrl()
const url = config.url?.replace(/\/$/g,'') // remove trailing slash if present

var subject = Helpers.replacePlaceholders(approval.title,extravars) || "AnsibleForms Approval Request"
Expand Down Expand Up @@ -626,7 +626,7 @@ Job.sendStatusNotification = async function(jobid){
return false
}else{
// we have notifications, correct status => let's send the mail
const config = await Settings.find()
const config = await Settings.findUrl()
const url = config.url?.replace(/\/$/g,'') // remove trailing slash if present

if(!url){
Expand Down
5 changes: 5 additions & 0 deletions server/src/models/lock.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@ var config=require('../../config/app.config')
const moment = require("moment")
const Repository = require("./repository.model");
const Repo = require("./repo.model");
const Settings = require("./settings.model");

//lock object create
var Lock=function(){

};
Lock.status = async function(user){
const hasFormsRepository = await Repository.hasFormsRepository()
const settings = await Settings.findFormsYaml()
if(hasFormsRepository){
throw new Error("Designer is disabled, Forms repository found.")
}
if(settings.forms_yaml){
throw new Error("Designer is disabled, Forms are stored in the database.")
}
try{
const lock = await Lock.get()
const lck=YAML.parse(lock)
Expand Down
51 changes: 49 additions & 2 deletions server/src/models/settings.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Settings.importFormsFileFromYaml = async function(){
}else{
logger.notice(`Loading ${appFormsPath} into the database`)
let formsFile = fs.readFileSync(appFormsPath, 'utf8')
var settings = await Settings.find()
var settings = await Settings.findFormsYaml()
settings.forms_yaml = formsFile
await Settings.update(settings)
return "Forms.yaml imported successfully"
Expand All @@ -54,6 +54,53 @@ Settings.find = function () {
logger.error("Couldn't decrypt mail password, did the secretkey change ?")
res[0].mail_password=""
}
res[0].enableFormsYamlInDatabase = appConfig.enableFormsYamlInDatabase
return res[0]
}else{
logger.error("No settings record in the database, something is wrong")
throw "No settings record in the database, something is wrong"
}
})

};
Settings.findMailSettings = function () {
return mysql.do("SELECT mail_server,mail_port,mail_secure,mail_username,mail_password,mail_from FROM AnsibleForms.`settings` limit 1;")
.then((res)=>{
if(res.length>0){
try{
if(res[0].mail_password!=""){
res[0].mail_password=decrypt(res[0].mail_password)
}
}catch(e){
logger.error("Couldn't decrypt mail password, did the secretkey change ?")
res[0].mail_password=""
}
return res[0]
}else{
logger.error("No settings record in the database, something is wrong")
throw "No settings record in the database, something is wrong"
}
})

};
Settings.findUrl = function () {

return mysql.do("SELECT url FROM AnsibleForms.`settings` limit 1;")
.then((res)=>{
if(res.length>0){
return res[0]
}else{
logger.error("No settings record in the database, something is wrong")
throw "No settings record in the database, something is wrong"
}
})

};
Settings.findFormsYaml = function () {

return mysql.do("SELECT forms_yaml FROM AnsibleForms.`settings` limit 1;")
.then((res)=>{
if(res.length>0){
return res[0]
}else{
logger.error("No settings record in the database, something is wrong")
Expand All @@ -77,7 +124,7 @@ Settings.mailcheck = function(config,to){
return Settings.maildo(config,to,subject,message)
}
Settings.mailsend = function(to,subject,message){
return Settings.find()
return Settings.findMailSettings()
.then((config)=>{
return Settings.maildo(config,to,subject,message)
})
Expand Down

0 comments on commit d634756

Please sign in to comment.