Coverage for src/P4OO/User.py: 86%

29 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-09-07 17:17 +0000

1###################################################################### 

2# Copyright (c)2012,2015,2024 David L. Armstrong. 

3# 

4# P4OO.User.py 

5# 

6###################################################################### 

7 

8from dataclasses import dataclass, field 

9 

10from P4OO.Client import P4OOClientSet 

11from P4OO.Change import P4OOChangeSet 

12from P4OO._SpecObj import _P4OOSpecObj 

13from P4OO._Set import _P4OOSet 

14 

15@dataclass(unsafe_hash=True) 

16class P4OOUser(_P4OOSpecObj): 

17 """ 

18 Perforce User Spec Object 

19 

20 id Required: No 

21 

22 Forcible: Yes 

23 

24 Attributes: 

25 user (str): Username of the user 

26 type (str): [service|operator|standard] Type of user 

27 fullname (str): Full name of the user 

28 email (str): Email address of the user 

29 jobview (str): Jobs to include in changelist creation 

30 password (str): P4PASSWD setting is required? 

31 authmethod (str): [`perforce`|`perforce+2fa`|`ldap`|`ldap+2fa`] 

32 reviews (str): Depot files to be reviewed by user 

33 update (datetime): Time of last update to the spec 

34 access (datetime): Time of last access of the spec 

35 

36 See Also: 

37 Perforce Helix Core Command Reference: 

38 https://www.perforce.com/manuals/cmdref/Content/CmdRef/p4_user.html 

39 """ 

40 # Subclasses must define SPECOBJ_TYPE 

41 _SPECOBJ_TYPE = 'user' 

42 

43 def listOpenedFiles(self, client=None): 

44 """ Return a P4OOFileSet of files opened by this user in the 

45 specified client workspace. 

46 """ 

47 

48 return self._runCommand('opened', user=self, client=client) 

49 

50 def listClients(self): 

51 """ 

52 Executes `p4 clients -u <self>` query 

53 

54 Returns: 

55 (P4OOClientSet): `P4OOSet` of `P4OOClient` objects owned by user 

56 

57 See Also: 

58 Perforce Helix Core Command Reference: 

59 https://www.perforce.com/manuals/cmdref/Content/CmdRef/p4_clients.html 

60 """ 

61 

62 return P4OOClientSet(_p4Conn=self._getP4Connection()).query(user=self) 

63 

64 def listChanges(self, status=None, maxresults=None): 

65 """ 

66 Executes `p4 changes -u <self> -s <status> -m <maxresults>` query 

67 

68 Args: 

69 maxresults (int, optional): Return only the first <max> results 

70 status (str, optional): ['pending, 'submitted', or 'shelved'] 

71 

72 Returns: 

73 (P4OOChangeSet): `P4OOSet` of `P4OOChange` objects matching query 

74 parameters 

75 

76 See Also: 

77 Perforce Helix Core Command Reference: 

78 https://www.perforce.com/manuals/cmdref/Content/CmdRef/p4_changes.html 

79 """ 

80 

81 changeSet = P4OOChangeSet(_p4Conn=self._getP4Connection()) 

82 return changeSet.query(user=self, status=status, maxresults=maxresults) 

83 

84 def deleteWithVengeance(self): 

85 """ 

86 Performs all operations necessary to remove a user. 

87 

88 - Revert open files in all clients 

89 - Remove all pending changes 

90 - Remove all clients 

91 - Remove user spec 

92 

93 Returns: 

94 (Boolean): Result from _P4OOSpecObj.deleteSpec() 

95 

96 See Also: 

97 Perforce Helix Core Knowledge Base: 

98 https://portal.perforce.com/s/article/2543 

99 """ 

100 

101 # First reopen/revert files in all clients to be sure we can 

102 # remove any changes 

103 clients = self.listClients() 

104 for client in clients: 

105 client.revertOpenedFiles() 

106 

107 # Next remove all Pending changes now that the files have been 

108 # reopened 

109 changes = self.listChanges(status="pending") 

110 for change in changes: 

111 change.deleteWithVengeance() 

112 

113 # Next remove all of user's clients to cleanup db.have table 

114 # where possible. 

115 for client in clients: 

116 client.deleteWithVengeance() 

117 

118 # Finally, remove the user spec 

119 return self.deleteSpec(force=True) 

120 

121 

122@dataclass 

123class P4OOUserSet(_P4OOSet): 

124 """ `P4OOSet` of `P4OOUser` objects """ 

125 

126 def query(self, allusers: bool=None, longoutput: bool=None, 

127 maxresults: int=None, users: str=None, **kwargs): 

128 """ 

129 Executes `p4 users` query 

130 

131 Args: 

132 allusers (bool, optional): include service users in results 

133 longoutput (bool, optional): include the full changelist 

134 descriptions 

135 maxresults (int, optional): Return only the first [max] results 

136 users (P4OOUserSet | P4OOUserFile | str, optional): The set of 

137 users to query 

138 

139 Returns: 

140 (P4OOUserSet): `P4OOSet` of `P4OOUser` objects matching query 

141 parameters 

142 

143 See Also: 

144 Perforce Helix Core Command Reference: 

145 https://www.perforce.com/manuals/cmdref/Content/CmdRef/p4_users.html 

146 """ 

147 

148 return self._query(setObjType='users', allusers=allusers, 

149 longoutput=longoutput, maxresults=maxresults, 

150 users=users, **kwargs)