; 1e*d?Z5e i#e$id@e*dAZ6e i#e$idBfffdCZ7e i#e$idDffdEZ8e i#e$idFdGZ9e i#e$idHffdIZ:e i#e$idJfdKZ;e i#e$idLdMZ<e i#e$idNdOZ=e i#e$idPdQZ>e i#e$idRdSZ?e i#e$idTdUZ@e i#e$idVdWZAe i#e$idXdYZBe i#e$idZd[ZCe i#e$id\eDd]ZEe iFd^d_ZGe i#e$id`daZHe i#e$idbdcZIe iFdddeZJe i#e$idfdgZKe i#e$idhdiZLe i#e$idjdkZMe i#e$idldmZNe i#e$idndoZOe i#e$idpdqZPe i#e$idrdsZQe i#e$idtduZRe i#e$idvdwZSe i#e$idxdyZTe i#e$idzd{ZUe i#e$id|d}ZVe i#e$id~dZWe i#e$iddZXe i#e$iddZYe i#e$iddZZe i#e$iddZ[e i#e$iddZ\dZ]e i^ddZ_e iFddZ`e i^ddZae i#e$ibddZce i#e$iddZde i#e$iddZee i^ddZfe i^dfdZge i^dfdZhe i^deDeDeDeDdZie i^ddZje i^dfdZke i^dfdZle i^deDeDdZme i^ddZne i^ddZoe iFddZpdZqe i#e$idgghdZre i#e$idhdZse i#e$idggggdhdZte i#e$idghdZue i#e$idgggghdZve i#e$idghdZwe iFddZxe i^ddZye iFddZze iFddZ{dZ|e iFddZ}dZ~e iFddZe i#e$idhdZe i#e$iddZe i^ddZe i#e$iddZe i#e$ideDd"dZe i#e$iddZe i#e$iddZe i^dhdZe i^ddZdZdZd"Zd"Zd"gfZdZgZe i#e$iddZe i#e$iddZe i#e$iddZe i deZe i deZe i deZe i deZe i#e$iddZe i#e$iddZe i^ddZe i^ddZe i#e$idhdZe i#e$ideDhdZe i#e$iddZe i#e$iddddZe i#e$idhdZe i#e$idhdZe i^ddZe i#e$ideDeDhdZRS(s? GroupUserFolder => User folder with groups management sGroup User Folders acl_userssGroup-aware User FolderislabelsOverviewsactionsmanage_overviewsSourcessmanage_GRUFSourcessGroupss manage_groupssUserss manage_userssAudits manage_auditsdtml/GRUF_overviewsdtml/GRUF_auditsdtml/GRUF_groupssdtml/GRUF_userssdtml/GRUF_newuserssdtml/GRUF_contentssdtml/GRUF_users Manage userss user_namesssetDomainAuthenticationModes#006600s#000099s#660000swww/GRUFUsers.gifswww/GRUFGroups.gifcCs|iSdS(s user_names() => return user IDS and not user NAMES !!! Due to a Zope inconsistency, the Role.get_valid_userids return user names and not user ids - which is bad. As GRUF distinguishes names and ids, this will cause it to break, especially in the listLocalRoles form. So we change user_names() behaviour so that it will return ids and not names. N(sselfs getUserIds(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys user_namesss getUserNamesic Cs g}g}|o.x+|iD]}|i|iq Wn|od|i di jo |i|i i d|nxo|D]c}|ioqnxI|idtD]5}|o|idt|fq|i|qWqWnt|ddSdS( s Return a list of all possible user atom names in the system. Groups will be returned WITHOUT their prefix by this method. So, there might be a collision between a user name and a group name. [NOTA: This method is time-expensive !] s acl_userssGroupssprefixedsattrs%s%ss_listiN(snamess ldap_sourcess__include_users__sselfslistUserSourcesssrcsextends getUserNamess__include_groups__s_getObs objectIdssGroupss listGroupss__groups_prefixed__sldapufs _local_groupss getGroupssLDAP_GROUP_RDNsgsappends GROUP_PREFIXsunique( sselfs__include_groups__s__include_users__s__groups_prefixed__ssrcsldapufsgs ldap_sourcessnames((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getUserNamess(   s getUserIdscCs|iddSdS(s  Return a list of all possible user atom ids in the system. WARNING: Please see the id Vs. name consideration at the top of this document. So, groups will be returned WITH their prefix by this method [NOTA: This method is time-expensive !] s__groups_prefixed__iN(sselfs getUserNames(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getUserIdsssgetUsersc CsUg}g}|ox|idiiD]p}| oq,n|i}||joq,n|i ||i t i ||ddddi |q,Wn|ox|iD]}x|iD]v}| oqn|i}||joqn|i ||i t i ||d|iddi |qWqWn|SdS(sReturn a list of user and group objects. In case of some UF implementations, the returned object may only be a subset of all possible users. In other words, you CANNOT assert that len(getUsers()) equals len(getUserNames()). With cache-support UserFolders, such as LDAPUserFolder, the getUser() method will return only cached user objects instead of fetching all possible users. sGroupssisGroupis source_idiN(sretsnamess__include_groups__sselfs_getObs acl_userssgetUserssusgetIdsnamesappendsGRUFUsers GRUFGroups__of__s__include_users__slistUserSourcesssrcsgetUserSourceId(sselfs__include_groups__s__include_users__ssrcsnamesretsusnames((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetUserss4   6     @sgetUserc Cs|tjotSnd|idij otSn|o |ito\|t}|idi |}|o/t i ||ddddi|}|Sqn|ofxc|iD]Q}|i|}|o5t i ||d|iddi|}|SqqWn|o| oR|idi |}|o/t i ||ddddi|}|Sq{ntSdS(s Return the named user object or None. User have precedence over group. If name is None, getUser() will return None. XXX Have to improve perfs here s acl_userssGroupssisGroupis source_idiN(snamesNonesselfs_getObs objectIdss__include_groups__s startswiths GROUP_PREFIXsGROUP_PREFIX_LENsids _getGroupsusGRUFUsers GRUFGroups__of__srets__include_users__slistUserSourcesssrcsgetUsersgetUserSourceIds__force_group_id__( sselfsnames__include_users__s__include_groups__s__force_group_id__ssrcsretsusid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetUsers0  '  -' s getUserByIdcCsP|i|dd}| o+|tjotd|fn|}n|SdS(sOReturn the user atom corresponding to the given id. Can return groups. s__force_group_id__isInvalid user or group id: '%s'N(sselfsgetUsersidsretsdefaults_markers ValueError(sselfsidsdefaultsret((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getUserByIdMs  s getUserByNamecCsE|i|}| o&dt|f}|i||}n|SdS(s/Same as getUser() but works with a name instead of an id. [NOTA: Theorically, the id is a handle, while the name is the actual login name. But difference between a user id and a user name is unsignificant in all current User Folder implementations... except for GROUPS.] s%s%sN(sselfsgetUsersnamesusrs GROUP_PREFIXs getUserByIdsdefault(sselfsnamesdefaultsusr((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getUserByNameYs sgetPureUserNamescCs|iddSdS(s7Fetch the list of actual users from GRUFUsers. s__include_groups__iN(sselfs getUserNames(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetPureUserNamesjssgetPureUserIdscCs|iddSdS(s0Same as getUserIds() but without groups s__include_groups__iN(sselfs getUserNames(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetPureUserIdsqss getPureUserscCs|iddSdS(s,Return a list of pure user objects. s__include_groups__iN(sselfsgetUsers(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getPureUserswss getPureUsercCs'| otSn|i|ddSdS(s$Return the named user object or Nones__include_groups__iN(sidsNonesselfsgetUser(sselfsid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getPureUser}ss getGroupNamescCs|iddddSdS(s7Same as getUserNames() but without pure users. s__include_users__is__groups_prefixed__N(sselfs getUserNames(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getGroupNamesss getGroupIdscCs|iddddSdS(s7Same as getUserNames() but without pure users. s__include_users__is__groups_prefixed__iN(sselfs getUserNames(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getGroupIdsss getGroupscCs|iddSdS(s3Same as getUsers() but without pure users. s__include_users__iN(sselfsgetUsers(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getGroupsssgetGroupcCsL| otSn|it odt|f}n|i|ddSdS(s$Return the named user object or Nones%s%ss__include_users__iN(snamesNones startswiths GROUP_PREFIXsselfsgetUser(sselfsnamesprefixed((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetGroups s getGroupByIdcCsV|i|dddd}| o+|tjotd|fn|}n|SdS(s>Same as getUserById(id) but forces returning a group. s__include_users__is__force_group_id__isInvalid user: '%s'N(sselfsgetUsersidsretsdefaults_markers ValueError(sselfsidsdefaultsret((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getGroupByIds  sgetGroupByNamecCsV|i|dddd}| o+|tjotd|fn|}n|SdS(sBSame as getUserByName(name) but forces returning a group. s__include_users__is__force_group_id__sInvalid user: '%s'N(sselfsgetUsersnamesretsdefaults_markers ValueError(sselfsnamesdefaultsret((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetGroupByNames  suserFolderAddUsercKs |i||||||SdS(sAPI method for creating a new user object. Note that not all user folder implementations support dynamic creation of user objects. N(sselfs _doAddUsersnamespasswordsrolessdomainssgroupsskw(sselfsnamespasswordsrolessdomainssgroupsskw((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserFolderAddUserssuserFolderEditUsercKs |i||||||SdS(sAPI method for changing user object attributes. Note that not all user folder implementations support changing of user object attributes.N(sselfs _doChangeUsersnamespasswordsrolessdomainssgroupsskw(sselfsnamespasswordsrolessdomainssgroupsskw((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserFolderEditUserssuserFolderDelUserscCs|i|SdS(sAPI method for deleting one or more user atom objects. Note that not all user folder implementations support deletion of user objects.N(sselfs _doDelUserssnames(sselfsnames((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserFolderDelUsersssuserFolderAddGroupcKs<x|ito|t}qW|i||||SdS(s-API method for creating a new group. N( snames startswiths GROUP_PREFIXsGROUP_PREFIX_LENsselfs _doAddGroupsrolessgroupsskw(sselfsnamesrolessgroupsskw((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserFolderAddGroups suserFolderEditGroupcKs|i||d||SdS(s9API method for changing group object attributes. sgroupsN(sselfs_doChangeGroupsnamesrolessgroupsskw(sselfsnamesrolessgroupsskw((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserFolderEditGroupssuserFolderDelGroupscCs|i|SdS(sAPI method for deleting one or more group objects. Implem. note : All ids must be prefixed with 'group_', so this method ends up beeing only a filter of non-prefixed ids before calling userFolderDelUsers(). N(sselfs _doDelGroupssnames(sselfsnames((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserFolderDelGroupssssearchUsersByAttributec Cskg}xZ|iD]L}t|ido|i}|djo |i }n!|djo |i}n|}|i ||} |igi} | D]}| ||q~ q|i}|djo d} n!|djo d} n tdxb|iddD]N}t|| i}ti||d jo|i|iq q WqW|Sd S( sFReturn user ids whose 'attribute' match the specified search_term. If search_term is an empty string, behaviour depends on the underlying user folder: it may return all users, return only cached users (for LDAPUF) or return no users. This will return all users whose name contains search_term (whaterver its case). THIS METHOD MAY BE VERY EXPENSIVE ON USER FOLDER KINDS WHICH DO NOT PROVIDE A SEARCHING METHOD (ie. every UF kind except LDAPUF). 'attribute' can be 'id' or 'name' for all UF kinds, or anything else for LDAPUF. sfindUsersnamesidsgetNamesgetIds@Attribute searching is only supported for LDAPUserFolder by now.s__include_groups__iiN(sretsselfslistUserSourcesssrcshasattrsaq_bases _uid_attrsid_attrs attributes _login_attrsattrsfindUsers search_termsuserssextendsappends_[1]suslowersmethodsNotImplementedErrorsgetUserssgetattrsssstringsfindsgetId( sselfs attributes search_termssrcsattrsretsid_attrsssus_[1]smethodsusers((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyssearchUsersByAttributes2      6      ssearchUsersByNamecCs|id|SdS(sReturn user ids whose name match the specified search_term. If search_term is an empty string, behaviour depends on the underlying user folder: it may return all users, return only cached users (for LDAPUF) or return no users. This will return all users whose name contains search_term (whaterver its case). THIS METHOD MAY BE VERY EXPENSIVE ON USER FOLDER KINDS WHICH DO NOT PROVIDE A SEARCHING METHOD (ie. every UF kind except LDAPUF) snameN(sselfssearchUsersByAttributes search_term(sselfs search_term((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyssearchUsersByName$sssearchUsersByIdcCs|id|SdS(sReturn user ids whose id match the specified search_term. If search_term is an empty string, behaviour depends on the underlying user folder: it may return all users, return only cached users (for LDAPUF) or return no users. This will return all users whose name contains search_term (whaterver its case). THIS METHOD MAY BE VERY EXPENSIVE ON USER FOLDER KINDS WHICH DO NOT PROVIDE A SEARCHING METHOD (ie. every UF kind except LDAPUF) sidN(sselfssearchUsersByAttributes search_term(sselfs search_term((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyssearchUsersById/sssearchGroupsByAttributec CsWg}|i}t|ido|i}|djo |i }n!|djo |i}n|}|i ||} |igi} | D]}| ||q~ n|i}|djo d} n!|djo d} n tdx\|iD]N}t|| i}ti||djo|i|iqqW|SdS( sMReturn group ids whose 'attribute' match the specified search_term. If search_term is an empty string, behaviour depends on the underlying group folder: it may return all groups, return only cached groups (for LDAPUF) or return no groups. This will return all groups whose name contains search_term (whaterver its case). THIS METHOD MAY BE VERY EXPENSIVE ON GROUP FOLDER KINDS WHICH DO NOT PROVIDE A SEARCHING METHOD (ie. every UF kind except LDAPUF). 'attribute' can be 'id' or 'name' for all UF kinds, or anything else for LDAPUF. s findGroupsnamesidsgetNamesgetIdsAAttribute searching is only supported for LDAPGroupFolder by now.iN(sretsselfsGroupsssrcshasattrsaq_bases _uid_attrsid_attrs attributes _login_attrsattrs findGroups search_termsgroupssextendsappends_[1]suslowersmethodsNotImplementedErrors getGroupssgetattrsssstringsfindsgetId( sselfs attributes search_termssrcsattrsretsid_attrsssus_[1]sgroupssmethod((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyssearchGroupsByAttribute;s0      6       ssearchGroupsByNamecCs|id|SdS(sReturn group ids whose name match the specified search_term. If search_term is an empty string, behaviour depends on the underlying group folder: it may return all groups, return only cached groups (for LDAPUF) or return no groups. This will return all groups whose name contains search_term (whaterver its case). THIS METHOD MAY BE VERY EXPENSIVE ON GROUP FOLDER KINDS WHICH DO NOT PROVIDE A SEARCHING METHOD (ie. every UF kind except LDAPUF) snameN(sselfssearchGroupsByAttributes search_term(sselfs search_term((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyssearchGroupsByNameisssearchGroupsByIdcCs|id|SdS(sReturn group ids whose id match the specified search_term. If search_term is an empty string, behaviour depends on the underlying group folder: it may return all groups, return only cached groups (for LDAPUF) or return no groups. This will return all groups whose name contains search_term (whaterver its case). THIS METHOD MAY BE VERY EXPENSIVE ON GROUP FOLDER KINDS WHICH DO NOT PROVIDE A SEARCHING METHOD (ie. every UF kind except LDAPUF) sidN(sselfssearchGroupsByAttributes search_term(sselfs search_term((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyssearchGroupsByIdtsssetRolesOnUserscCs%x|D]}|i||qWdS(s=Set a common set of roles for a bunch of user atoms. N(suseridssusrsselfs userSetRolessroles(sselfsrolessuseridssusr((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyssetRolesOnUsersssgetUsersOfRolecCsRg}x;|iD]-}||i|jo|i|qqWt|SdS(sGets the user (and group) ids having the specified role... ...on the specified Zope object if it's not None ...on their own information if the object is None. NOTA: THIS METHOD IS VERY EXPENSIVE. XXX PERFORMANCES HAVE TO BE IMPROVED N(sretsselfs getUserIdssidsrolesgetRolesOfUsersappendstuple(sselfsrolesobjectsretsid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetUsersOfRoles sgetRolesOfUsercCs|i|iSdS(s"Alias for user.getRoles() N(sselfs getUserByIdsuseridsgetRoles(sselfsuserid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetRolesOfUserssuserFolderAddRolecCs>||iijotd|fn|ii|SdS(sZAdd a new role. The role will be appended, in fact, in GRUF's surrounding folder. sRole '%s' already existN(srolesselfs aq_parents valid_roless ValueErrors_addRole(sselfsrole((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserFolderAddRolessuserFolderDelRolescCs|ii}x0|D](}||j otd|fqqWx8|D]0}x'|i|D]}|i ||q_WqIW|ii |t SdS(sDelete roles. The removed roles will be removed from the UserFolder's users and groups as well, so this method can be very time consuming with a large number of users. s4Role '%s' is not defined on acl_users' parent folderN( sselfs aq_parentsuserdefined_rolessud_rolessrolessrs ValueErrorsgetUsersOfRolesususerRemoveRoles _delRolessNone(sselfsrolessud_rolessrsu((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserFolderDelRolesssuserFolderGetRolescCst|iiSdS(s userFolderGetRoles(self,) => tuple of strings List the roles defined at the top of GRUF's folder. This includes both user-defined roles and default roles. N(stuplesselfs aq_parents valid_roles(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserFolderGetRolesss setMemberscCs|i|i|dS(s%Set the members of the group N(sselfsgetGroupsgroupids setMemberssuserids(sselfsgroupidsuserids((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys setMembersss addMembercCs|i|i|SdS(s Add a member to a group N(sselfsgetGroupsgroupids addMembersuserid(sselfsgroupidsuserid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys addMemberss removeMembercCs|i|i|SdS(s&Remove a member from a group. N(sselfsgetGroupsgroupids removeMembersuserid(sselfsgroupidsuserid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys removeMemberss getMemberIdscCs?|i|}| otd|n|i|iSdS(sGReturn the list of member ids (groups and users) in this group sInvalid group: '%s'N(sselfsgetGroupsgroupidsms ValueErrors getMemberIds(sselfsgroupidsm((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getMemberIdss sgetUserMemberIdscCs|i|iSdS(sGReturn the list of member ids (groups and users) in this group N(sselfsgetGroupsgroupidsgetUserMemberIds(sselfsgroupid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetUserMemberIdsssgetGroupMemberIdscCs|i|iSdS(spReturn the list of member ids (groups and users) in this group XXX THIS MAY BE VERY EXPENSIVE ! N(sselfsgetGroupsgroupidsgetGroupMemberIds(sselfsgroupid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetGroupMemberIdsss hasMembercCs|i|i|SdS(sReturn true if the specified atom id is in the group. This is the contrary of IUserAtom.isInGroup(groupid). THIS CAN BE VERY EXPENSIVE N(sselfsgetGroupsgroupids hasMembersid(sselfsgroupidsid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys hasMemberss userSetRolescCs|i|d|dS(s)Change the roles of a user atom. srolesN(sselfs _updateUsersidsroles(sselfsidsroles((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys userSetRoles ss userAddRolecCsQt|i|i}||j o$|i||i|d|ndS(s&Append a role for a user atom srolesN( slistsselfsgetUsersidsgetRolessrolessrolesappends _updateUser(sselfsidsrolesroles((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys userAddRoles  suserRemoveRolecCsJt|i|}||jo$|i||i|d|ndS(sPRemove the role of a user atom. Will NOT complain if role doesn't exist srolesN(slistsselfsgetRolesOfUsersidsrolessrolesremoves _updateUser(sselfsidsrolesroles((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserRemoveRoles   suserSetPasswordcCsH|i|}| otd|fn|i|id|dS(s#Set the password of a user sInvalid pure user id: '%s'spasswordN(sselfs getPureUsersidsus ValueErrors _updateUsersgetIds newPassword(sselfsids newPasswordsu((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserSetPassword!s suserGetDomainscCs#|i|}t|iSdS(sget domains for a user N(sselfs getPureUsersidsusrstuples getDomains(sselfsidsusr((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserGetDomains+ssuserSetDomainscCs,|i|}|i|id|dS(sSet domains for a user sdomainsN(sselfs getPureUsersidsusrs _updateUsersgetIdsdomains(sselfsidsdomainssusr((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserSetDomains3ss userAddDomaincCs]|i|}t|i}||j o*ti ||i |i d|ndS(s"Append a domain to a user sdomainsN( sselfs getPureUsersidsusrslists getDomainssdomainssdomainsrolessappends _updateUsersgetId(sselfsidsdomainsusrsdomains((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys userAddDomain:s  suserRemoveDomaincCs|i|}t|i}||j otd||fnx||jot i |qIW|i |i d|dS(s$Remove a domain from a user s"User '%s' doesn't have domain '%s'sdomainsN( sselfs getPureUsersidsusrslists getDomainssdomainssdomains ValueErrorsrolessremoves _updateUsersgetId(sselfsidsdomainsusrsdomains((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserRemoveDomainDs s userSetGroupscCs|i|d|dS(s!Set the groups of a user sgroupsN(sselfs _updateUsersids groupnames(sselfsids groupnames((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys userSetGroupsPss userAddGroupcCsQt|i|i}||j o$|i||i|d|ndS(s#add a group to a user atom sgroupsN( slistsselfs getUserByIdsids getGroupssgroupss groupnamesappends _updateUser(sselfsids groupnamesgroups((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys userAddGroupVs  suserRemoveGroupcCsnt|i|i}|ito|t }n||jo$|i ||i |d|ndS(s)remove a group from a user atom. sgroupsN( slistsselfs getUserByIdsids getGroupNamessgroupss groupnames startswiths GROUP_PREFIXsGROUP_PREFIX_LENsremoves _updateUser(sselfsids groupnamesgroups((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysuserRemoveGroup_s  cCsdS(s~ __init__(self) -> initialization method We define it to prevend calling ancestor's __init__ methods. N((sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys__init__oss _post_initcCsEti}ti}|id||id|d|_dS(sy _post_init(self) => meant to be called when the object is in the Zope tree sUserssGroupss acl_usersN(s GRUFFolders GRUFUserssufs GRUFGroupssgfsselfs _setObjectsid(sselfsgfsuf((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys _post_initxs   sgetGroupPrefixcCstSdS(s group prefix N(s GROUP_PREFIX(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetGroupPrefixssgetGRUFPhysicalRootcCs|iSdS(N(sselfsgetPhysicalRoot(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetGRUFPhysicalRootss getGRUFIdcCs|iSdS(s' Alias to self.getId() N(sselfsgetId(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getGRUFIdssgetUnwrappedUsercCs/|i|i}|i|i|SdS(sR getUnwrappedUser(self, name) => user object or None This method is used to get a User object directly from the User's folder acl_users, without wrapping it with group information. This is useful for UserFolders that define additional User classes, when you want to call specific methods on these user objects. For example, LDAPUserFolder defines a 'getProperty' method that's not inherited from the standard User object. You can, then, use the getUnwrappedUser() to get the matching user and call this method. N(sselfsgetUsersnamesgetUserSourceIdssrc_ids getUserSource(sselfsnamessrc_id((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetUnwrappedUserssgetUnwrappedGroupcCs|iii|SdS(sx getUnwrappedGroup(self, name) => user object or None Same as getUnwrappedUser but for groups. N(sselfsGroupss acl_userssgetUsersname(sselfsname((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetUnwrappedGroupss authenticatecCs|i}|tjotSn|o||ijo#|i||o|Sq[tSnx_|i D]Q}|i|||}|o/t i ||ddd|i i|SqhqhWtSdS(s Pass the request along to the underlying user-related UserFolder object THIS METHOD RETURNS A USER OBJECT OR NONE, as specified in the code in AccessControl/User.py. We also check for inituser in there. sisGroupis source_idN(sselfs_emergency_users emergencysnamesNones getUserNames authenticatespasswordsrequestslistUserSourcesssrcsusGRUFUsersgetUserSourceIds__of__(sselfsnamespasswordsrequestssrcs emergencysu((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys authenticates   3s _doAddUserc Kst}t|}|i}xb|D]Z} | i | od|| f} n| |j ot d| fn|i | q%Wg|_ |i i|||||SdS(s  Create a new user. This should be implemented by subclasses to do the actual adding of a user. The 'password' will be the original input password, unencrypted. The implementation of this method is responsible for performing any needed encryption. s%s%ssInvalid group: '%s'N(s GROUP_PREFIXsprefixslistsrolessselfs getGroupIdss gruf_groupssgroupssgroups startswiths ValueErrorsappends_v_batch_userssgetDefaultUserSources _doAddUsersnamespasswordsdomainsskw( sselfsnamespasswordsrolessdomainssgroupsskws gruf_groupssprefixsgroup((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys _doAddUsers    s _doChangeUsercKs t|}t|}|i|} | i} |i } t | i t |} x`|D]X}|it odt|f}n|| j o || j o|i|qbqbWg|_| i}|i|i| ||||} | i| SdS(sj Modify an existing user. This should be implemented by subclasses to make the actual changes to a user. The 'password' will be the original input password, unencrypted. The implementation of this method is responsible for performing any needed encryption. A None password should not change it (well, we hope so) s%s%sN(slistsrolessgroupssselfsgetUsersnamesusrs getRealIdsids getGroupss cur_groupsstuplesgetRoless given_rolessgroups startswiths GROUP_PREFIXsappends_v_batch_userssgetUserSourceIdssrcs getUserSources _doChangeUserspasswordsdomainsskwsretsclearCachedGroupsAndRoles(sselfsnamespasswordsrolessdomainssgroupsskwssrcsgroups cur_groupssretsusrsids given_roles((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys _doChangeUsers$      $ s _updateUserc CsY|i|} |tjo1| i}td|}td|}nRtd|}|i}x0|D](} | |j ot d| fqrqrW|tjo | i }n|tjo| idd}nY|i}|itd|x0|D](}||j ot d|fqqWg|_|i|||||SdS( s _updateUser(self, id, password = None, roles = None, domains = None, groups = None) This one should work for users AND groups. Front-end to _doChangeUser, but with a better default value support. We guarantee that None values will let the underlying UF keep the original ones. This is not true for the password: some buggy UF implementation may not handle None password correctly :-( cCs|it S(N(sxs startswiths GROUP_PREFIX(sx((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys=scCs|ddddfjS(Ns Anonymouss AuthenticatedsShareds(sx(sx((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys>ss!Invalid or inexistant role: '%s'.s no_recurseicCsdt|fS(Ns%s%s(s GROUP_PREFIXsx(sx((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysMssInvalid group: '%s'N(sselfsgetUsersidsusrsrolessNones_original_rolessfiltersuserFolderGetRolessvrsrs ValueErrorsdomainss_original_domainssgroupss getGroupss getGroupNamessglistsextendsmapsgs_v_batch_userss _doChangeUserspassword( sselfsidspasswordsrolessdomainssgroupssgsglistsvrsrsusr((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys _updateUser-s0         s _doDelUserscCsh}xn|D]f}|i|dd}| oq n|i}|i| og||     cCs|i|io|t}n|i|dd}|tjo1|i }t d|}t d|}n|tjo|i dd}ng|_ |i|||SdS(s _updateGroup(self, name, roles = None, groups = None) Front-end to _doChangeUser, but with a better default value support. We guarantee that None values will let the underlying UF keep the original ones. This is not true for the password: some buggy UF implementation may not handle None password correctly but we do not care for Groups. group name can be prefixed or not sprefixedicCs|it S(N(sxs startswiths GROUP_PREFIX(sx((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysscCs|dddfjS(Ns Anonymouss AuthenticatedsShared(sx(sx((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysss no_recurseiN(snames startswithsselfsgetGroupPrefixsGROUP_PREFIX_LENsgetGroupsusrsrolessNones_original_rolessfiltersgroupss getGroupss_v_batch_userss_doChangeGroup(sselfsnamesrolessgroupssusr((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys _updateGroups     s _doDelGroupcCsG|i|io|t}ng|_|iii|gSdS(sDelete one user.N( snames startswithsselfsgetGroupPrefixsGROUP_PREFIX_LENs_v_batch_userssGroupss acl_userss _doDelUsers(sselfsname((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys _doDelGroups  s _doDelGroupscCs=x6|D].}|i|t oqn|i|qWdS(sDelete one or more users.N(snamessgroupsselfsgetGroupByNamesNones _doDelGroup(sselfsnamessgroup((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys _doDelGroupss sgetGRUFVersioncCsddd!}dt|fSdS(sZ getGRUFVersion(self,) => Return human-readable GRUF version as a string. s$Date: 2004/09/06 09:44:47 $iis%s / Revised %sN(srev_dates version__(sselfsrev_date((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetGRUFVersions s__None__s changeUsercCs|i|}|io |id|d|d|n|id|d|d||i do,|i i |i d|idSndS( s` changeUser(self, user, groups = [], roles = [], REQUEST = {}, ) => used in ZMI snamesgroupssrolessidsRESPONSEs/s/manage_workspaceN(sselfsgetUsersusersobjsisGroups _updateGroupsgroupssroless _updateUsersREQUESTshas_keysRESPONSEsredirects absolute_urlsgetId(sselfsusersgroupssrolessREQUESTsobj((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys changeUsers  s deleteUsercCsdS(sG deleteUser(self, user, REQUEST = {}, ) => used in ZMI N((sselfsusersREQUEST((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys deleteUsersschangeOrCreateUsersscCsd}d}|i|jo|i|id}n|i|jo|i|id}n| o| ot}g} n|} | o| ot}g} n|} g}x|D]} t i| }| oqn|td|ijoqn|o |} n:d} x0tddD]}d| tidf} q*W|i|| | f| |ihd|<d | <qWx*|D]"} |id | d |d |qW| o2|id o|ii |i!dSqn|i"d||i#t|SdS(s changeOrCreateUsers => affect roles & groups to users and/or create new users All parameters are strings or lists (NOT tuples !). NO CHECKING IS DONE. This is an utility method, it's not part of the official API. iicCs |iS(N(sxsgetId(sx((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysKssis%s%ss7ABCDEFGHJKMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789snamespasswordsidsgroupssrolessRESPONSEs /manage_userssUSER_PASSWORDSN($s del_roless del_groupssselfs reset_entrysrolessremovesgroupssNones add_roless add_groupsspasswords_lists new_userssnewsstringsstripsnamesmapsgetUserssdefault_passwordspasswordsrangesxsrandomschoices _doAddUsersappendsuserssusers _updateUsersREQUESTshas_keysRESPONSEsredirects absolute_urlssetsmanage_newusers(sselfsuserssgroupssroless new_userssdefault_passwordsREQUESTs del_roless del_groupssnews add_groupssusers add_rolesspasswordsnamespasswords_listsx((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyschangeOrCreateUsers%sR     # "s deleteUserscCs?|i||ido|ii|idSndS(s deleteUsers => explicit All parameters are strings. NO CHECKING IS DONE. This is an utility method ! sRESPONSEs /manage_usersN(sselfs _doDelUserssuserssREQUESTshas_keysRESPONSEsredirects absolute_url(sselfsuserssREQUEST((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys deleteUsersis schangeOrCreateGroupsc CsMd}d} |i|jo|i|id}n|i|jo|i|id} n| o| ot}g}n|}| o| ot}g} n|} xB|D]:} t i | } | oqn|i| |d| qWx'|D]}|i|d|d|qW|ido|ii|idSndS(s changeOrCreateGroups => affect roles to groups and/or create new groups All parameters are strings. NO CHECKING IS DONE. This is an utility method ! iisgroupssrolessRESPONSEs/manage_groupsN(s del_roless del_groupssselfs reset_entrysrolessremoves nested_groupssNones add_roless add_groupss new_groupssnewsstringsstripsnames _doAddGroupsgroupssgroups _updateGroupsREQUESTshas_keysRESPONSEsredirects absolute_url( sselfsgroupssroless nested_groupss new_groupssREQUESTsgroups add_roless del_roless add_groupss del_groupssnewsname((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyschangeOrCreateGroupsxs8    s deleteGroupscCsPx|D]}|i|qW|ido|ii|idSndS(s deleteGroups => explicit All parameters are strings. NO CHECKING IS DONE. This is an utility method ! sRESPONSEs/manage_groupsN( sgroupssgroupsselfs _doDelGroupsREQUESTshas_keysRESPONSEsredirects absolute_url(sselfsgroupssREQUESTsgroup((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys deleteGroupss sacquireLocalRolescCsAtiti| otddn|i||SdS(sD Enable or disable local role acquisition on the specified folder. If status is true, it will enable, else it will disable. Note that the user _must_ have the change_permissions permission on the folder to allow changes on it. If you want to use this code from a product, please use _acquireLocalRoles() instead: this private method won't check security on the destination folder. It's usually a bad idea to use _acquireLocalRoles() directly in your product, but, well, after all, you do what you want ! :^) snamesacquireLocalRolesN( sgetSecurityManagerscheckPermissions Permissionsschange_permissionssfolders Unauthorizedsselfs_acquireLocalRolessstatus(sselfsfoldersstatus((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysacquireLocalRoless sacquireLocalRolesUnrestrictedcCs9| o d|_n!t|dto t|_ndS(sUSame as _acquireLocalRoles() but won't perform security check on the folder. is__ac_local_roles_block__N(sstatussfolders__ac_local_roles_block__sgetattrsNone(sselfsfoldersstatus((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys_acquireLocalRoless  sisLocalRoleAcquiredcCs#t|dtodSndSdS(sKReturn true if the specified folder allows local role acquisition. s__ac_local_roles_block__iiN(sgetattrsfoldersNone(sselfsfolder((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysisLocalRoleAcquiredssgetLocalRolesForDisplaycCs>titi| otddn|i|SdS(s This is used for plone's local roles display This method returns a tuple (massagedUsername, roles, userType, actualUserName). This method is protected by the 'access content information' permission. We may change that if it's too permissive...snamesgetLocalRolesForDisplayN(sgetSecurityManagerscheckPermissions Permissionssaccess_contents_informationsobjects Unauthorizedsselfs_getLocalRolesForDisplay(sselfsobject((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetLocalRolesForDisplaysc Csg}|i} |i}x| D]}|d}}|d}d}|o\|i |p|i d||fo.|i |o|t|}nd}qnd}|i||||fq%Wt|SdS(sThis is used for plone's local roles display This method returns a tuple (massagedUsername, roles, userType, actualUserName)iisusers%s%ssgroupsunknownN(sresultsobjectsget_local_roless local_rolessselfsgetGroupPrefixsprefixsone_usersmassagedUsernamesusernamesrolessuserTypesgetGroups startswithslensappendstuple( sselfsobjectsusernamesmassagedUsernamesrolessone_usersuserTypesprefixsresults local_roles((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys_getLocalRolesForDisplays"   *sgetAllLocalRolescCs>titi| otddn|i|SdS(sgetAllLocalRoles(self, object): return a dictionnary {useratom_id: roles} of local roles defined AND herited at a certain point. This will handle lr-blocking as well. snamesgetAllLocalRolesN(sgetSecurityManagerscheckPermissions Permissionsschange_permissionssobjects Unauthorizedsselfs_getAllLocalRoles(sselfsobject((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetAllLocalRolessc Csph}t|d|}x not|do|iph}t|o |}nx\|iD]J\}}|i | oh||     cCsvtiti| otddn|i}dg|i }g}|}xdno\titi| otddn|i ||idjoPn|i}q_W|ig} t}d}x|D]}hd|<d|i<d |i<d |i<d |i<d titi|<d |i|<dh<dd<} |d7}h}|i|} xa|i|i D]J\}}x;|D]3} |i$|  oh|| st         ?  scomputeSecuritySettingsc Csh} x|D]\}} }|i|}x`|D]X\}} } }}|ddfjo|i| oh|| fh<|| return a structure that is suitable for security audit Page Template. - folders is the structure returned by getSiteTree() - actors is the structure returned by listUsersAndRoles() - permissions is ((id: permission), (id: permission), ...) - cache is passed along requests to make computing faster susersgroupiN(s usr_cachesfolderssidsdepthspathsselfsunrestrictedTraversesfoldersactorsskindsactorsdisplayshandleshtmlscacheshas_keys perm_keyssgetsusrsgetUsersgetRolesInContextsrolessrolescomputeSettings permissionsskeyssperm_key(sselfsfolderssactorss permissionsscaches perm_keysskindshandlesperm_keysrolessactorsdisplays usr_cachesdepthshtmlsusrspathsfoldersrolesid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyscomputeSecuritySettingss4"$!scomputeSettingcCsd}|i|hi||fttj o||||fSn|i| oh||fh<|| used by computeSecuritySettings to populate the cache for ROLES sroleisnamesacquires AnonymoussselectediN(skindscachesgetspathsactorsNoneshas_keysfolderspermission_settingsspss permissionssperm_keys permissionscansacquiredsps aq_parentsgetPhysicalPathsparentsselfscomputeSettingsunrestrictedTraversespermssrolesOfPermission(sselfspathsfoldersactors permissionsscachespsskindsparentsperm_keys permissionsacquiredspermsspscan((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyscomputeSettingsD+  $     s_getNextHandlecCs d|SdS(sw _getNextHandle(self, index) => utility function to get an unique handle for each legend item. s%02dN(sindex(sselfsindex((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys_getNextHandlesslistUsersAndRolescCs|i}|idd}|idd}|idd} d} d} d}g}|oNxK|i i D]6}d| }| d7} |id||||fqnWn| orxotd|iD]Q} |i| } | i}d | }| d7} |id | | ||fqWn|olxi|iD]W} |i| } d |}| i}|d7}|id | | i||fq9Wn|Sd S(s listUsersAndRoles(self,) => list of tuples This method is used by the Security Audit page. XXX HAS TO BE OPTIMIZED s display_rolesisdisplay_groupss display_userssR%02disrolecCs |iS(N(sxsgetId(sx((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys2ssU%02dsusersG%02dsgroupN(sselfsREQUESTsrequestsgets display_rolessdisplay_groupss display_userss role_indexs user_indexs group_indexsrets aq_parents valid_rolessrshandlesappendsmaps getPureUserssusgetUsersobjsasHTMLshtmls getGroupNamessgetUserNameWithoutGroupPrefix(sselfshandlesdisplay_groupss display_roless group_indexsrequestshtmlsretsrsusobjs user_indexs role_indexs display_users((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyslistUsersAndRoless@   $   $    *s getSiteTreecCsg}| o |i}n|i|i|ti|i dgx|i D]}yp|idfjowVn|it d djowVn|i o!|i|i||dnWqVqVXqVW|SdS(s| getSiteTree(self, obj=None, depth=0) => special structure This is used by the security audit page s/s acl_userssportal_iN(sretsobjsselfs aq_parentsappendsgetIdsdepthsstringsjoinsgetPhysicalPaths objectValuesssubslensisPrincipiaFolderishsextends getSiteTree(sselfsobjsdepthssubsret((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getSiteTreeEs" .  %slistAuditPermissionscCs |i}td|SdS(sV listAuditPermissions(self,) => return a list of eligible permissions cCs|dS(Nsname(sp(sp((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysisN(sselfspermission_settingsspssmap(sselfsps((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyslistAuditPermissionsds sgetDefaultPermissionscCsd}|i}|idjo d}n3x/|iD]!}|idjo d}Pq6q6W|ohdd<dd return default R & W permissions for security audit. isCMF SiteisRsViewsWsModify portal contentsChange Images and FilesN(shasPlonesselfs aq_parentsps meta_types objectValuessobj(sselfshasPlonespsobj((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetDefaultPermissionsls    s getTreeInfoc Cs|i}|i|odSnh||<|i}|i}|io t i |i dd}nd}g}x=|iddD])}|i||i|i|qWhd|<d|<d |<d |<||<|SdS( sutility methodNs/s /img_groups img_users no_recurseisnamesis_groupsicons belongs_to(susrs getUserNamesnamesdictshas_keysgetUserNameWithoutGroupPrefixsnoprefixsisGroupsis_groupsstringsjoinsselfsgetPhysicalPathsicons belongs_tos getGroupssgrpsappends getTreeInfosgetGroup( sselfsusrsdictsnamesgrpsnoprefixsis_groups belongs_tosicon((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getTreeInfos"       .stpValuesc CsQ|io|itijogSngSt|i}|tjo$d|_tit|_gSnt|i }||tjo |i }n |i }d|_h}g}g}xL|D]A}|i|||i dd o|i|iqqWx$|D]}|it||qW|id|SdS(Niis no_recursecCst|i|iS(N(scmpsxssortIdsy(sxsy((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyss(sselfs _v_no_trees_v_cache_no_treestimeslens getGroupNamessngroupssMAX_TREE_USERS_AND_GROUPSsTREE_CACHE_TIMEsgetUserssnuserss getGroupss meth_lists tree_dictstop_level_namess top_levelsusrs getTreeInfosappends getUserNamesids treeWrapperssort( sselfs meth_listsnuserssngroupss top_levelsusrstop_level_namess tree_dictsid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pystpValuess4       cCs|iSdS(N(sselfsgetId(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pystpIdscCsti|idd }|d}|djoW|td|ijo4|i d||i dd|i dSqn|i d Sd S( s manage_workspace(self, REQUEST) => Overrided to allow direct user or group traversal via the left tree view. s/is acl_userscCs |iS(N(sxsgetId(sx((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysssusernamesMANAGE_TABS_NO_BANNERs1s manage_usersmanage_overviewN( sstringssplitsREQUESTs PATH_INFOspathsusernamesmapsselfsgetUsersssetsrestrictedTraverse(sselfsREQUESTsusernamespath((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysmanage_workspaces  cCs t|i|ot||Sn|idon|idon|tjon|idtijo5t d|i }tit |f|_n|id}||jod|_ |Sn|idod|_ |Snt||SdS(so Looks for the name of a user or a group. This applies only if users list is not huge. s_smanage_icCs |iS(N(sxsgetId(sx((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys sis FORCE_USERN(shasattrsselfsaq_basesnamesgetattrs startswithsINVALID_USER_NAMESs _v_cache_treestimesmapsgetUserssunsTREE_CACHE_TIMEs _v_no_treesrequestsget(sselfsrequestsnamesun((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys__bobo_traverse__s(     slistUsersBatchescCstd|i}t|tjotSn|ig}d}t|}t t i |tt}xktd|D]Z}|t}|td}||jo|d}n|i||||||fqW||_|SdS(s listUsersBatches(self,) => return a list of (start, end) tuples. Return None if batching is not necessary cCs |iS(N(sxsgetId(sx((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys.siiN(smapsselfs getPureUserssunslensMAX_USERS_PER_PAGEsNonessortsretsidxsl_unsintsmathsceilsfloatsnbatchessrangesfirstslastsappends_v_batch_users(sselfslastsl_unsidxsnbatchessunsretsfirst((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyslistUsersBatches(s$    % sgetUsersBatchTablecCsg}d}g}x`|ipgD]K}|d o"|o|i|ng}n|i||d7}q&W|o|i|n|SdS(s listUsersBatchTable(self,) => Same a mgt screens but divided into sublists to present them into 5 columns. XXX have to merge this w/getUsersBatch to make it in one single pass iiiN(sretsidxscurrentsselfslistUsersBatchessrecsappend(sselfscurrentsrecsidxsret((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyslistUsersBatchTableEs   s getUsersBatchcCs|i o%td|i}||_n|t}|i||!}g}x5|D]-}|i |}|o|i |qWqWW|SdS(s9 getUsersBatch(self, start) => user list cCs |iS(N(sxsgetId(sx((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyscsN(sselfs_v_batch_userssmaps getPureUserssunsstartsMAX_USERS_PER_PAGEsendsidssretsidsgetUsersusrsappend(sselfsstartsendsidssretsunsusrsid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getUsersBatch]s   swww/up_arrow.gifswww/down_arrow.gifswww/up_arrow_grey.gifswww/down_arrow_grey.gifslistUserSourcescCsg}tohx|idgD]M}d|ijo4tt|idt o|i |iqmq q WnExA|idgD]-}d|ijo|i |iqqW|i d|SdS(s6 listUserSources(self, ) => Return a list of userfolder objects Only return VALID (ie containing an acl_users) user sources if all is None XXX HAS TO BE OPTIMIZED VERY MUCH! We add a check in debug mode to ensure that invalid sources won't be added to the list. s GRUFUserss acl_userss authenticatecCst|ii|iiS(N(scmpsxs aq_parentsidsy(sxsy((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyssN( srets DEBUG_MODEsselfs objectValuesssrcs objectIdssgetattrsaq_bases acl_userssNonesappendssort(sselfssrcsret((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyslistUserSources|s slistUserSourceFolderscCsHg}x'|idgD]}|i|qW|id|SdS(sO listUserSources(self, ) => Return a list of GRUFUsers objects s GRUFUserscCst|i|iS(N(scmpsxsidsy(sxsy((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyssN(sretsselfs objectValuesssrcsappendssort(sselfssrcsret((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyslistUserSourceFoldersss getUserSourcecCst||iSdS(sq getUserSource(self, id) => GRUFUsers.acl_users object. Raises if no acl_users available N(sgetattrsselfsids acl_users(sselfsid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys getUserSourcessgetUserSourceFoldercCst||SdS(sC getUserSourceFolder(self, id) => GRUFUsers object N(sgetattrsselfsid(sselfsid((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetUserSourceFolderss addUserSourcec Os|id}|oM|i|dgjo d}nt|dd}d|df}nd}tid|}|i |||i d o'|i id |i||fSnt||i|||Sd S( s addUserSource(self, factory_uri, REQUEST = {}, *args, **kw) => redirect Adds the specified user folder s GRUFUserssUsersiiis Users%02disidsRESPONSEs%s/%s/%sN(sselfs objectIdssidsssortslastsintsnext_ids GRUFFolders GRUFUserssufs _setObjectsREQUESTshas_keysRESPONSEsredirects absolute_urls factory_urisgetattrsunrestrictedTraversesargsskw( sselfs factory_urisREQUESTsargsskwslastsidssnext_idsuf((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys addUserSources  'sdeleteUserSourcecCsht|tdjo tdn|i|g|ido|ii|i dSndS(se deleteUserSource(self, id = None, REQUEST = {}) => Delete the specified user source sss8You must choose a valid source to delete and confirm it.sRESPONSEs/manage_GRUFSourcesN( stypesids ValueErrorsselfsmanage_delObjectssREQUESTshas_keysRESPONSEsredirects absolute_url(sselfsidsREQUEST((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysdeleteUserSources  sgetDefaultUserSourcecCs-|i}| o tdn|dSdS(s getDefaultUserSource(self,) => acl_users object Return default user source for user writing. XXX By now, the FIRST source is the default one. This may change in the future. s%No valid User Source to add users in.iN(sselfslistUserSourcesslsts RuntimeError(sselfslst((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysgetDefaultUserSources   slistAvailableUserSourcesc Csg}ti}g}t|io|i}n |i}x^|D]V}|o |i do,|i |d|o|i |qqK|i |qKWx|D]}|d|i joqn|oy|idto |dio"|i |d|dfwn|idtotitii|do"|i |d|dfwnWqtj oqXq|i |d|dfqWt|SdS(sR listAvailableUserSources(self, filter_permissions = 1, filter_classes = 1) => tuples (name, factory_uri) List UserFolder replacement candidates. - if filter_classes is true, return only ones which have a base UserFolder class - if filter_permissions, return only types the user has rights to add s permissionsnamesinstancesactionN(sretsgetSecurityManagersgetUsersusers meta_typesscallablesselfsall_meta_typessalls meta_typesfilter_permissionsshas_keyshas_permissionsappendstsfilter_classessgetsNones isAUserFolders class_utilitys isBaseClasss AccessControlsUsersBasicUserFoldersAttributeErrorstuple( sselfsfilter_permissionssfilter_classessalls meta_typessrets meta_typesuserst((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyslistAvailableUserSourcess: !0  smoveUserSourceUpc CsO|id}|i| p ||j otd|fn|i|}|djotd|fn|d}||djo d} nt ||d} | d}|} | djo d}nd| f}d |f}|i| ||i|| |i|||id o|ii|id Snd S( s moveUserSourceUp(self, id, REQUEST = {}) => used in management screens try to get ids as consistant as possible s GRUFUserssInvalid User Source: '%s'is!Cannot move '%s' User Source up.isUsersis Users%02ds%s_sRESPONSEs/manage_GRUFSourcesN(sselfs objectIdssidsssortsids ValueErrorsindexs src_indexs dest_indexsdest_numsintssrc_numssrc_idsdest_idstmp_ids_renameUserSourcesREQUESTshas_keysRESPONSEsredirects absolute_url( sselfsidsREQUESTs src_indexstmp_idssrc_nums dest_indexsdest_idsidssdest_numssrc_id((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysmoveUserSourceUp s.         smoveUserSourceDownc CsU|id}|i| p ||j otd|fn|i|}|t|djotd|fn|d}|djo d} nt ||d} | d}|} | djo d}nd| f}d |f}|i| ||i|| |i|||id o|ii|id Snd S( s moveUserSourceDown(self, id, REQUEST = {}) => used in management screens try to get ids as consistant as possible s GRUFUserssInvalid User Source: '%s'is!Cannot move '%s' User Source up.sUsersiis Users%02ds%s_sRESPONSEs/manage_GRUFSourcesN(sselfs objectIdssidsssortsids ValueErrorsindexs src_indexslens dest_indexsdest_numsintssrc_numssrc_idsdest_idstmp_ids_renameUserSourcesREQUESTshas_keysRESPONSEsredirects absolute_url( sselfsidsREQUESTs src_indexstmp_idssrc_nums dest_indexsdest_idsidssdest_numssrc_id((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysmoveUserSourceDownA s.         s_renameUserSourcecCsy|i|Wn/ttdddtidddnX|i|}y|i |ddWn/ttdddtidddnX|i |t |}|i ||i||d d d S( s Rename a particular sub-object. Taken fro CopySupport.manage_renameObject() code, modified to disable verifications. stitles Invalid Idsmessageisactions manage_mainsops Rename Errors set_owneriN(sselfs_checkIdsnew_ids CopyErrors MessageDialogssyssexc_infos_getObsidsobs_notifyOfCopyTos _delObjectsaq_bases_setIds _setObject(sselfsidsnew_idsob((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys_renameUserSourcem s$     sreplaceUserSourcescOs t|tdjo tdn| oVx:|idgD]&}|d|jo|d}PqAqAW| o tdqnt||}d|i jo|i dgn|i do'|i id |i||fSn|i|||Sd S( s replaceUserSource(self, id = None, new_factory = None, REQUEST = {}, *args, **kw) => perform user source replacement If new_factory is None, find it inside REQUEST (useful for ZMI screens) sss9You must choose a valid source to replace and confirm it.s source_recsids new_factorys'You must select a new User Folder type.s acl_userssRESPONSEs%s/%s/%sN(stypesids ValueErrors new_factorysREQUESTsgetsrecordsgetattrsselfsuss objectIdssmanage_delObjectsshas_keysRESPONSEsredirects absolute_urlsunrestrictedTraversesargsskw(sselfsids new_factorysREQUESTsargsskwsussrecord((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysreplaceUserSource s"   '(s__name__s __module__s__doc__s meta_typesidstitles IUserFolders__implements__sisAnObjectManagersisPrincipiaFolderishs isAUserFoldersClassSecurityInfossecuritysOFSs ObjectManagersmanage_optionss RoleManagersItems manage_mainsPageTemplateFilesglobalssmanage_overviews manage_audits manage_groupss manage_userssmanage_newuserssmanage_GRUFSourcess manage_users__ac_permissions__s user_colors group_colors role_colors ImageFilesimg_users img_groupsdeclareProtecteds Permissionss user_namess getUserNamess getUserIdssgetUserssgetUsers_markers getUserByIds getUserByNamesgetPureUserNamessgetPureUserIdss getPureUserss getPureUsers getGroupNamess getGroupIdss getGroupssgetGroups getGroupByIdsgetGroupByNamesuserFolderAddUsersuserFolderEditUsersuserFolderDelUserssuserFolderAddGroupsuserFolderEditGroupsuserFolderDelGroupsssearchUsersByAttributessearchUsersByNamessearchUsersByIdssearchGroupsByAttributessearchGroupsByNamessearchGroupsByIdssetRolesOnUserssNonesgetUsersOfRoles declarePublicsgetRolesOfUsersuserFolderAddRolesuserFolderDelRolessuserFolderGetRoless setMemberss addMembers removeMembers getMemberIdssgetUserMemberIdssgetGroupMemberIdss hasMembers userSetRoless userAddRolesuserRemoveRolesuserSetPasswordsuserGetDomainssuserSetDomainss userAddDomainsuserRemoveDomains userSetGroupss userAddGroupsuserRemoveGroups__init__sdeclarePrivates _post_initsgetGroupPrefixsgetGRUFPhysicalRootsviews getGRUFIdsgetUnwrappedUsersgetUnwrappedGroups authenticates _doAddUsers _doChangeUsers _updateUsers _doDelUserss _doAddGroups_doChangeGroups _updateGroups _doDelGroups _doDelGroupssgetGRUFVersions reset_entrys changeUsers deleteUserschangeOrCreateUserss deleteUsersschangeOrCreateGroupss deleteGroupssacquireLocalRoless_acquireLocalRolessisLocalRoleAcquiredsgetLocalRolesForDisplays_getLocalRolesForDisplaysgetAllLocalRoless_getAllLocalRolessgetPloneSecurityMatrixscomputeSecuritySettingsscomputeSettings_getNextHandleslistUsersAndRoless getSiteTreeslistAuditPermissionssgetDefaultPermissionss getTreeInfostpValuesstpIdsmanage_workspaces _v_no_trees_v_cache_no_trees _v_cache_trees__bobo_traverse__s_v_batch_userssview_management_screensslistUsersBatchesslistUsersBatchTables getUsersBatchs img_up_arrowsimg_down_arrowsimg_up_arrow_greysimg_down_arrow_greyslistUserSourcesslistUserSourceFolderss getUserSourcesgetUserSourceFolders addUserSourcesdeleteUserSourcesgetDefaultUserSourceslistAvailableUserSourcessmoveUserSourceUpsmoveUserSourceDowns_renameUserSourcesreplaceUserSource(((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysGroupUserFolderTs      # D/                ,   -                                      %    ) +    %  )       C*         #  q * 3   ,    "  &    /          , * +  s treeWrappercBsGtZdZgdZdZdZdZdZdZRS(sE treeWrapper: Wrapper around user/group objects for the tree cCs||_||d|_||d|_||d|_|i|||_ g}xF|i D]8}|||djo|it |||qeqeW|id||_ dS(s_ __init__(self, id, tree, parents = []) => wraps the user object for dtml-tree snamesiconsis_groups belongs_tocCst|i|iS(N(scmpsxssortIdsy(sxsy((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys sN(sidsselfs_idstreesnamesiconsis_groupsparentssappendspaths subobjectsskeyssgrp_ids treeWrapperssort(sselfsidstreesparentss subobjectssgrp_id((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys__init__ s    !cCs |iSdS(N(sselfsname(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pysid scCs'|iod|ifSn|iSdS(Ns__%s(sselfsis_groups_id(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pyssortId s cCs |iSdS(s% Return 'subobjects' N(sselfs subobjects(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pystpValues scCs |iSdS(N(sselfs_id(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pystpId scCs|iSdS(N(sselfstpId(sself((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pystpURL s( s__name__s __module__s__doc__s__init__sidssortIdstpValuesstpIdstpURL(((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys treeWrapper s      (6s__doc__sGlobalss MessageDialogsDTMLFiles AccessControlsClassSecurityInfos PermissionssgetSecurityManagers UnauthorizedsInitializeClasss Acquisitionsaq_basesaq_inners aq_parentsImplicits PersistentsAccessControl.Roles RoleManagersOFS.SimpleItemsItemsOFS.PropertyManagersPropertyManagersOFSs ObjectManagers SimpleItemsDateTimesApps ImageFilesProducts.PageTemplatessPageTemplateFileswebdav.CollectionswebdavsProductssossstringssysstimesmathsrandomsglobal_symbolssAccessControl.Users GRUFFoldersGRUFUsers class_utilitysinterfaces.IUserFolders IUserFolders_markersuniquesNonesmanage_addGroupUserFoldersUsersBasicUserFoldersGroupUserFolders treeWrapper('swebdavsrandoms RoleManagersDateTimes aq_parentsstrings GRUFFolders class_utilitysPageTemplateFilestimesInitializeClasssImplicitsmathsaq_innersGRUFUsers_markersGroupUserFoldersaq_bases Unauthorizeds ObjectManagersClassSecurityInfos PersistentsDTMLFilessyssOFSsProductssuniques MessageDialogs IUserFolders AccessControlsItemsgetSecurityManagers treeWrappers ImageFilesmanage_addGroupUserFoldersPropertyManagers Permissionssoss SimpleItem((sS/mnt/gmirror/ports/www/zope-groupuserfolder/work/GroupUserFolder/GroupUserFolder.pys?s^                            %b-