Skip to content

Commit d6e6528

Browse files
committed
set webdav sys_groupid onAfterInsert, it didn't work onBeforeInsert. Change server_id and sys_groupid if parent_domain_id changes
1 parent d4a475c commit d6e6528

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

interface/web/sites/webdav_user_edit.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,22 +139,22 @@ function onBeforeInsert() {
139139
*/
140140
$hash = md5($this->dataRecord["username"] . ':' . $this->dataRecord["dir"] . ':' . $this->dataRecord["password"]);
141141
$this->dataRecord["password"] = $hash;
142-
143-
/*
144-
* Get the data of the domain, owning the webdav user
145-
*/
146-
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$app->functions->intval($this->dataRecord["parent_domain_id"]));
147-
/* The server is the server of the domain */
148-
$this->dataRecord["server_id"] = $web["server_id"];
149-
/* The Webdav user shall be owned by the same group then the website */
150-
$this->dataRecord["sys_groupid"] = $web['sys_groupid'];
151142
}
152143

153144
parent::onBeforeInsert();
154145
}
155146

156147
function onAfterInsert() {
157148
global $app, $conf;
149+
150+
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$app->functions->intval($this->dataRecord["parent_domain_id"]));
151+
$server_id = $app->functions->intval($web["server_id"]);
152+
153+
// The webdav user shall be owned by the same group then the website
154+
$sys_groupid = $app->functions->intval($web['sys_groupid']);
155+
156+
$sql = "UPDATE webdav_user SET server_id = $server_id, sys_groupid = '$sys_groupid' WHERE webdav_user_id = ".$this->id;
157+
$app->db->query($sql);
158158
}
159159

160160
function onBeforeUpdate() {
@@ -184,6 +184,18 @@ function onBeforeUpdate() {
184184

185185
function onAfterUpdate() {
186186
global $app, $conf;
187+
188+
//* When the site of the webdav user has been changed
189+
if(isset($this->dataRecord['parent_domain_id']) && $this->oldDataRecord['parent_domain_id'] != $this->dataRecord['parent_domain_id']) {
190+
$web = $app->db->queryOneRecord("SELECT * FROM web_domain WHERE domain_id = ".$app->functions->intval($this->dataRecord["parent_domain_id"]));
191+
$server_id = $app->functions->intval($web["server_id"]);
192+
193+
// The webdav user shall be owned by the same group then the website
194+
$sys_groupid = $app->functions->intval($web['sys_groupid']);
195+
196+
$sql = "UPDATE webdav_user SET server_id = $server_id, sys_groupid = '$sys_groupid' WHERE webdav_user_id = ".$this->id;
197+
$app->db->query($sql);
198+
}
187199
}
188200

189201
}

0 commit comments

Comments
 (0)