Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Expand the Shared User creation form to fill user email, full name, s…
Browse files Browse the repository at this point in the history
…end an email, etc.
  • Loading branch information
cdujeu committed Nov 7, 2013
1 parent e0a945c commit 0489aeb
Show file tree
Hide file tree
Showing 13 changed files with 367 additions and 60 deletions.
3 changes: 2 additions & 1 deletion core/src/plugins/action.share/class.ShareCenter.js
Expand Up @@ -237,11 +237,12 @@ Class.create("ShareCenter", {
{
tmpUsersPrefix:pref,
updateUserEntryAfterCreate:updateUserEntryAfterCreate,
/*
createUserPanel:{
panel : $("create_shared_user"),
pass : $("shared_pass"),
confirmPass: $("shared_pass_confirm")
},
},*/
indicator: $("complete_indicator"),
minChars:parseInt(ajaxplorer.getPluginConfigs("conf").get("USERS_LIST_COMPLETE_MIN_CHARS"))
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -1131,7 +1131,7 @@ public function createSharedRepository($httpVars, $repository, $accessDriver, $u
return 102;
}
} else {
if ( ($httpVars["create_guest_user"] != "true" && !ConfService::getCoreConf("ALLOW_NEWUSERS_SHARING", "conf")) || AuthService::isReservedUserId($userName)) {
if ( ($httpVars["create_guest_user"] != "true" && !ConfService::getCoreConf("USER_CREATE_USERS", "conf")) || AuthService::isReservedUserId($userName)) {
return 102;
}
if (!isSet($httpVars["shared_pass"]) || $httpVars["shared_pass"] == "") {
Expand Down
85 changes: 78 additions & 7 deletions core/src/plugins/core.conf/class.AbstractConfDriver.php
Expand Up @@ -113,6 +113,24 @@ protected function parseSpecificContributions(&$contribNode)
}
}

// CREATE A NEW USER
if (!ConfService::getCoreConf("USER_CREATE_USERS", "conf")) {
unset($this->actions["user_create_user"]);
$actionXpath=new DOMXPath($contribNode->ownerDocument);
$publicUrlNodeList = $actionXpath->query('action[@name="user_create_user"]', $contribNode);
if ($publicUrlNodeList->length) {
$publicUrlNode = $publicUrlNodeList->item(0);
$contribNode->removeChild($publicUrlNode);
}
unset($this->actions["user_delete_user"]);
$actionXpath=new DOMXPath($contribNode->ownerDocument);
$publicUrlNodeList = $actionXpath->query('action[@name="user_delete_user"]', $contribNode);
if ($publicUrlNodeList->length) {
$publicUrlNode = $publicUrlNodeList->item(0);
$contribNode->removeChild($publicUrlNode);
}
}

}

// NEW FUNCTIONS FOR LOADING/SAVING PLUGINS CONFIGS
Expand Down Expand Up @@ -581,10 +599,31 @@ public function switchAction($action, $httpVars, $fileVars)
// SAVE USER PREFERENCE
//------------------------------------
case "custom_data_edit":
case "user_create_user":

$userObject = AuthService::getLoggedUser();
$data = array();
AJXP_Utils::parseStandardFormParameters($httpVars, $data, null, "PREFERENCES_");

if($action == "user_create_user"){
AJXP_Utils::parseStandardFormParameters($httpVars, $data, null, "NEW_");

if(AuthService::userExists($data["new_user_id"])){
throw new Exception('Please choose another user id');
}
AJXP_Controller::applyHook("user.before_create", array($data["new_user_id"]));

AuthService::createUser($data["new_user_id"], $data["new_password"]);
$userObject = ConfService::getConfStorageImpl()->createUserObject($data["new_user_id"]);
$loggedUser = AuthService::getLoggedUser();
$userObject->setParent($loggedUser->getId());
$userObject->save('superuser');
$userObject->personalRole->clearAcls();
$userObject->setGroupPath($loggedUser->getGroupPath());
$userObject->setProfile("shared");

}else{
$userObject = AuthService::getLoggedUser();
AJXP_Utils::parseStandardFormParameters($httpVars, $data, null, "PREFERENCES_");
}

$paramNodes = AJXP_PluginsService::searchAllManifests("//server_settings/param[contains(@scope,'user') and @expose='true']", "node", false, false, true);
$rChanges = false;
Expand All @@ -609,16 +648,36 @@ public function switchAction($action, $httpVars, $fileVars)
if ($rChanges) {
AuthService::updateRole($userObject->personalRole, $userObject);
$userObject->recomputeMergedRole();
AuthService::updateUser($userObject);
if($action == "custom_data_edit"){
AuthService::updateUser($userObject);
}
}

if($action == "user_create_user"){
AJXP_Controller::applyHook("user.after_create", array($userObject));
if(isset($data["send_email"]) && $data["send_email"] == true && !empty($data["email"])){
$mailer = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("mailer");
if ($mailer !== false) {
$mess = ConfService::getMessages();
$link = AJXP_Utils::detectServerURL();
$apptitle = ConfService::getCoreConf("APPLICATION_NAME");
$subject = "Welcome on Pydio!";
$body = "An account was just created for you by %s on $apptitle. <br>Go to <a href='$link'>$link</a> and use the following credentials to login: %s, %s. ";
$body = sprintf($body, AuthService::getLoggedUser()->getId(), $data["new_user_id"], $data["new_password"]);
$mailer->sendMail(array($data["email"]), $subject, $body);
}
}

AJXP_XMLWriter::header();
AJXP_XMLWriter::sendMessage($mess["241"], null);
AJXP_XMLWriter::close();
echo "SUCCESS";
}else{
AJXP_XMLWriter::header();
AJXP_XMLWriter::sendMessage($mess["241"], null);
AJXP_XMLWriter::close();
}

break;


//------------------------------------
// WEBDAV PREFERENCES
//------------------------------------
Expand Down Expand Up @@ -807,6 +866,18 @@ public function switchAction($action, $httpVars, $fileVars)

break;

case "user_delete_user":

$userId = $httpVars["user_id"];
$userObject = ConfService::getConfStorageImpl()->createUserObject($userId);
if($userObject == null || !$userObject->hasParent() || $userObject->getParent() != AuthService::getLoggedUser()->getId()){
throw new Exception("You are not allowed to edit this user");
}
AuthService::deleteUser($userId);
echo "SUCCESS";

break;

case "user_list_authorized_users" :

$defaultFormat = "html";
Expand All @@ -828,7 +899,7 @@ public function switchAction($action, $httpVars, $fileVars)
}
$users = "";
$index = 0;
if ($regexp != null && !count($allUsers) && ConfService::getCoreConf("ALLOW_NEWUSERS_SHARING", "conf") && !$existingOnly) {
if ($regexp != null && (!count($allUsers) || !array_key_exists($crtValue, $allUsers)) && ConfService::getCoreConf("USER_CREATE_USERS", "conf") && !$existingOnly) {
$users .= "<li class='complete_user_entry_temp' data-temporary='true' data-label='$crtValue'><span class='user_entry_label'>$crtValue (".$mess["448"].")</span></li>";
} else if ($existingOnly && !empty($crtValue)) {
$users .= "<li class='complete_user_entry_temp' data-temporary='true' data-label='$crtValue' data-entry_id='$crtValue'><span class='user_entry_label'>$crtValue</span></li>";
Expand Down
3 changes: 2 additions & 1 deletion core/src/plugins/core.conf/manifest.xml
Expand Up @@ -32,7 +32,8 @@
<global_param description="CONF_MESSAGE[Minimum number of characters to trigger the auto completion feature]" label="CONF_MESSAGE[Users completer min chars]" name="USERS_LIST_COMPLETE_MIN_CHARS" type="integer" default="3" expose="true"/>
<global_param description="CONF_MESSAGE[Do not display real login in parenthesis]" label="CONF_MESSAGE[Hide real login]" name="USERS_LIST_HIDE_LOGIN" type="boolean" default="false"/>
<global_param name="ALLOW_CROSSUSERS_SHARING" group="CONF_MESSAGE[Sharing]" type="boolean" label="CONF_MESSAGE[See existing users]" description="CONF_MESSAGE[Allow the users to pick an existing user when sharing a folder]" mandatory="false" default="true"/>
<global_param name="ALLOW_NEWUSERS_SHARING" group="CONF_MESSAGE[Sharing]" type="boolean" label="CONF_MESSAGE[Create external users]" description="CONF_MESSAGE[Allow the users to create a new user when sharing a folder]" mandatory="false" default="true"/>
<global_param name="USER_CREATE_USERS" group="CONF_MESSAGE[Sharing]" type="boolean" label="CONF_MESSAGE[Create external users]" description="CONF_MESSAGE[Allow the users to create a new user when sharing a folder]" mandatory="false" default="true"/>
<global_param name="NEWUSERS_EDIT_PARAMETERS" group="CONF_MESSAGE[Sharing]" type="string" label="CONF_MESSAGE[External users parameters]" description="CONF_MESSAGE[List of parameters to be edited when creating a new shared user.]" mandatory="false" default="email,USER_DISPLAY_NAME,lang" expose="true"/>
<global_param type="plugin_instance:conf" name="UNIQUE_INSTANCE_CONFIG" group="CONF_MESSAGE[Instance Param]" label="CONF_MESSAGE[Instance]" description="CONF_MESSAGE[Choose the configuration plugin]" mandatory="true" default="conf.serial"/>
</server_settings>
</ajxpcore>
129 changes: 96 additions & 33 deletions core/src/plugins/core.conf/standard_conf_actions.xml
Expand Up @@ -143,6 +143,11 @@
<serverCallback methodName="switchAction"></serverCallback>
</processing>
</action>
<action name="user_delete_user">
<processing>
<serverCallback methodName="switchAction"></serverCallback>
</processing>
</action>
<action name="get_bookmarks">
<gui text="145" title="145" src="edit_user.png" iconClass="icon-star" accessKey="" hasAccessKey="false">
<context selection="false" dir="" recycle="true" actionBar="false" actionBarGroup="filter" contextMenu="false" infoPanel="false"/>
Expand Down Expand Up @@ -215,39 +220,97 @@
</gui>
<rightsContext adminOnly="false" noUser="false" read="false" userLogged="only" write="false"/>
<processing>
<clientCallback prepareModal="true" dialogOpenForm="custom_data_edit" dialogOkButtonOnly="false" dialogSkipButtons="false">
<dialogOnOpen><![CDATA[
var f = new FormManager();
var definitions = f.parseParameters(ajaxplorer.getXmlRegistry(), "user/preferences/pref[@exposed]|//param[contains(@scope,'user')]");
f.createParametersInputs(oForm.down('#custom_data_edit'), definitions, true, ajaxplorer.user.preferences, false, true);
]]></dialogOnOpen>
<dialogOnComplete hideDialog="true"><![CDATA[
var params = $H();
var f = new FormManager();
f.serializeParametersInputs(oForm.down('#custom_data_edit'), params, 'PREFERENCES_');
var conn = new Connexion();
params.set("get_action", "custom_data_edit");
conn.setParameters(params);
conn.setMethod("POST");
conn.onComplete = function(transport){
ajaxplorer.actionBar.parseXmlMessage(transport.responseXML);
document.observeOnce("ajaxplorer:registry_part_loaded", function(event){
if(event.memo != "user/preferences") return;
ajaxplorer.logXmlUser(ajaxplorer.getXmlRegistry());
});
ajaxplorer.loadXmlRegistry(false, "user/preferences");
};
conn.sendAsync();
]]></dialogOnComplete>
<dialogOnCancel><![CDATA[]]></dialogOnCancel>
</clientCallback>
<clientForm id="custom_data_edit"><![CDATA[
<div id="custom_data_edit" action="custom_data_edit" box_width="250">
</div>
]]></clientForm>
<serverCallback methodName="switchAction"></serverCallback>
</processing>
</action>
<clientCallback prepareModal="true" dialogOpenForm="custom_data_edit" dialogOkButtonOnly="false" dialogSkipButtons="false">
<dialogOnOpen><![CDATA[
var f = new FormManager();
var definitions = f.parseParameters(ajaxplorer.getXmlRegistry(), "user/preferences/pref[@exposed]|//param[contains(@scope,'user')]");
f.createParametersInputs(oForm.down('#custom_data_edit'), definitions, true, ajaxplorer.user.preferences, false, true);
modal.refreshDialogPosition();
]]></dialogOnOpen>
<dialogOnComplete hideDialog="true"><![CDATA[
var params = $H();
var f = new FormManager();
f.serializeParametersInputs(oForm.down('#custom_data_edit'), params, 'PREFERENCES_');
var conn = new Connexion();
params.set("get_action", "custom_data_edit");
conn.setParameters(params);
conn.setMethod("POST");
conn.onComplete = function(transport){
ajaxplorer.actionBar.parseXmlMessage(transport.responseXML);
document.observeOnce("ajaxplorer:registry_part_loaded", function(event){
if(event.memo != "user/preferences") return;
ajaxplorer.logXmlUser(ajaxplorer.getXmlRegistry());
});
ajaxplorer.loadXmlRegistry(false, "user/preferences");
};
conn.sendAsync();
]]></dialogOnComplete>
<dialogOnCancel><![CDATA[]]></dialogOnCancel>
</clientCallback>
<clientForm id="custom_data_edit"><![CDATA[
<div id="custom_data_edit" action="custom_data_edit" box_width="320">
</div>
]]></clientForm>
<serverCallback methodName="switchAction"></serverCallback>
</processing>
</action>
<action name="user_create_user">
<gui text="442" title="443" src="edit_user.png" iconClass="icon-reorder" accessKey="" hasAccessKey="false">
<context selection="false" dir="" recycle="true" actionBar="false" actionBarGroup="utils" contextMenu="false" infoPanel="false"/>
</gui>
<rightsContext adminOnly="false" noUser="false" read="false" userLogged="only" write="false"/>
<processing>
<clientCallback prepareModal="true" dialogOpenForm="user_create_user" dialogOkButtonOnly="false" dialogSkipButtons="false">
<dialogOnOpen><![CDATA[
var params = $A(ajaxplorer.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: "User ID",
editable: "true",
expose: "true",
label: "User ID",
name: "new_user_id",
scope: "user",
type: "string"
}),$H({
description: "New user password",
editable: "true",
expose: "true",
label: "Password",
name: "new_password",
scope: "user",
type: "password-create"
}));
var definitions = f.parseParameters(ajaxplorer.getXmlRegistry(), params.join('|'));
definitions.each(function(el){ def1.push(el); });
f.createParametersInputs(oForm.down('#user_create_user'), def1, 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){
};
conn.sendAsync();
]]></dialogOnComplete>
<dialogOnCancel><![CDATA[]]></dialogOnCancel>
</clientCallback>
<clientForm id="user_create_user"><![CDATA[
<div id="user_create_user" action="custom_data_edit" box_width="320">
</div>
]]></clientForm>
<serverCallback methodName="switchAction"></serverCallback>
</processing>
</action>
<action name="switch_language">
<gui text="190" title="190" src="flag.png" accessKey="" hasAccessKey="false" iconClass="icon-flag">
<context selection="false" dir="" recycle="true" actionBar="false" actionBarGroup="utils" contextMenu="false" infoPanel="false"></context>
Expand Down
3 changes: 1 addition & 2 deletions core/src/plugins/core.mailer/AjxpMailer.css
@@ -1,6 +1,5 @@
#mailer_message{
border: 0 !important;
width: 380px;
}

#mailer_message div.message_body input{
Expand All @@ -9,7 +8,7 @@
}

#mailer_message div.message_body textarea{
width: 374px;
width: 334px;
height: 120px;
padding: 2px;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/plugins/gui.ajax/res/js/ajaxplorer.js

Large diffs are not rendered by default.

0 comments on commit 0489aeb

Please sign in to comment.