Skip to content

Commit f4de70a

Browse files
committed
- Fixed FS#3354 - Protected folders must not be created twice.
- Make sure the correct sys_groupid is saved for web folders and web folder users.
1 parent 9910199 commit f4de70a

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

interface/web/sites/lib/lang/de_web_folder.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ $wb['parent_domain_id_txt'] = 'Webseite';
44
$wb['path_txt'] = 'Pfad';
55
$wb['active_txt'] = 'Aktiv';
66
$wb['path_error_regex'] = 'Ungültiger Pfad.';
7+
$wb['error_folder_already_protected_txt'] = 'Für diesen Ordner existiert schon ein Eintrag.';
78
?>

interface/web/sites/lib/lang/de_web_folder_user.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ $wb['repeat_password_txt'] = 'Passwort wiederholen';
1010
$wb['password_mismatch_txt'] = 'Die Passwörter stimmen nicht überein.';
1111
$wb['password_match_txt'] = 'Die Passwörter stimmen überein.';
1212
$wb['no_folder_perm'] = 'Sie haben keine Berechtigung für diesen Ordner.';
13+
$wb['error_user_exists_already_txt'] = 'Für diesen Benutzer existiert schon ein Eintrag.';
1314
?>

interface/web/sites/lib/lang/en_web_folder.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ $wb["parent_domain_id_txt"] = 'Website';
44
$wb["path_txt"] = 'Path';
55
$wb["active_txt"] = 'Active';
66
$wb["path_error_regex"] = 'Invalid folder path.';
7+
$wb['error_folder_already_protected_txt'] = 'There is already a record for this folder.';
78
?>

interface/web/sites/lib/lang/en_web_folder_user.lng

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ $wb['repeat_password_txt'] = 'Repeat Password';
1010
$wb['password_mismatch_txt'] = 'The passwords do not match.';
1111
$wb['password_match_txt'] = 'The passwords do match.';
1212
$wb["no_folder_perm"] = 'You have no permission for this folder.';
13+
$wb['error_user_exists_already_txt'] = 'There is already a record for this user.';
1314
?>

interface/web/sites/web_folder_edit.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,45 @@ function onSubmit() {
6060

6161
// Set a few fixed values
6262
$this->dataRecord["server_id"] = $parent_domain["server_id"];
63+
64+
// make sure this folder isn't protected already
65+
if($this->id > 0){
66+
$folder = $app->db->queryOneRecord("SELECT * FROM web_folder WHERE parent_domain_id = ".$this->dataRecord['parent_domain_id']." AND path = '".$this->dataRecord['path']."' AND web_folder_id != ".$this->id);
67+
} else {
68+
$folder = $app->db->queryOneRecord("SELECT * FROM web_folder WHERE parent_domain_id = ".$this->dataRecord['parent_domain_id']." AND path = '".$this->dataRecord['path']."'");
69+
}
70+
if(is_array($folder) && !empty($folder)) $app->tform->errorMessage .= $app->tform->lng('error_folder_already_protected_txt');
6371

6472
parent::onSubmit();
6573
}
74+
75+
function onAfterInsert() {
76+
global $app, $conf;
77+
78+
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$app->functions->intval($this->dataRecord["parent_domain_id"]));
79+
80+
// The web folder entry shall be owned by the same group as the website
81+
$sys_groupid = $app->functions->intval($web['sys_groupid']);
82+
83+
$sql = "UPDATE web_folder SET sys_groupid = '$sys_groupid' WHERE web_folder_id = ".$this->id;
84+
$app->db->query($sql);
85+
}
86+
87+
function onAfterUpdate() {
88+
global $app, $conf;
89+
90+
//* When the site of the web folder has been changed
91+
if(isset($this->dataRecord['parent_domain_id']) && $this->oldDataRecord['parent_domain_id'] != $this->dataRecord['parent_domain_id']) {
92+
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$app->functions->intval($this->dataRecord["parent_domain_id"]));
93+
94+
// The web folder entry shall be owned by the same group as the website
95+
$sys_groupid = $app->functions->intval($web['sys_groupid']);
96+
97+
$sql = "UPDATE web_folder SET sys_groupid = '$sys_groupid' WHERE web_folder_id = ".$this->id;
98+
$app->db->query($sql);
99+
}
100+
101+
}
66102

67103
}
68104

interface/web/sites/web_folder_user_edit.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,45 @@ function onSubmit() {
6060

6161
// Set a few fixed values
6262
$this->dataRecord["server_id"] = $folder["server_id"];
63+
64+
// make sure this folder/user combination does not exist already
65+
if($this->id > 0){
66+
$user = $app->db->queryOneRecord("SELECT * FROM web_folder_user WHERE web_folder_id = ".$this->dataRecord['web_folder_id']." AND username = '".$this->dataRecord['username']."' AND web_folder_user_id != ".$this->id);
67+
} else {
68+
$user = $app->db->queryOneRecord("SELECT * FROM web_folder_user WHERE web_folder_id = ".$this->dataRecord['web_folder_id']." AND username = '".$this->dataRecord['username']."'");
69+
}
70+
if(is_array($user) && !empty($user)) $app->tform->errorMessage .= $app->tform->lng('error_user_exists_already_txt');
6371

6472
parent::onSubmit();
6573
}
74+
75+
function onAfterInsert() {
76+
global $app, $conf;
77+
78+
$folder = $app->db->queryOneRecord("SELECT * FROM web_folder WHERE web_folder_id = ".$app->functions->intval($this->dataRecord["web_folder_id"]));
79+
80+
// The web folder user entry shall be owned by the same group as the web folder
81+
$sys_groupid = $app->functions->intval($folder['sys_groupid']);
82+
83+
$sql = "UPDATE web_folder_user SET sys_groupid = '$sys_groupid' WHERE web_folder_user_id = ".$this->id;
84+
$app->db->query($sql);
85+
}
86+
87+
function onAfterUpdate() {
88+
global $app, $conf;
89+
90+
//* When the web folder has been changed
91+
if(isset($this->dataRecord['web_folder_id']) && $this->oldDataRecord['web_folder_id'] != $this->dataRecord['web_folder_id']) {
92+
$folder = $app->db->queryOneRecord("SELECT * FROM web_folder WHERE web_folder_id = ".$app->functions->intval($this->dataRecord["web_folder_id"]));
93+
94+
// The web folder user entry shall be owned by the same group as the web folder
95+
$sys_groupid = $app->functions->intval($folder['sys_groupid']);
96+
97+
$sql = "UPDATE web_folder_user SET sys_groupid = '$sys_groupid' WHERE web_folder_user_id = ".$this->id;
98+
$app->db->query($sql);
99+
}
100+
101+
}
66102

67103
}
68104

0 commit comments

Comments
 (0)