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

Commit

Permalink
Add a parameter to allow new users creation while sharing (true by de…
Browse files Browse the repository at this point in the history
…fault).

Use AutoCompleter for AjxpMailer
Send users_only in list_authorized_users to avoid retrieving groups.
  • Loading branch information
cdujeu committed Oct 17, 2013
1 parent 14d5eb0 commit f8b01ac
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 62 deletions.
2 changes: 1 addition & 1 deletion core/src/plugins/action.share/class.ShareCenter.php
Expand Up @@ -1096,7 +1096,7 @@ public function createSharedRepository($httpVars, $repository, $accessDriver, $u
return 102;
}
} else {
if (AuthService::isReservedUserId($userName)) {
if ( !ConfService::getCoreConf("ALLOW_NEWUSERS_SHARING", "conf") || AuthService::isReservedUserId($userName)) {
return 102;
}
if(!isSet($httpVars["shared_pass"]) || $httpVars["shared_pass"] == "") return 100;
Expand Down
9 changes: 6 additions & 3 deletions core/src/plugins/core.conf/class.AbstractConfDriver.php
Expand Up @@ -813,19 +813,22 @@ public function switchAction($action, $httpVars, $fileVars)
}
$loggedUser = AuthService::getLoggedUser();
$crtValue = $httpVars["value"];
$usersOnly = isSet($httpVars["users_only"]) && $httpVars["users_only"] == "true";
if(!empty($crtValue)) $regexp = '^'.preg_quote($crtValue);
else $regexp = null;
$limit = min(ConfService::getCoreConf("USERS_LIST_COMPLETE_LIMIT", "conf"), 20);
$allUsers = AuthService::listUsers("/", $regexp, 0, $limit, false);
$allGroups = AuthService::listChildrenGroups("/");
if (!$usersOnly) {
$allGroups = AuthService::listChildrenGroups("/");
}
$users = "";
$index = 0;
if ($regexp != null && !count($allUsers)) {
if ($regexp != null && !count($allUsers) && ConfService::getCoreConf("ALLOW_NEWUSERS_SHARING", "conf")) {
$users .= "<li class='complete_user_entry_temp' data-temporary='true' data-label='$crtValue'><span class='user_entry_label'>$crtValue (".$mess["448"].")</span></li>";
}
$mess = ConfService::getMessages();
if($regexp == null) $users .= "<li class='complete_group_entry' data-group='/' data-label='".$mess["447"]."'><span class='user_entry_label'>".$mess["447"]."</span></li>";
if (count($allGroups)) {
if (!$usersOnly && count($allGroups)) {
foreach ($allGroups as $groupId => $groupLabel) {
if ($regexp == null || preg_match("/$regexp/i", $groupLabel)) {
$users .= "<li class='complete_group_entry' data-group='$groupId' data-label='$groupLabel' data-entry_id='$groupId'><span class='user_entry_label'>".$groupLabel."</span></li>";
Expand Down
1 change: 1 addition & 0 deletions core/src/plugins/core.conf/manifest.xml
Expand Up @@ -31,6 +31,7 @@
<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 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>
20 changes: 19 additions & 1 deletion core/src/plugins/core.mailer/AjxpMailer.css
Expand Up @@ -22,7 +22,7 @@
.mailer_input_label{
display: inline-block;
width: 17%;
padding: 5px 3px;
padding: 7px 4px;
background-color: #E2E2E2;
text-align: right;
font-weight: bold;
Expand All @@ -34,4 +34,22 @@
margin: 1px !important;
width: 78% !important;
display: inline-block !important;
}

#emails_autocomplete {
background-color: white;
margin-top: 3px;
border: 1px solid #bbb;
border-radius: 2px;
box-shadow: 1px 1px 11px rgba(0,0,0,0.5);
}

#emails_autocomplete ul {
list-style: none;
padding: 0;
margin: 0;
}

#emails_autocomplete li.complete_user_entry.selected {
color: black;
}
20 changes: 18 additions & 2 deletions core/src/plugins/core.mailer/class.AjxpMailer.js
Expand Up @@ -48,9 +48,9 @@ Class.create("AjxpMailer", {
hiddenRecipientString = hiddenRecipientString.join(",");
}
var fromString = ajaxplorer.user.id;
$("mailer_message").update("<div id='mailer_message'><div class='message_body'><form>" +
$("mailer_message").update("<div id='mailer_message' style='position: relative;'><div id='emails_autocomplete' style='position:absolute'></div><div class='message_body'><form>" +
"<div class='grey_gradient_light_inputs mailer_input_line'><span class='mailer_input_label'>From:</span><input class='mailer_input_field' type='text' name='from' value='"+fromString+"'/></div>" +
"<div class='grey_gradient_light_inputs mailer_input_line'><span class='mailer_input_label'>To:</span><input class='mailer_input_field' type='text' name='to' value='"+recipientString+"'/></div>" +
"<div class='grey_gradient_light_inputs mailer_input_line'><span class='mailer_input_label'>To:</span><input class='mailer_input_field' type='text' name='to' id='tofield' value='"+recipientString+"'/></div>" +
"<div class='grey_gradient_light_inputs mailer_input_line'><span class='mailer_input_label'>Subject:</span><input class='mailer_input_field' type='text' name='subject' value='"+subject+"'/></div>" +
"<textarea name='message' class='grey_gradient_light_inputs'>"+body+"</textarea>" +
"<input type='hidden' name='users_ids' value='"+ hiddenRecipientString +"'/> " +
Expand All @@ -61,6 +61,22 @@ Class.create("AjxpMailer", {
}

this._mailerPane = $("mailer_message");

this._autocompleter = new AjxpUsersCompleter(
this._mailerPane.down('#tofield'),
null,
this._mailerPane.down('#emails_autocomplete'),
{
tmpUsersPrefix:'',
usersOnly: true,
updateUserEntryAfterCreate:null,
createUserPanel:null,
indicator: null,
minChars:parseInt(ajaxplorer.getPluginConfigs("conf").get("USERS_LIST_COMPLETE_MIN_CHARS"))
}
);


return $("mailer_message");
},

Expand Down
Expand Up @@ -78,54 +78,59 @@ Class.create("AjxpUsersCompleter", Ajax.Autocompleter, {
tmpUsersPrefix:'',
updateUserEntryAfterCreate:null,
createUserPanel:null,
usersOnly: false,
afterUpdateElement: function(element, selectedLi){
var id = Math.random();
var label = selectedLi.getAttribute("data-label");
var entryId = selectedLi.getAttribute("data-entry_id");
if(selectedLi.getAttribute("data-temporary") && pref && ! label.startsWith(pref)){
label = pref + label;
}
var li = entryTplGenerator(selectedLi.getAttribute("data-group")?true:false,
selectedLi.getAttribute("data-temporary")?true:false,
selectedLi.getAttribute("data-group")?selectedLi.getAttribute("data-group"):(entryId ? entryId : label),
label
);
if(listElement){

if(entryTplUpdater){
entryTplUpdater(li);
}
var id = Math.random();
var label = selectedLi.getAttribute("data-label");
var entryId = selectedLi.getAttribute("data-entry_id");
if(selectedLi.getAttribute("data-temporary") && pref && ! label.startsWith(pref)){
label = pref + label;
}
var li = entryTplGenerator(selectedLi.getAttribute("data-group")?true:false,
selectedLi.getAttribute("data-temporary")?true:false,
selectedLi.getAttribute("data-group")?selectedLi.getAttribute("data-group"):(entryId ? entryId : label),
label
);

if(entryTplUpdater){
entryTplUpdater(li);
}

if(selectedLi.getAttribute("data-temporary") && createUserPanel != null){
element.readOnly = true;
createUserPass.setValue(""); createUserConfirmPass.setValue("");
element.setValue(MessageHash["449"].replace("%s", label));
createUserPanel.select('div.dialogButtons>input').invoke("addClassName", "dialogButtons");
createUserPanel.select('div.dialogButtons>input').invoke("stopObserving", "click");
createUserPanel.select('div.dialogButtons>input').invoke("observe", "click", function(event){
Event.stop(event);
var close = false;
if(event.target.name == "ok"){
if( !createUserPass.value || createUserPass.value.length < ajxpBootstrap.parameters.get('password_min_length')){
alert(MessageHash[378]);
}else if(createUserPass.getValue() == createUserConfirmPass.getValue()){
li.NEW_USER_PASSWORD = createUserPass.getValue();
li.appendToList(listElement);
if(selectedLi.getAttribute("data-temporary") && createUserPanel != null){
element.readOnly = true;
createUserPass.setValue(""); createUserConfirmPass.setValue("");
element.setValue(MessageHash["449"].replace("%s", label));
createUserPanel.select('div.dialogButtons>input').invoke("addClassName", "dialogButtons");
createUserPanel.select('div.dialogButtons>input').invoke("stopObserving", "click");
createUserPanel.select('div.dialogButtons>input').invoke("observe", "click", function(event){
Event.stop(event);
var close = false;
if(event.target.name == "ok"){
if( !createUserPass.value || createUserPass.value.length < ajxpBootstrap.parameters.get('password_min_length')){
alert(MessageHash[378]);
}else if(createUserPass.getValue() == createUserConfirmPass.getValue()){
li.NEW_USER_PASSWORD = createUserPass.getValue();
li.appendToList(listElement);
close = true;
}
}else if(event.target.name.startsWith("can")){
close = true;
}
}else if(event.target.name.startsWith("can")){
close = true;
}
if(close) {
element.setValue("");
element.readOnly = false;
Effect.BlindUp('create_shared_user', {duration:0.4});
createUserPanel.select('div.dialogButtons>input').invoke("removeClassName", "dialogButtons");
}
});
Effect.BlindDown(createUserPanel, {duration:0.6, transition:Effect.Transitions.spring, afterFinish:function(){createUserPass.focus();}});
}else{
element.setValue("");
li.appendToList(listElement);
if(close) {
element.setValue("");
element.readOnly = false;
Effect.BlindUp('create_shared_user', {duration:0.4});
createUserPanel.select('div.dialogButtons>input').invoke("removeClassName", "dialogButtons");
}
});
Effect.BlindDown(createUserPanel, {duration:0.6, transition:Effect.Transitions.spring, afterFinish:function(){createUserPass.focus();}});
}else{
element.setValue("");
li.appendToList(listElement);
}

}
}
}, options);
Expand All @@ -135,19 +140,23 @@ Class.create("AjxpUsersCompleter", Ajax.Autocompleter, {
this.options.onComplete = this.onComplete.bind(this);
this.options.defaultParams = this.options.parameters || null;
this.url = this.options.url || window.ajxpServerAccessPath + "&get_action=user_list_authorized_users";
if(this.options.usersOnly){
this.url += '&users_only=true';
}


this.options.onComplete = function(transport){
var tmpElement = new Element('div');
tmpElement.update(transport.responseText);
listElement.select("div.user_entry").each(function(li){
var found = tmpElement.down('[data-label="'+li.getAttribute("data-entry_id")+'"]');
if(found) {
found.remove();
}
});
this.updateChoices(tmpElement.innerHTML);
}.bind(this);
if(listElement){
this.options.onComplete = function(transport){
var tmpElement = new Element('div');
tmpElement.update(transport.responseText);
listElement.select("div.user_entry").each(function(li){
var found = tmpElement.down('[data-label="'+li.getAttribute("data-entry_id")+'"]');
if(found) {
found.remove();
}
});
this.updateChoices(tmpElement.innerHTML);
}.bind(this);
}
if(Prototype.Browser.IE){
$(document.body).insert(update);
}
Expand Down

0 comments on commit f8b01ac

Please sign in to comment.