(feat) added mailbox delegation support

This commit is contained in:
Ludovic Marcotte
2015-07-03 20:40:06 -04:00
parent 9225f2b908
commit 05d59df68b
6 changed files with 261 additions and 98 deletions
+25 -2
View File
@@ -627,10 +627,10 @@
{
NSString *fullName, *replyTo, *imapLogin, *imapServer, *cImapServer, *signature,
*encryption, *scheme, *action, *query, *customEmail, *defaultEmail, *sieveServer;
NSMutableDictionary *mailAccount, *identity, *mailboxes, *receipts;
NSMutableDictionary *mailAccount, *identity, *mailboxes, *receipts, *mailSettings;
NSNumber *port;
NSMutableArray *identities;
NSArray *mails;
NSArray *mails, *delegates;
NSURL *url, *cUrl;
unsigned int count, max, default_identity;
NSInteger defaultPort;
@@ -824,6 +824,29 @@
[mailAccounts addObject: mailAccount];
[mailAccount release];
/* delegates */
mailSettings = [[self userSettings] objectForKey: @"Mail"];
delegates = [mailSettings objectForKey: @"DelegateTo"];
if (!delegates)
delegates = [NSArray array];
else
{
NSMutableArray *allDelegates;
SOGoUser *delegate;
allDelegates = [NSMutableArray array];
for (count = 0; count < [delegates count]; count++)
{
delegate = [SOGoUser userWithLogin: [delegates objectAtIndex: count]];
[allDelegates addObject: [NSDictionary dictionaryWithObjectsAndKeys: [delegates objectAtIndex: count], @"uid",
[delegate cn], @"cn",
[delegate systemEmail], @"c_email", nil]];
}
delegates = allDelegates;
}
[mailAccount setObject: delegates forKey: @"delegates"];
}
- (NSArray *) mailAccounts
+62 -64
View File
@@ -1,8 +1,6 @@
/* UIxMailUserDelegationEditor.m - this file is part of SOGo
*
* Copyright (C) 2010 Inverse inc.
*
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
* Copyright (C) 2010-2015 Inverse inc.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -29,84 +27,84 @@
#import <SOGoUI/UIxComponent.h>
@interface UIxMailUserDelegationEditor : UIxComponent
{
NSArray *delegates;
NSString *currentDelegate;
}
// {
// NSArray *delegates;
// NSString *currentDelegate;
// }
- (NSArray *) delegates;
- (void) setCurrentDelegate: (NSString *) newCurrentDelegate;
- (NSString *) currentDelegate;
// - (NSArray *) delegates;
// - (void) setCurrentDelegate: (NSString *) newCurrentDelegate;
// - (NSString *) currentDelegate;
@end
@implementation UIxMailUserDelegationEditor
- (id) init
{
if ((self = [super init]))
{
delegates = nil;
currentDelegate = nil;
}
// - (id) init
// {
// if ((self = [super init]))
// {
// delegates = nil;
// currentDelegate = nil;
// }
return self;
}
// return self;
// }
- (void) dealloc
{
[delegates release];
[currentDelegate release];
[super dealloc];
}
// - (void) dealloc
// {
// [delegates release];
// [currentDelegate release];
// [super dealloc];
// }
- (NSArray *) delegates
{
if (!delegates)
{
delegates = [[self clientObject] delegates];
[delegates retain];
}
// - (NSArray *) delegates
// {
// if (!delegates)
// {
// delegates = [[self clientObject] delegates];
// [delegates retain];
// }
return delegates;
}
// return delegates;
// }
- (void) setCurrentDelegate: (NSString *) newCurrentDelegate
{
ASSIGN (currentDelegate, newCurrentDelegate);
}
// - (void) setCurrentDelegate: (NSString *) newCurrentDelegate
// {
// ASSIGN (currentDelegate, newCurrentDelegate);
// }
- (NSString *) currentDelegate
{
return currentDelegate;
}
// - (NSString *) currentDelegate
// {
// return currentDelegate;
// }
- (NSString *) currentDelegateDisplayName
{
SOGoUserManager *um;
NSString *s;
// - (NSString *) currentDelegateDisplayName
// {
// SOGoUserManager *um;
// NSString *s;
um = [SOGoUserManager sharedUserManager];
s = ([currentDelegate hasPrefix: @"@"]
? [currentDelegate substringFromIndex: 1]
: currentDelegate);
// um = [SOGoUserManager sharedUserManager];
// s = ([currentDelegate hasPrefix: @"@"]
// ? [currentDelegate substringFromIndex: 1]
// : currentDelegate);
return [um getFullEmailForUID: s];
}
// return [um getFullEmailForUID: s];
// }
- (id) defaultAction
{
id response;
SOGoMailAccount *co;
// - (id) defaultAction
// {
// id response;
// SOGoMailAccount *co;
co = [self clientObject];
if ([[co nameInContainer] isEqualToString: @"0"])
response = self;
else
response = [self responseWithStatus: 403
andString: @"The list of account delegates cannot be modified on secondary accounts."];
// co = [self clientObject];
// if ([[co nameInContainer] isEqualToString: @"0"])
// response = self;
// else
// response = [self responseWithStatus: 403
// andString: @"The list of account delegates cannot be modified on secondary accounts."];
return response;
}
// return response;
// }
@end
@@ -245,6 +245,12 @@
ng-click="newFolder(account)">
<i class="md-icon-add-circle-outline"><!-- add --></i>
</md-button>
<md-button class="iconButton"
ng-show="account.id == 0"
label:aria-label="Delegation..."
ng-click="delegate(account)">
<i class="md-icon-people"><!-- delegate --></i>
</md-button>
</div>
</md-subheader>
<md-list>
@@ -1,35 +1,57 @@
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE var:component>
<var:component xmlns="http://www.w3.org/1999/xhtml"
xmlns:var="http://www.skyrix.com/od/binding"
xmlns:const="http://www.skyrix.com/od/constant"
xmlns:uix="OGo:uix"
xmlns:label="OGo:label"
xmlns:rsrc="OGo:url"
className="UIxPageFrame"
title="title"
const:toolbar="none"
const:popup="YES">
<!DOCTYPE container>
<container
xmlns="http://www.w3.org/1999/xhtml"
xmlns:var="http://www.skyrix.com/od/binding"
xmlns:const="http://www.skyrix.com/od/constant"
xmlns:label="OGo:label"
>
<md-dialog flex="50" flex-sm="100">
<md-dialog-content>
<h2 class="md-headline"><var:string label:value="Delegation"/> - {{delegate.account.name}}</h2>
<md-card ng-repeat="user in delegate.users | orderBy:['userClass', 'displayName']"
ng-click="delegate.selectUser(user)"
ng-class="{ 'sg-collapsed': user.uid != delegate.selectedUser.uid, 'sg-expanded': user.uid == delegate.selectedUser.uid }">
<md-button>
<div layout="row" layout-align="start center" class="md-flex">
<span class="card-picture" ng-switch="user.userClass">
<div class="sg-avatar"><!-- normal-user --></div>
</span>
<div class="sg-tile-content">
<div class="sg-md-subhead-multi">{{user.cn}}</div>
<div class="sg-md-body-multi">{{user.c_email}}</div>
</div>
<md-button ng-click="delegate.removeUser(user)"
type="button"
ng-hide="user.uid != delegate.selectedUser.uid || user.$isSpecial()">
<i class="md-icon-delete"><!-- delete --></i>
</md-button>
</div>
</md-button>
</md-card>
</md-dialog-content>
<form id="delegationForm" const:href="saveDelegation">
<div class="delegation">
<div class="delegateSelector" id="delegates">
<div id="delegateSelectorButtons">
<a href="#" id="addDelegate" class="smallToolbarButton"><span>
<img rsrc:src="add-contact.gif" label:title="Add..." /></span></a>
<a href="#" id="deleteDelegate" class="smallToolbarButton"><span>
<img rsrc:src="remove-contact.gif" label:title="Remove" /></span></a>
</div>
<ul id="delegateList">
<var:foreach list="delegates" item="currentDelegate"
><li var:id="currentDelegate" class="normal-user">
<span class="userFullName"
><var:string value="currentDelegateDisplayName"
/></span
></li>
</var:foreach>
</ul>
</div>
<div class="md-actions">
<md-autocomplete
class="md-flex"
md-input-name="addUser"
md-search-text="delegate.searchText"
md-selected-item="delegate.userToAdd"
md-selected-item-change="delegate.addUser(user)"
md-items="user in delegate.userFilter(delegate.searchText)"
md-min-length="3"
md-no-cache="true"
label:md-floating-label="Add User">
<span class="md-contact-suggestion" layout="row" layout-align="space-between center">
<span class="md-contact-name"
md-highlight-text="delegate.searchText"
md-highlight-flags="^i">{{user.cn}}</span> <span class="md-contact-email"
md-highlight-text="delegate.searchText"
md-highlight-flags="^i">{{user.c_email}}</span>
</span>
</md-autocomplete>
<md-button ng-click="delegate.closeModal()"><var:string label:value="Close"/></md-button>
</div>
</form>
</var:component>
</md-dialog>
</container>
@@ -220,4 +220,48 @@
return deferred.promise;
};
/**
* @function $addDelegate
* @memberof Account.prototype
* @param {Object} user - a User object with minimal set of attributes (uid, isGroup, cn, c_email)
* @desc Remove a user from the account's delegates
* @see {@link User.$filter}
*/
Account.prototype.$addDelegate = function(user) {
var _this = this,
deferred = Account.$q.defer(),
param = {uid: user.uid};
if (!user.uid || _.indexOf(_.pluck(this.delegates, 'uid'), user.uid) > -1) {
// No UID specified or user already in delegates
deferred.resolve();
}
else {
Account.$$resource.fetch(this.id.toString(), 'addDelegate', param).then(function() {
_this.delegates.push(user);
deferred.resolve(_this.users);
}, function(data, status) {
deferred.reject(l('An error occured please try again.'));
});
}
return deferred.promise;
};
/**
* @function $removeDelegate
* @memberof Account.prototype
* @param {Object} user - a User object with minimal set of attributes (uid, isGroup, cn, c_email)
* @desc Remove a user from the account's delegates
* @return a promise of the server call to remove the user from the account's delegates
*/
Account.prototype.$removeDelegate = function(uid) {
var _this = this,
param = {uid: uid};
return Account.$$resource.fetch(this.id.toString(), 'removeDelegate', param).then(function() {
var i = _.indexOf(_.pluck(_this.delegates, 'uid'), uid);
if (i >= 0) {
_this.delegates.splice(i, 1);
}
});
};
})();
@@ -24,6 +24,76 @@
});
});
};
$scope.delegate = function(account) {
$mdDialog.show({
templateUrl: account.id + '/delegation', // UI/Templates/MailerUI/UIxMailUserDelegation.wox
controller: MailboxDelegationController,
controllerAs: 'delegate',
clickOutsideToClose: true,
escapeToClose: true,
locals: {
User: User,
account: account,
$q: $q
}
});
/**
* @ngInject
*/
MailboxDelegationController.$inject = ['$scope', '$mdDialog', 'User', 'account', '$q'];
function MailboxDelegationController($scope, $mdDialog, User, account, $q) {
var vm = this;
vm.users = account.delegates;
vm.account = account;
vm.selectedUser = null;
vm.userToAdd = '';
vm.searchText = '';
vm.userFilter = userFilter;
vm.closeModal = closeModal;
vm.removeUser = removeUser;
vm.addUser = addUser;
vm.selectUser = selectUser;
function userFilter($query) {
//return User.$filter($query, folder.$acl.users);
return User.$filter($query, account.delegates);
}
function closeModal() {
$mdDialog.hide();
}
function removeUser(user) {
account.$removeDelegate(user.uid).then(function() {
if (user.uid == vm.selectedUser.uid) {
vm.selectedUser = null;
}
}, function(data, status) {
Dialog.alert(l('Warning'), l('An error occured please try again.'))
});
}
function addUser(data) {
if (data) {
account.$addDelegate(data).then(function() {
vm.userToAdd = '';
vm.searchText = '';
}, function(error) {
Dialog.alert(l('Warning'), error);
});
}
}
function selectUser(user) {
// Check if it is a different user
if (vm.selectedUser != user) {
vm.selectedUser = user;
}
}
}
};
$scope.editFolder = function(folder) {
$scope.editMode = folder.path;
focus('mailboxName_' + folder.path);