From 14f0b85276333fb8963b0c14e4149ed2fa90149d Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 24 Apr 2007 22:49:38 +0000 Subject: [PATCH] Monotone-Parent: d3ba36ba8bfc76739a9e1820c3fe106f3e68d71a Monotone-Revision: 4fa23faeb7b6dfed2046ea79c364ca3e961e3d3c Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-04-24T22:49:38 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 15 ++++ UI/Common/UIxUserRightsEditor.h | 21 +++++ UI/Common/UIxUserRightsEditor.m | 136 ++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+) diff --git a/ChangeLog b/ChangeLog index ac07e75b8..b85807a10 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2007-04-24 Wolfgang Sourdeau + * UI/Common/UIxUserRightsEditor.m ([UIxUserRightsEditor -defaultAction]) + ([UIxUserRightsEditor -saveUserRightsAction]): new action methods + which should never be overriden. + ([UIxUserRightsEditor -appendRight:newRight]) + ([UIxUserRightsEditor -removeRight:right]) + ([UIxUserRightsEditor -appendExclusiveRight:newRightfromList:list]) + ([UIxUserRightsEditor -removeAllRightsFromList:list]): new utility + methods that can be used by the subclasses. + ([UIxUserRightsEditor -prepareRightsForm]): new method that should + mandatorily be overriden to prepare the elements of the subclassed + form. + ([UIxUserRightsEditor -updateRights]): new method that should + mandatorily be overriden to update the user rights from the + elements of the subclassed form. + * UI/Common/UIxAclEditor.m ([UIxAclEditor -_prepareUsers]): we check if the uid is already listed before adding it to our array. This is because the acl table can contain more than one record per diff --git a/UI/Common/UIxUserRightsEditor.h b/UI/Common/UIxUserRightsEditor.h index 0ab1a52f6..35cfe1568 100644 --- a/UI/Common/UIxUserRightsEditor.h +++ b/UI/Common/UIxUserRightsEditor.h @@ -25,7 +25,28 @@ #import +@class NSMutableArray; +@class NSString; + +@protocol WOActionResults; + @interface UIxUserRightsEditor : UIxComponent +{ + NSMutableArray *userRights; + NSString *uid; +} + +- (NSString *) userDisplayName; +- (NSString *) uid; + +- (void) appendRight: (NSString *) newRight; +- (void) appendExclusiveRight: (NSString *) newRight + fromList: (NSArray *) list; +- (void) removeRight: (NSString *) right; +- (void) removeAllRightsFromList: (NSArray *) list; + +- (void) prepareRightsForm; +- (void) updateRights; @end diff --git a/UI/Common/UIxUserRightsEditor.m b/UI/Common/UIxUserRightsEditor.m index 489d2f3d8..9eaa7614f 100644 --- a/UI/Common/UIxUserRightsEditor.m +++ b/UI/Common/UIxUserRightsEditor.m @@ -20,8 +20,144 @@ * Boston, MA 02111-1307, USA. */ +#import +#import +#import +#import + #import "UIxUserRightsEditor.h" @implementation UIxUserRightsEditor +- (id) init +{ + if ((self = [super init])) + { + uid = nil; + userRights = [NSMutableArray new]; + } + + return self; +} + +- (void) dealloc +{ + [uid release]; + [userRights release]; + [super dealloc]; +} + +- (NSString *) uid +{ + return uid; +} + +- (NSString *) userDisplayName +{ + AgenorUserManager *um; + + um = [AgenorUserManager sharedUserManager]; + + return [NSString stringWithFormat: @"%@ <%@>", + [um getCNForUID: uid], + [um getEmailForUID: uid]]; +} + +- (BOOL) _initRights +{ + BOOL response; + NSString *newUID, *email; + AgenorUserManager *um; + SOGoObject *clientObject; + + response = NO; + + newUID = [[context request] formValueForKey: @"uid"]; + if ([newUID length] > 0) + { + um = [AgenorUserManager sharedUserManager]; + email = [um getEmailForUID: newUID]; + if ([email length] > 0) + { + ASSIGN (uid, newUID); + clientObject = [self clientObject]; + [userRights addObjectsFromArray: [clientObject aclsForUser: uid]]; + if (![userRights count]) + [userRights addObjectsFromArray: [clientObject defaultAclRoles]]; + + response = YES; + } + } + + return response; +} + +- (id ) defaultAction +{ + id response; + + if (![self _initRights]) + response = [NSException exceptionWithHTTPStatus: 403 + reason: @"No such user."]; + else + { + [self prepareRightsForm]; + response = self; + } + + return response; +} + +- (id ) saveUserRightsAction +{ + id response; + + if (![self _initRights]) + response = [NSException exceptionWithHTTPStatus: 403 + reason: @"No such user."]; + else + { + [self updateRights]; + [[self clientObject] setRoles: userRights + forUser: uid]; + response = [self jsCloseWithRefreshMethod: nil]; + } + + return response; +} + +- (void) appendRight: (NSString *) newRight +{ + if (![userRights containsObject: newRight]) + [userRights addObject: newRight]; +} + +- (void) removeRight: (NSString *) right +{ + if ([userRights containsObject: right]) + [userRights removeObject: right]; +} + +- (void) appendExclusiveRight: (NSString *) newRight + fromList: (NSArray *) list +{ + [userRights removeObjectsInArray: list]; + [self appendRight: newRight]; +} + +- (void) removeAllRightsFromList: (NSArray *) list +{ + [userRights removeObjectsInArray: list]; +} + +- (void) prepareRightsForm +{ + [self subclassResponsibility: _cmd]; +} + +- (void) updateRights +{ + [self subclassResponsibility: _cmd]; +} + @end