/* UIxUserRightsEditor.m - this file is part of SOGo * * Copyright (C) 2007-2009 Inverse inc. * * Author: Wolfgang Sourdeau * * 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 * the Free Software Foundation; either version 2, or (at your option) * any later version. * * This file is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ #import #import #import #import #import #import #import #import #import #import #import #import #import "UIxUserRightsEditor.h" @implementation UIxUserRightsEditor - (id) init { if ((self = [super init])) { uid = nil; userRights = [NSMutableArray new]; defaultUserID = nil; } return self; } - (void) dealloc { [uid release]; [userRights release]; [defaultUserID release]; [super dealloc]; } - (NSString *) uid { return uid; } - (BOOL) userIsDefaultUser { if (!defaultUserID) ASSIGN (defaultUserID, [[self clientObject] defaultUserID]); return [uid isEqualToString: defaultUserID]; } - (NSString *) userDisplayName { SOGoUserManager *um; um = [SOGoUserManager sharedUserManager]; return [NSString stringWithFormat: @"%@ <%@>", [um getCNForUID: uid], [um getEmailForUID: uid]]; } - (BOOL) _initRights { BOOL response; NSString *newUID, *domain; SOGoUserManager *um; SOGoObject *clientObject; SOGoGroup *group; response = NO; newUID = [[context request] formValueForKey: @"uid"]; if ([newUID length] > 0) { if (!defaultUserID) ASSIGN (defaultUserID, [[self clientObject] defaultUserID]); um = [SOGoUserManager sharedUserManager]; if ([newUID isEqualToString: defaultUserID] || [[um getEmailForUID: newUID] length] > 0) { if (![newUID hasPrefix: @"@"]) { domain = [[context activeUser] domain]; group = [SOGoGroup groupWithIdentifier: newUID inDomain: domain]; if (group) newUID = [NSString stringWithFormat: @"@%@", newUID]; } ASSIGN (uid, newUID); clientObject = [self clientObject]; [userRights addObjectsFromArray: [clientObject aclsForUser: uid]]; 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; } - (void) sendACLAdvisoryTemplateForObject: (id) theObject { NSString *language, *pageName; SOGoUserDefaults *ud; SOGoACLAdvisory *page; WOApplication *app; ud = [[SOGoUser userWithLogin: uid roles: nil] userDefaults]; language = [ud language]; pageName = [NSString stringWithFormat: @"SOGoACL%@ModificationAdvisory", language]; app = [WOApplication application]; page = [app pageWithName: pageName inContext: context]; [page setACLObject: theObject]; [page setRecipientUID: uid]; [page send]; } - (id ) saveUserRightsAction { id response; SOGoDomainDefaults *dd; if (![self _initRights]) response = [NSException exceptionWithHTTPStatus: 403 reason: @"No such user."]; else { NSArray *o; o = [NSArray arrayWithArray: userRights]; [self updateRights]; [[self clientObject] setRoles: userRights forUser: uid]; dd = [[context activeUser] domainDefaults]; if (![o isEqualToArray: userRights] && [dd aclSendEMailNotifications]) [self sendACLAdvisoryTemplateForObject: [self clientObject]]; 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 { } - (void) updateRights { [self subclassResponsibility: _cmd]; } @end