]> err.no Git - scalable-opengroupware.org/blob - UI/Common/UIxUserRightsEditor.m
d3792a23298cb0cdd41a5f3399885e8c76cb4272
[scalable-opengroupware.org] / UI / Common / UIxUserRightsEditor.m
1 /* UIxUserRightsEditor.m - this file is part of SOGo
2  *
3  * Copyright (C) 2007 Inverse groupe conseil
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 <NGObjWeb/NSException+HTTP.h>
24 #import <NGObjWeb/WOResponse.h>
25 #import <NGObjWeb/WORequest.h>
26 #import <SoObjects/SOGo/AgenorUserManager.h>
27
28 #import "UIxUserRightsEditor.h"
29
30 @implementation UIxUserRightsEditor
31
32 - (id) init
33 {
34   if ((self = [super init]))
35     {
36       uid = nil;
37       userRights = [NSMutableArray new];
38     }
39
40   return self;
41 }
42
43 - (void) dealloc
44 {
45   [uid release];
46   [userRights release];
47   [super dealloc];
48 }
49
50 - (NSString *) uid
51 {
52   return uid;
53 }
54
55 - (NSString *) userDisplayName
56 {
57   AgenorUserManager *um;
58   
59   um = [AgenorUserManager sharedUserManager];
60
61   return [NSString stringWithFormat: @"%@ <%@>",
62                    [um getCNForUID: uid],
63                    [um getEmailForUID: uid]];
64 }
65
66 - (BOOL) _initRights
67 {
68   BOOL response;
69   NSString *newUID, *email;
70   AgenorUserManager *um;
71   SOGoObject *clientObject;
72
73   response = NO;
74
75   newUID = [[context request] formValueForKey: @"uid"];
76   if ([newUID length] > 0)
77     {
78       um = [AgenorUserManager sharedUserManager];
79       email = [um getEmailForUID: newUID];
80       if ([email length] > 0)
81         {
82           ASSIGN (uid, newUID);
83           clientObject = [self clientObject];
84           [userRights addObjectsFromArray: [clientObject aclsForUser: uid]];
85           if (![userRights count])
86             [userRights addObjectsFromArray: [clientObject defaultAclRoles]];
87           
88           response = YES;
89         }
90     }
91
92   return response;
93 }
94
95 - (id <WOActionResults>) defaultAction
96 {
97   id <WOActionResults> response;
98
99   if (![self _initRights])
100     response = [NSException exceptionWithHTTPStatus: 403
101                             reason: @"No such user."];
102   else
103     {
104       [self prepareRightsForm];
105       response = self;
106     }
107
108   return response;
109 }
110
111 - (id <WOActionResults>) saveUserRightsAction
112 {
113   id <WOActionResults> response;
114
115   if (![self _initRights])
116     response = [NSException exceptionWithHTTPStatus: 403
117                             reason: @"No such user."];
118   else
119     {
120       [self updateRights];
121       [[self clientObject] setRoles: userRights
122                            forUser: uid];
123       response = [self jsCloseWithRefreshMethod: nil];
124     }
125
126   return response;
127 }
128
129 - (void) appendRight: (NSString *) newRight
130 {
131   if (![userRights containsObject: newRight])
132     [userRights addObject: newRight];
133 }
134
135 - (void) removeRight: (NSString *) right
136 {
137   if ([userRights containsObject: right])
138     [userRights removeObject: right];
139 }
140
141 - (void) appendExclusiveRight: (NSString *) newRight
142                      fromList: (NSArray *) list
143 {
144   [userRights removeObjectsInArray: list];
145   [self appendRight: newRight];
146 }
147
148 - (void) removeAllRightsFromList: (NSArray *) list
149 {
150   [userRights removeObjectsInArray: list];
151 }
152
153 - (void) prepareRightsForm
154 {
155 }
156
157 - (void) updateRights
158 {
159   [self subclassResponsibility: _cmd];
160 }
161
162 @end