From cfab4ff6a47a50a9ac6d6d49e97ba43444644863 Mon Sep 17 00:00:00 2001
From: Sebastien Curt <sebastien.curt@tetras-libre.fr>
Date: Mon, 21 Feb 2022 14:33:34 +0100
Subject: [PATCH] Allow deactivation of project deletion using environment
 variable.

---
 capsule-prototype/js/online-rekall/Rekall.js | 40 +++++++-------------
 capsule-prototype/js/online-script.js        |  2 +-
 capsule-prototype/php/rekallApp.js.php       |  2 +-
 3 files changed, 15 insertions(+), 29 deletions(-)

diff --git a/capsule-prototype/js/online-rekall/Rekall.js b/capsule-prototype/js/online-rekall/Rekall.js
index 5048899..0f14490 100644
--- a/capsule-prototype/js/online-rekall/Rekall.js
+++ b/capsule-prototype/js/online-rekall/Rekall.js
@@ -44,16 +44,6 @@ function Rekall(options) {
 		if(!url.endsWith("/"))
 			url = url + "/";
 
-		if(window.location.host == "dev3.memorekall.com") {
-			url = url.replace("dev3.memorekall.com", "dev2.memorekall.com");
-		}
-		if(window.location.host == "legacy.memorekall.com") {
-			url = url.replace("legacy.memorekall.com", "project.memorekall.com");
-		}
-		if(window.location.host == "legacy.memorekall.fr") {
-			url = url.replace("legacy.memorekall.fr", "project.memorekall.com");
-		}
-
 		return url;
 	}
 
@@ -65,12 +55,20 @@ function Rekall(options) {
 	this.Settings = $.extend({}, defaultSettings, options);
 }
 
-Rekall.prototype.enableProjectDeletion = function() {
-	this.Settings.allowProjectDeletion = true;
-}
+Rekall.prototype.allowProjectDeletion = function(){
+	if (arguments.length <= 0 && 'boolean' !== typeof arguments[0]){
+		return this.Settings._allowProjectDeletion;
+	}
 
-Rekall.prototype.disableProjectDeletion = function() {
-	this.Settings.allowProjectDeletion = false;
+	if (arguments[0]) {
+		this.Settings._allowProjectDeletion = true;
+		$('#popupSettingsBtnDelete').attr('display', null);
+	}
+	else {
+		this.Settings._allowProjectDeletion = false;
+		$('#popupSettingsBtnDelete').hide();
+	}
+	this.Settings._allowProjectDeletion = arguments[0];
 }
 
 Rekall.prototype.loadXMLFile = function() {
@@ -92,18 +90,6 @@ Rekall.prototype.loadXMLFile = function() {
 		$('#popupSettingsBtnDelete').hide();
 	};
 
-	if(window.location.host == "dev3.memorekall.com") {
-		url = url.replace("dev3.memorekall.com", "dev2.memorekall.com");
-		$("#popupSettingsBtnDelete").hide();
-	} 
-	if(window.location.host == "legacy.memorekall.com") {
-		url = url.replace("legacy.memorekall.com", "project.memorekall.com");
-		$("#popupSettingsBtnDelete").hide();
-	} 
-	if(window.location.host == "legacy.memorekall.fr") {
-		url = url.replace("legacy.memorekall.fr", "project.memorekall.com");
-		$("#popupSettingsBtnDelete").hide();
-	}
 	this.baseUrl = url;
 	
 	var thiss = this;
diff --git a/capsule-prototype/js/online-script.js b/capsule-prototype/js/online-script.js
index 17e974f..bf13d5c 100644
--- a/capsule-prototype/js/online-script.js
+++ b/capsule-prototype/js/online-script.js
@@ -1,8 +1,8 @@
 var rekall = new Rekall();
 var rekall_common = new Object();
 $(document).ready(function() {
-	rekall.Settings.ProjectDeletionEnabled = window.app.ProjectDeletionEnabled;
 
+	rekall.allowProjectDeletion(window.app.Settings.Project.ProjectDeletionEnabled)
 	Utils.actionPrefix = "php/";
 	Utils.actionSuffix = ".php?r=";
 	
diff --git a/capsule-prototype/php/rekallApp.js.php b/capsule-prototype/php/rekallApp.js.php
index f0d9638..bce36d1 100644
--- a/capsule-prototype/php/rekallApp.js.php
+++ b/capsule-prototype/php/rekallApp.js.php
@@ -3,7 +3,7 @@ Header("content-type: application/x-javascript");
 
 $front_url = $_ENV["FRONT_URL_EXTERNAL"];
 $member_url = $_ENV["MEMBER_URL_EXTERNAL"];
-$project_allow_deletion = isset($_ENV["LEGACY_PROJECT_DELETION_ENABLED"]) && $_ENV["LEGACY_PROJECT_DELETION_ENABLED"] == 'true';
+$project_allow_deletion = isset($_ENV["LEGACY_PROJECT_DELETION_ENABLED"]) && $_ENV["LEGACY_PROJECT_DELETION_ENABLED"] == 'true' ? 'true' : 'false';
 ?>
 function RekallApp (opts = {}){
     const METHODS = [
-- 
GitLab