Permalink
Browse files

Fix user_create_user and external users mandatory prefix that was bro…

…ken.
  • Loading branch information...
1 parent dc85a5c commit 1c95a90cb18f94f35deba114befb1f7851ee7f85 @cdujeu cdujeu committed Oct 13, 2016
@@ -777,13 +777,21 @@ public function switchAction(ServerRequestInterface $requestInterface, ResponseI
if ($action == "user_create_user" && isSet($httpVars["NEW_new_user_id"])) {
$updating = false;
OptionsHelper::parseStandardFormParameters($ctx, $httpVars, $data, "NEW_");
- $original_id = InputFilter::decodeSecureMagic($data["new_user_id"]);
- $data["new_user_id"] = InputFilter::decodeSecureMagic($data["new_user_id"], InputFilter::SANITIZE_EMAILCHARS);
- if($original_id != $data["new_user_id"]){
- throw new \Exception(str_replace("%s", $data["new_user_id"], $mess["ajxp_conf.127"]));
+ $originalId = InputFilter::decodeSecureMagic($data["new_user_id"]);
+ $newUserId = InputFilter::decodeSecureMagic($data["new_user_id"], InputFilter::SANITIZE_EMAILCHARS);
+ if($originalId != $newUserId){
+ throw new PydioException(str_replace("%s", $newUserId, $mess["ajxp_conf.127"]));
}
- if (UsersService::userExists($data["new_user_id"], "w")) {
- throw new \Exception($mess["ajxp_conf.43"]);
+ $prefix = '';
+ $sharePlugin = PluginsService::getInstance($ctx)->getPluginById("action.share");
+ if($sharePlugin !== null){
+ $prefix = $sharePlugin->getContextualOption($ctx, "SHARED_USERS_TMP_PREFIX");
+ }
+ if(!empty($prefix) && strpos($newUserId, $prefix) !== 0){
+ $newUserId = $prefix . $newUserId;
+ }
+ if (UsersService::userExists($newUserId, "w")) {
+ throw new PydioException($mess["ajxp_conf.43"]);
}
$limit = $loggedUser->getMergedRole()->filterParameterValue("core.conf", "USER_SHARED_USERS_LIMIT", AJXP_REPO_SCOPE_ALL, "");
if (!empty($limit) && intval($limit) > 0) {
@@ -792,8 +800,7 @@ public function switchAction(ServerRequestInterface $requestInterface, ResponseI
throw new \Exception($mess['483']);
}
}
-
- $userObject = UsersService::createUser($data["new_user_id"], $data["new_password"]);
+ $userObject = UsersService::createUser($newUserId, $data["new_password"]);
$userObject->setParent($loggedUser->getId());
$userObject->save('superuser');
$userObject->getPersonalRole()->clearAcls();
@@ -853,7 +860,7 @@ public function switchAction(ServerRequestInterface $requestInterface, ResponseI
UsersService::updateUser($userObject);
}
- if ($action == "user_create_user") {
+ if ($action == "user_create_user" && isSet($newUserId)) {
Controller::applyHook($updating?"user.after_update":"user.after_create", [$ctx, $userObject]);
if (isset($data["send_email"]) && $data["send_email"] == true && !empty($data["email"])) {
@@ -863,13 +870,11 @@ public function switchAction(ServerRequestInterface $requestInterface, ResponseI
$link = ApplicationState::detectServerURL();
$apptitle = ConfService::getGlobalConf("APPLICATION_TITLE");
$subject = str_replace("%s", $apptitle, $mess["507"]);
- $body = str_replace(["%s", "%link", "%user", "%pass"], [$apptitle, $link, $data["new_user_id"], $data["new_password"]], $mess["508"]);
+ $body = str_replace(["%s", "%link", "%user", "%pass"], [$apptitle, $link, $newUserId, $data["new_password"]], $mess["508"]);
$mailer->sendMail($ctx, [$data["email"]], $subject, $body);
}
}
-
- $responseInterface = $responseInterface->withHeader("Content-type", "text/plain");
- $responseInterface->getBody()->write("SUCCESS");
+ $responseInterface = new JsonResponse(["result" => "SUCCESS", "createdUserId" => $newUserId]);
} else {
@@ -321,32 +321,23 @@
var values = $H(transport.responseJSON);
values.set("existing_user_id", user_id);
- var params = $A(pydio.getPluginConfigs('conf').get('NEWUSERS_EDIT_PARAMETERS').split(','));
- for(var i=0;i<params.length;i++){
- params[i] = "user/preferences/pref[@exposed]|//param[@name='"+params[i]+"']";
- }
var f = new FormManager();
- var def1 = $A();
- def1.push($H({
- description: MessageHash[522],
- editable: "true",
- expose: "true",
- label: MessageHash[522],
- name: "existing_user_id",
- scope: "user",
- type: "hidden"
- }),$H({
- description: MessageHash[524],
- editable: "true",
- expose: "true",
- label: MessageHash[524],
- name: "new_password",
- scope: "user",
- type: "password-create"
- }));
- var definitions = f.parseParameters(pydio.getXmlRegistry(), params.join('|'));
- definitions.each(function(el){ def1.push(el); });
- f.createParametersInputs(oForm.down('#user_create_user'), def1, true, values, false, true);
+ var parameters = [];
+ PydioUsers.Client.getCreateUserParameters().map(function(obj){
+ if(obj.type === 'valid-password') {
+ obj.type = 'password-create';
+ }
+ if(obj.name === 'new_user_id'){
+ obj.name = 'existing_user_id';
+ obj.type = 'hidden';
+ }
+ if(obj.name === 'send_email'){
+ return;
+ }
+ parameters.push($H(obj));
+ });
+
+ f.createParametersInputs(oForm.down('#user_create_user'), parameters, true, values, false, true);
modal.refreshDialogPosition();
};
@@ -384,48 +375,28 @@
<processing>
<clientCallback prepareModal="true" dialogOpenForm="user_create_user" dialogOkButtonOnly="false" dialogSkipButtons="false">
<dialogOnOpen><![CDATA[
- var params = $A(pydio.getPluginConfigs('conf').get('NEWUSERS_EDIT_PARAMETERS').split(','));
- for(var i=0;i<params.length;i++){
- params[i] = "user/preferences/pref[@exposed]|//param[@name='"+params[i]+"']";
- }
+ var parameters = PydioUsers.Client.getCreateUserParameters().map(function(obj){
+ if(obj.type === 'valid-password') obj.type = 'password-create';
+ return $H(obj)
+ });
var f = new FormManager();
- var def1 = $A();
- def1.push($H({
- description: MessageHash[522],
- editable: "true",
- expose: "true",
- label: MessageHash[522],
- name: "new_user_id",
- scope: "user",
- type: "string"
- }),$H({
- description: MessageHash[523],
- editable: "true",
- expose: "true",
- label: MessageHash[523],
- name: "new_password",
- scope: "user",
- type: "password-create"
- }));
- var definitions = f.parseParameters(pydio.getXmlRegistry(), params.join('|'));
- definitions.each(function(el){ def1.push(el); });
- f.createParametersInputs(oForm.down('#user_create_user'), def1, true, $H(), false, true);
+ f.createParametersInputs(oForm.down('#user_create_user'), parameters, true, $H(), false, true);
modal.refreshDialogPosition();
]]></dialogOnOpen>
<dialogOnComplete hideDialog="true"><![CDATA[
var params = $H();
var f = new FormManager();
- f.serializeParametersInputs(oForm.down('#user_create_user'), params, 'NEW_');
- var conn = new Connexion();
- params.set("get_action", "user_create_user");
- conn.setParameters(params);
- conn.setMethod("POST");
- conn.onComplete = function(transport){
- if($("address_book")){
- $("address_book").ajxpPaneObject.reloadDataModel();
- }
- };
- conn.sendAsync();
+ f.serializeParametersInputs(oForm.down('#user_create_user'), params, 'NEW_');
+ var conn = new Connexion();
+ params.set("get_action", "user_create_user");
+ conn.setParameters(params);
+ conn.setMethod("POST");
+ conn.onComplete = function(transport){
+ if($("address_book")){
+ $("address_book").ajxpPaneObject.reloadDataModel();
+ }
+ };
+ conn.sendAsync();
]]></dialogOnComplete>
<dialogOnCancel><![CDATA[]]></dialogOnCancel>
</clientCallback>
@@ -124,7 +124,8 @@
}
static getCreateUserParameters(){
- var basicParameters = [];
+ let basicParameters = [];
+ let prefix = pydio.getPluginConfigs('action.share').get('SHARED_USERS_TMP_PREFIX');
basicParameters.push({
description: MessageHash['533'],
editable: false,
@@ -133,7 +134,8 @@
name: "new_user_id",
scope: "user",
type: "string",
- mandatory: "true"
+ mandatory: "true",
+ "default": prefix ? prefix : ''
},{
description: MessageHash['534'],
editable: "true",
@@ -143,15 +145,6 @@
scope: "user",
type: "valid-password",
mandatory: "true"
- },{
- description: MessageHash['536'],
- editable: "true",
- expose: "true",
- label: MessageHash['535'],
- name: "send_email",
- scope: "user",
- type: "boolean",
- mandatory: true
});
var params = global.pydio.getPluginConfigs('conf').get('NEWUSERS_EDIT_PARAMETERS').split(',');
@@ -162,6 +155,16 @@
PydioForm.Manager.parseParameters(global.pydio.getXmlRegistry(), xPath).map(function(el){
basicParameters.push(el);
});
+ basicParameters.push({
+ description: MessageHash['536'],
+ editable: "true",
+ expose: "true",
+ label: MessageHash['535'],
+ name: "send_email",
+ scope: "user",
+ type: "boolean",
+ mandatory: true
+ });
return basicParameters;
}
@@ -172,7 +175,7 @@
static createUserFromPost(postValues, callback){
postValues['get_action'] = 'user_create_user';
PydioApi.getClient().request(postValues, function(transport){
- callback(postValues);
+ callback(postValues, transport.responseJSON);
}.bind(this));
}
@@ -211,7 +211,7 @@ Class.create("AjxpUsersCompleter", Ajax.Autocompleter, {
conn.setMethod("POST");
var success = false;
conn.onComplete = function(transport){
- if(transport.responseText == 'SUCCESS'){
+ if(transport.responseJSON['result'] === 'SUCCESS'){
var id = createActionPanel.down('[name="new_user_id"]').getValue();
var label = id;
if(createActionPanel.down('[name="USER_DISPLAY_NAME"]')){
@@ -105,8 +105,13 @@
var prefix = PydioUsers.Client.getCreateUserPostPrefix();
var values = this.refs['creationForm'].getValuesForPost(prefix);
- PydioUsers.Client.createUserFromPost(values, function(values){
- var id = values[prefix + 'new_user_id'];
+ PydioUsers.Client.createUserFromPost(values, function(values, jsonReponse){
+ let id;
+ if(jsonReponse['createdUserId']){
+ id = jsonReponse['createdUserId'];
+ }else{
+ id = values[prefix + 'new_user_id'];
+ }
var display = values[prefix + 'USER_DISPLAY_NAME'] || id;
var fakeUser = new PydioUsers.User(id, display, 'user');
this.props.onValueSelected(id, display, 'user', fakeUser);
@@ -186,9 +191,11 @@
},
getInitialState: function(){
+ let userPrefix = pydio.getPluginConfigs('action.share').get('SHARED_USERS_TMP_PREFIX');
+ if(!userPrefix || this.props.newUserName.startsWith(userPrefix)) userPrefix = '';
return {
values:{
- new_user_id:this.props.newUserName,
+ new_user_id:userPrefix + this.props.newUserName,
lang:global.pydio.currentLanguage,
new_password:'',
send_email:true

0 comments on commit 1c95a90

Please sign in to comment.