1/* UIxMailUserDelegationEditor.m - this file is part of SOGo
2 *
3 * Copyright (C) 2010 Inverse inc.
4 *
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
6 *
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
11 *
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING.  If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
21 */
22
23#import <Foundation/NSArray.h>
24#import <Foundation/NSString.h>
25
26#import <SOGo/SOGoUserManager.h>
27#import <Mailer/SOGoMailAccount.h>
28
29#import <SOGoUI/UIxComponent.h>
30
31@interface UIxMailUserDelegationEditor : UIxComponent
32{
33  NSArray *delegates;
34  NSString *currentDelegate;
35}
36
37- (NSArray *) delegates;
38- (void) setCurrentDelegate: (NSString *) newCurrentDelegate;
39- (NSString *) currentDelegate;
40
41@end
42
43@implementation UIxMailUserDelegationEditor
44
45- (id) init
46{
47  if ((self = [super init]))
48    {
49      delegates = nil;
50      currentDelegate = nil;
51    }
52
53  return self;
54}
55
56- (void) dealloc
57{
58  [delegates release];
59  [currentDelegate release];
60  [super dealloc];
61}
62
63- (NSArray *) delegates
64{
65  if (!delegates)
66    {
67      delegates = [[self clientObject] delegates];
68      [delegates retain];
69    }
70
71  return delegates;
72}
73
74- (void) setCurrentDelegate: (NSString *) newCurrentDelegate
75{
76  ASSIGN (currentDelegate, newCurrentDelegate);
77}
78
79- (NSString *) currentDelegate
80{
81  return currentDelegate;
82}
83
84- (NSString *) currentDelegateDisplayName
85{
86  SOGoUserManager *um;
87  NSString *s, *fullEmail;
88
89  um = [SOGoUserManager sharedUserManager];
90  s = ([currentDelegate hasPrefix: @"@"]
91       ? [currentDelegate substringFromIndex: 1]
92       : currentDelegate);
93  fullEmail = [um getFullEmailForUID: s];
94
95  return fullEmail? fullEmail : currentDelegate;
96}
97
98- (id) defaultAction
99{
100  id response;
101  SOGoMailAccount *co;
102
103  co = [self clientObject];
104  if ([[co nameInContainer] isEqualToString: @"0"])
105    response = self;
106  else
107    response = [self responseWithStatus: 403
108                              andString: @"The list of account delegates cannot be modified on secondary accounts."];
109
110  return response;
111}
112
113@end
114