1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wiki.user.internal; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collection; |
24 |
|
import java.util.Date; |
25 |
|
import java.util.List; |
26 |
|
|
27 |
|
import javax.inject.Inject; |
28 |
|
import javax.inject.Provider; |
29 |
|
import javax.inject.Singleton; |
30 |
|
|
31 |
|
import org.apache.commons.lang3.StringUtils; |
32 |
|
import org.xwiki.component.annotation.Component; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
35 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
36 |
|
import org.xwiki.wiki.descriptor.WikiDescriptor; |
37 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
38 |
|
import org.xwiki.wiki.manager.WikiManagerException; |
39 |
|
import org.xwiki.wiki.user.MemberCandidacy; |
40 |
|
import org.xwiki.wiki.user.MembershipType; |
41 |
|
import org.xwiki.wiki.user.UserScope; |
42 |
|
import org.xwiki.wiki.user.WikiUserConfiguration; |
43 |
|
import org.xwiki.wiki.user.WikiUserManager; |
44 |
|
import org.xwiki.wiki.user.WikiUserManagerException; |
45 |
|
|
46 |
|
import com.xpn.xwiki.XWiki; |
47 |
|
import com.xpn.xwiki.XWikiContext; |
48 |
|
import com.xpn.xwiki.XWikiException; |
49 |
|
import com.xpn.xwiki.doc.XWikiDocument; |
50 |
|
import com.xpn.xwiki.objects.BaseObject; |
51 |
|
|
52 |
|
|
53 |
|
@link |
54 |
|
|
55 |
|
@version |
56 |
|
@since |
57 |
|
|
58 |
|
@Component |
59 |
|
@Singleton |
|
|
| 12% |
Uncovered Elements: 264 (300) |
Complexity: 65 |
Complexity Density: 0.29 |
|
60 |
|
public class DefaultWikiUserManager implements WikiUserManager |
61 |
|
{ |
62 |
|
private static final LocalDocumentReference GROUPCLASS_REFERENCE = new LocalDocumentReference(XWiki.SYSTEM_SPACE, |
63 |
|
"XWikiGroups"); |
64 |
|
|
65 |
|
private static final String GROUP_CLASS_MEMBER_FIELD = "member"; |
66 |
|
|
67 |
|
@Inject |
68 |
|
private WikiDescriptorManager wikiDescriptorManager; |
69 |
|
|
70 |
|
@Inject |
71 |
|
private WikiUserConfigurationHelper wikiUserConfigurationHelper; |
72 |
|
|
73 |
|
@Inject |
74 |
|
private EntityReferenceSerializer<String> documentReferenceSerializer; |
75 |
|
|
76 |
|
@Inject |
77 |
|
private Provider<XWikiContext> xcontextProvider; |
78 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
79 |
60 |
@Override... |
80 |
|
public UserScope getUserScope(String wikiId) throws WikiUserManagerException |
81 |
|
{ |
82 |
60 |
return wikiUserConfigurationHelper.getConfiguration(wikiId).getUserScope(); |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
85 |
3 |
@Override... |
86 |
|
public void setUserScope(String wikiId, UserScope scope) throws WikiUserManagerException |
87 |
|
{ |
88 |
3 |
WikiUserConfiguration configuration = wikiUserConfigurationHelper.getConfiguration(wikiId); |
89 |
3 |
configuration.setUserScope(scope); |
90 |
3 |
wikiUserConfigurationHelper.saveConfiguration(configuration, wikiId); |
91 |
|
} |
92 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
24 |
@Override... |
94 |
|
public MembershipType getMembershipType(String wikiId) throws WikiUserManagerException |
95 |
|
{ |
96 |
24 |
return wikiUserConfigurationHelper.getConfiguration(wikiId).getMembershipType(); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
99 |
3 |
@Override... |
100 |
|
public void setMembershipType(String wikiId, MembershipType type) throws WikiUserManagerException |
101 |
|
{ |
102 |
3 |
WikiUserConfiguration configuration = wikiUserConfigurationHelper.getConfiguration(wikiId); |
103 |
3 |
configuration.setMembershipType(type); |
104 |
3 |
wikiUserConfigurationHelper.saveConfiguration(configuration, wikiId); |
105 |
|
} |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
107 |
0 |
@Override... |
108 |
|
public Collection<String> getLocalUsers(String wikiId) throws WikiUserManagerException |
109 |
|
{ |
110 |
|
|
111 |
0 |
return null; |
112 |
|
} |
113 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
114 |
24 |
private XWikiDocument getMembersGroupDocument(String wikiId) throws WikiUserManagerException... |
115 |
|
{ |
116 |
|
|
117 |
24 |
DocumentReference memberGroupReference = new DocumentReference(wikiId, XWiki.SYSTEM_SPACE, "XWikiAllGroup"); |
118 |
|
|
119 |
|
|
120 |
24 |
try { |
121 |
24 |
XWikiContext xcontext = xcontextProvider.get(); |
122 |
24 |
XWiki xwiki = xcontext.getWiki(); |
123 |
24 |
return xwiki.getDocument(memberGroupReference, xcontext); |
124 |
|
} catch (XWikiException e) { |
125 |
0 |
throw new WikiUserManagerException(String.format("Fail to load the member group document [%s].", |
126 |
|
memberGroupReference.toString()), e); |
127 |
|
} |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
130 |
0 |
private void saveGroupDocument(XWikiDocument document, String message) throws WikiUserManagerException {... |
131 |
|
|
132 |
0 |
XWikiContext xcontext = xcontextProvider.get(); |
133 |
0 |
XWiki xwiki = xcontext.getWiki(); |
134 |
|
|
135 |
|
|
136 |
0 |
document.setHidden(true); |
137 |
|
|
138 |
|
|
139 |
0 |
if (document.getCreatorReference() == null) { |
140 |
0 |
document.setCreatorReference(xcontext.getUserReference()); |
141 |
|
} |
142 |
|
|
143 |
0 |
if (document.getAuthorReference() == null) { |
144 |
0 |
document.setAuthorReference(xcontext.getUserReference()); |
145 |
|
} |
146 |
|
|
147 |
|
|
148 |
0 |
try { |
149 |
0 |
xwiki.saveDocument(document, message, xcontext); |
150 |
|
} catch (XWikiException e) { |
151 |
0 |
throw new WikiUserManagerException("Fail to save the member group", e); |
152 |
|
} |
153 |
|
} |
154 |
|
|
|
|
| 71.4% |
Uncovered Elements: 6 (21) |
Complexity: 6 |
Complexity Density: 0.4 |
|
155 |
24 |
@Override... |
156 |
|
public Collection<String> getMembers(String wikiId) throws WikiUserManagerException |
157 |
|
{ |
158 |
24 |
List<String> members = new ArrayList<>(); |
159 |
|
|
160 |
24 |
try { |
161 |
|
|
162 |
24 |
WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId); |
163 |
|
|
164 |
24 |
members.add(descriptor.getOwnerId()); |
165 |
|
} catch (WikiManagerException e) { |
166 |
0 |
throw new WikiUserManagerException(String.format("Failed to get the descriptor for [%s]", wikiId), e); |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
24 |
XWikiDocument groupDoc = getMembersGroupDocument(wikiId); |
171 |
24 |
List<BaseObject> memberObjects = groupDoc.getXObjects(GROUPCLASS_REFERENCE); |
172 |
24 |
if (memberObjects != null) { |
173 |
24 |
for (BaseObject object : memberObjects) { |
174 |
24 |
if (object == null) { |
175 |
0 |
continue; |
176 |
|
} |
177 |
24 |
String member = object.getStringValue(GROUP_CLASS_MEMBER_FIELD); |
178 |
24 |
if (!member.isEmpty() && !members.contains(member)) { |
179 |
0 |
members.add(member); |
180 |
|
} |
181 |
|
} |
182 |
|
} |
183 |
|
|
184 |
24 |
return members; |
185 |
|
} |
186 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
187 |
24 |
@Override... |
188 |
|
public boolean isMember(String userId, String wikiId) throws WikiUserManagerException |
189 |
|
{ |
190 |
24 |
return getMembers(wikiId).contains(userId); |
191 |
|
} |
192 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
193 |
0 |
private void addMemberObject(XWikiDocument groupDoc, String userId)... |
194 |
|
throws WikiUserManagerException |
195 |
|
{ |
196 |
0 |
try { |
197 |
0 |
XWikiContext xcontext = xcontextProvider.get(); |
198 |
0 |
int objectNumber = groupDoc.createXObject(GROUPCLASS_REFERENCE, xcontext); |
199 |
0 |
BaseObject object = groupDoc.getXObject(GROUPCLASS_REFERENCE, objectNumber); |
200 |
0 |
object.set(GROUP_CLASS_MEMBER_FIELD, userId, xcontext); |
201 |
|
} catch (XWikiException e) { |
202 |
0 |
throw new WikiUserManagerException("Fail to add a member to the group", e); |
203 |
|
} |
204 |
|
} |
205 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
206 |
0 |
@Override... |
207 |
|
public void addMember(String userId, String wikiId) throws WikiUserManagerException |
208 |
|
{ |
209 |
0 |
Collection<String> members = getMembers(wikiId); |
210 |
0 |
if (members.contains(userId)) { |
211 |
|
|
212 |
0 |
return; |
213 |
|
} |
214 |
|
|
215 |
|
|
216 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(wikiId); |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
0 |
List<BaseObject> memberObjects = groupDoc.getXObjects(GROUPCLASS_REFERENCE); |
221 |
0 |
if (memberObjects == null || memberObjects.isEmpty()) { |
222 |
0 |
addMemberObject(groupDoc, ""); |
223 |
|
} |
224 |
|
|
225 |
|
|
226 |
0 |
addMemberObject(groupDoc, userId); |
227 |
|
|
228 |
|
|
229 |
0 |
saveGroupDocument(groupDoc, String.format("Add [%s] to the group.", userId)); |
230 |
|
} |
231 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
232 |
0 |
@Override... |
233 |
|
public void addMembers(Collection<String> userIds, String wikiId) throws WikiUserManagerException |
234 |
|
{ |
235 |
0 |
Collection<String> members = getMembers(wikiId); |
236 |
|
|
237 |
|
|
238 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(wikiId); |
239 |
|
|
240 |
|
|
241 |
0 |
List<BaseObject> memberObjects = groupDoc.getXObjects(GROUPCLASS_REFERENCE); |
242 |
0 |
if (memberObjects == null || memberObjects.isEmpty()) { |
243 |
0 |
addMemberObject(groupDoc, ""); |
244 |
|
} |
245 |
|
|
246 |
|
|
247 |
0 |
for (String userId : userIds) { |
248 |
0 |
if (!members.contains(userId)) { |
249 |
|
|
250 |
0 |
addMemberObject(groupDoc, userId); |
251 |
|
} |
252 |
|
} |
253 |
|
|
254 |
|
|
255 |
0 |
saveGroupDocument(groupDoc, "Add members to the group."); |
256 |
|
} |
257 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
258 |
0 |
@Override... |
259 |
|
public void removeMember(String userId, String wikiId) throws WikiUserManagerException |
260 |
|
{ |
261 |
|
|
262 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(wikiId); |
263 |
|
|
264 |
|
|
265 |
0 |
List<BaseObject> objects = groupDoc.getXObjects(GROUPCLASS_REFERENCE); |
266 |
0 |
if (objects != null) { |
267 |
|
|
268 |
|
|
269 |
0 |
List<BaseObject> objectsToRemove = new ArrayList<>(); |
270 |
0 |
for (BaseObject object : objects) { |
271 |
0 |
if (object == null) { |
272 |
0 |
continue; |
273 |
|
} |
274 |
0 |
String member = object.getStringValue(GROUP_CLASS_MEMBER_FIELD); |
275 |
0 |
if (userId.equals(member)) { |
276 |
0 |
objectsToRemove.add(object); |
277 |
|
} |
278 |
|
} |
279 |
|
|
280 |
|
|
281 |
0 |
for (BaseObject object : objectsToRemove) { |
282 |
0 |
groupDoc.removeXObject(object); |
283 |
|
} |
284 |
|
|
285 |
|
|
286 |
0 |
saveGroupDocument(groupDoc, String.format("Remove [%s] from the group.", userId)); |
287 |
|
} |
288 |
|
} |
289 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 4 |
Complexity Density: 0.29 |
|
290 |
0 |
@Override... |
291 |
|
public void removeMembers(Collection<String> userIds, String wikiId) throws WikiUserManagerException |
292 |
|
{ |
293 |
|
|
294 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(wikiId); |
295 |
|
|
296 |
|
|
297 |
0 |
List<BaseObject> objects = groupDoc.getXObjects(GROUPCLASS_REFERENCE); |
298 |
0 |
if (objects != null) { |
299 |
|
|
300 |
|
|
301 |
0 |
List<BaseObject> objectsToRemove = new ArrayList<>(); |
302 |
0 |
for (String userId: userIds) { |
303 |
0 |
for (BaseObject object : objects) { |
304 |
0 |
if (object == null) { |
305 |
0 |
continue; |
306 |
|
} |
307 |
0 |
String member = object.getStringValue(GROUP_CLASS_MEMBER_FIELD); |
308 |
0 |
if (userId.equals(member)) { |
309 |
0 |
objectsToRemove.add(object); |
310 |
|
} |
311 |
|
} |
312 |
|
} |
313 |
|
|
314 |
|
|
315 |
0 |
for (BaseObject object : objectsToRemove) { |
316 |
0 |
groupDoc.removeXObject(object); |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
0 |
saveGroupDocument(groupDoc, "Remove some users from the group."); |
321 |
|
} |
322 |
|
} |
323 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
|
324 |
0 |
private MemberCandidacy readCandidacyFromObject(BaseObject object, String wikiId)... |
325 |
|
{ |
326 |
0 |
MemberCandidacy candidacy = new MemberCandidacy(); |
327 |
|
|
328 |
0 |
candidacy.setId(object.getNumber()); |
329 |
0 |
candidacy.setWikiId(wikiId); |
330 |
0 |
candidacy.setUserId(object.getStringValue(WikiCandidateMemberClassInitializer.FIELD_USER)); |
331 |
0 |
candidacy.setUserComment(object.getLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT)); |
332 |
0 |
candidacy.setAdminId(object.getStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN)); |
333 |
0 |
candidacy.setAdminComment(object.getLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT)); |
334 |
0 |
candidacy.setAdminPrivateComment(object.getLargeStringValue( |
335 |
|
WikiCandidateMemberClassInitializer.FIELD_ADMIN_PRIVATE_COMMENT)); |
336 |
0 |
candidacy.setStatus( |
337 |
|
MemberCandidacy.Status.valueOf( |
338 |
|
object.getStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS).toUpperCase())); |
339 |
0 |
candidacy.setType( |
340 |
|
MemberCandidacy.CandidateType.valueOf( |
341 |
|
object.getStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE).toUpperCase()) |
342 |
|
); |
343 |
0 |
candidacy.setDateOfCreation(object.getDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CREATION)); |
344 |
0 |
candidacy.setDateOfCreation(object.getDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE)); |
345 |
|
|
346 |
0 |
return candidacy; |
347 |
|
} |
348 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
349 |
0 |
private Collection<MemberCandidacy> getAllMemberCandidacies(String wikiId, MemberCandidacy.CandidateType type)... |
350 |
|
throws WikiUserManagerException |
351 |
|
{ |
352 |
|
|
353 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(wikiId); |
354 |
|
|
355 |
|
|
356 |
0 |
Collection<MemberCandidacy> candidacies = new ArrayList<>(); |
357 |
0 |
String typeString = type.name().toLowerCase(); |
358 |
0 |
List<BaseObject> candidacyObjects = groupDoc.getXObjects(WikiCandidateMemberClassInitializer.REFERENCE); |
359 |
0 |
if (candidacyObjects != null) { |
360 |
0 |
for (BaseObject object : candidacyObjects) { |
361 |
0 |
if (object != null |
362 |
|
&& object.getStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE).equals(typeString)) { |
363 |
0 |
candidacies.add(readCandidacyFromObject(object, wikiId)); |
364 |
|
} |
365 |
|
} |
366 |
|
} |
367 |
|
|
368 |
0 |
return candidacies; |
369 |
|
} |
370 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
371 |
0 |
@Override... |
372 |
|
public Collection<MemberCandidacy> getAllInvitations(String wikiId) throws WikiUserManagerException |
373 |
|
{ |
374 |
0 |
return getAllMemberCandidacies(wikiId, MemberCandidacy.CandidateType.INVITATION); |
375 |
|
} |
376 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
377 |
0 |
@Override... |
378 |
|
public Collection<MemberCandidacy> getAllRequests(String wikiId) throws WikiUserManagerException |
379 |
|
{ |
380 |
0 |
return getAllMemberCandidacies(wikiId, MemberCandidacy.CandidateType.REQUEST); |
381 |
|
} |
382 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
383 |
0 |
@Override... |
384 |
|
public boolean hasPendingInvitation(DocumentReference user, String wikiId) throws WikiUserManagerException |
385 |
|
{ |
386 |
0 |
Collection<MemberCandidacy> invitations = getAllInvitations(wikiId); |
387 |
0 |
if (invitations != null) { |
388 |
0 |
String userId = documentReferenceSerializer.serialize(user); |
389 |
0 |
for (MemberCandidacy invitation : invitations) { |
390 |
0 |
if (StringUtils.equals(invitation.getUserId(), userId) |
391 |
|
&& invitation.getStatus() == MemberCandidacy.Status.PENDING) { |
392 |
0 |
return true; |
393 |
|
} |
394 |
|
} |
395 |
|
} |
396 |
|
|
397 |
0 |
return false; |
398 |
|
} |
399 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 4 |
Complexity Density: 0.57 |
|
400 |
0 |
@Override... |
401 |
|
public boolean hasPendingRequest(DocumentReference user, String wikiId) throws WikiUserManagerException |
402 |
|
{ |
403 |
0 |
Collection<MemberCandidacy> requests = getAllRequests(wikiId); |
404 |
0 |
if (requests != null) { |
405 |
0 |
String userId = documentReferenceSerializer.serialize(user); |
406 |
0 |
for (MemberCandidacy request : requests) { |
407 |
0 |
if (StringUtils.equals(request.getUserId(), userId) |
408 |
|
&& request.getStatus() == MemberCandidacy.Status.PENDING) { |
409 |
0 |
return true; |
410 |
|
} |
411 |
|
} |
412 |
|
} |
413 |
|
|
414 |
0 |
return false; |
415 |
|
} |
416 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
417 |
0 |
@Override... |
418 |
|
public MemberCandidacy getCandidacy(String wikiId, int candidacyId) throws WikiUserManagerException |
419 |
|
{ |
420 |
|
|
421 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(wikiId); |
422 |
|
|
423 |
|
|
424 |
0 |
BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, candidacyId); |
425 |
0 |
return readCandidacyFromObject(object, wikiId); |
426 |
|
} |
427 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 2 |
Complexity Density: 0.12 |
|
428 |
0 |
@Override... |
429 |
|
public MemberCandidacy askToJoin(String userId, String wikiId, String message) |
430 |
|
throws WikiUserManagerException |
431 |
|
{ |
432 |
0 |
MemberCandidacy candidacy = new MemberCandidacy(wikiId, userId, MemberCandidacy.CandidateType.REQUEST); |
433 |
0 |
candidacy.setUserComment(message); |
434 |
|
|
435 |
|
|
436 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(wikiId); |
437 |
|
|
438 |
|
|
439 |
0 |
XWikiContext xcontext = xcontextProvider.get(); |
440 |
0 |
try { |
441 |
0 |
int objectNumber = groupDoc.createXObject(WikiCandidateMemberClassInitializer.REFERENCE, xcontext); |
442 |
0 |
candidacy.setId(objectNumber); |
443 |
0 |
BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, objectNumber); |
444 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_USER, candidacy.getUserId()); |
445 |
0 |
object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, |
446 |
|
candidacy.getUserComment()); |
447 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, |
448 |
|
candidacy.getStatus().name().toLowerCase()); |
449 |
0 |
object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CREATION, |
450 |
|
candidacy.getDateOfCreation()); |
451 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE, |
452 |
|
candidacy.getType().name().toLowerCase()); |
453 |
|
} catch (XWikiException e) { |
454 |
0 |
throw new WikiUserManagerException("Failed to create a new join request.", e); |
455 |
|
} |
456 |
|
|
457 |
|
|
458 |
0 |
saveGroupDocument(groupDoc, String.format("[%s] asks to join the wiki.", userId)); |
459 |
|
|
460 |
0 |
return candidacy; |
461 |
|
} |
462 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
463 |
0 |
@Override... |
464 |
|
public void join(String userId, String wikiId) throws WikiUserManagerException |
465 |
|
{ |
466 |
|
|
467 |
0 |
if (!wikiUserConfigurationHelper.getConfiguration(wikiId).getMembershipType().equals(MembershipType.OPEN)) { |
468 |
0 |
throw new WikiUserManagerException(String.format("The user [%s] is not authorized to join the wiki [%s].", |
469 |
|
userId, wikiId)); |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
0 |
addMember(userId, wikiId); |
474 |
|
} |
475 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
476 |
0 |
@Override... |
477 |
|
public void leave(String userId, String wikiId) throws WikiUserManagerException |
478 |
|
{ |
479 |
0 |
removeMember(userId, wikiId); |
480 |
|
} |
481 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
|
482 |
0 |
@Override... |
483 |
|
public void acceptRequest(MemberCandidacy request, String message, String privateComment) |
484 |
|
throws WikiUserManagerException |
485 |
|
{ |
486 |
|
|
487 |
0 |
addMember(request.getUserId(), request.getWikiId()); |
488 |
|
|
489 |
|
|
490 |
0 |
XWikiContext xcontext = xcontextProvider.get(); |
491 |
|
|
492 |
|
|
493 |
0 |
request.setAdminId(documentReferenceSerializer.serialize(xcontext.getUserReference())); |
494 |
0 |
request.setAdminComment(message); |
495 |
0 |
request.setAdminPrivateComment(privateComment); |
496 |
0 |
request.setStatus(MemberCandidacy.Status.ACCEPTED); |
497 |
0 |
request.setDateOfClosure(new Date()); |
498 |
|
|
499 |
|
|
500 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(request.getWikiId()); |
501 |
|
|
502 |
|
|
503 |
0 |
BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, request.getId()); |
504 |
|
|
505 |
|
|
506 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, request.getAdminId()); |
507 |
0 |
object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, request.getAdminComment()); |
508 |
0 |
object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_PRIVATE_COMMENT, |
509 |
|
request.getAdminPrivateComment()); |
510 |
0 |
object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE, |
511 |
|
request.getDateOfClosure()); |
512 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, |
513 |
|
request.getStatus().name().toLowerCase()); |
514 |
|
|
515 |
|
|
516 |
0 |
saveGroupDocument(groupDoc, String.format("Accept join request from user [%s]", request.getUserId())); |
517 |
|
} |
518 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
|
519 |
0 |
@Override... |
520 |
|
public void refuseRequest(MemberCandidacy request, String message, String privateComment) |
521 |
|
throws WikiUserManagerException |
522 |
|
{ |
523 |
|
|
524 |
0 |
XWikiContext xcontext = xcontextProvider.get(); |
525 |
|
|
526 |
|
|
527 |
0 |
request.setAdminId(documentReferenceSerializer.serialize(xcontext.getUserReference())); |
528 |
0 |
request.setAdminComment(message); |
529 |
0 |
request.setAdminPrivateComment(privateComment); |
530 |
0 |
request.setStatus(MemberCandidacy.Status.REJECTED); |
531 |
0 |
request.setDateOfClosure(new Date()); |
532 |
|
|
533 |
|
|
534 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(request.getWikiId()); |
535 |
|
|
536 |
|
|
537 |
0 |
BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, request.getId()); |
538 |
|
|
539 |
|
|
540 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, request.getAdminId()); |
541 |
0 |
object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, request.getAdminComment()); |
542 |
0 |
object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_PRIVATE_COMMENT, |
543 |
|
request.getAdminPrivateComment()); |
544 |
0 |
object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE, |
545 |
|
request.getDateOfClosure()); |
546 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, |
547 |
|
request.getStatus().name().toLowerCase()); |
548 |
|
|
549 |
|
|
550 |
0 |
saveGroupDocument(groupDoc, String.format("Reject join request from user [%s]", request.getUserId())); |
551 |
|
} |
552 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
553 |
0 |
@Override... |
554 |
|
public void cancelCandidacy(MemberCandidacy candidacy) throws WikiUserManagerException |
555 |
|
{ |
556 |
|
|
557 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(candidacy.getWikiId()); |
558 |
|
|
559 |
|
|
560 |
0 |
BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, candidacy.getId()); |
561 |
|
|
562 |
|
|
563 |
0 |
if (object != null) { |
564 |
0 |
groupDoc.removeXObject(object); |
565 |
0 |
saveGroupDocument(groupDoc, String.format("Candidacy [%d] is canceled.", candidacy.getId())); |
566 |
|
} |
567 |
|
} |
568 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 2 |
Complexity Density: 0.11 |
|
569 |
0 |
@Override... |
570 |
|
public MemberCandidacy invite(String userId, String wikiId, String message) |
571 |
|
throws WikiUserManagerException |
572 |
|
{ |
573 |
0 |
XWikiContext xcontext = xcontextProvider.get(); |
574 |
|
|
575 |
|
|
576 |
0 |
MemberCandidacy candidacy = new MemberCandidacy(wikiId, userId, MemberCandidacy.CandidateType.INVITATION); |
577 |
0 |
candidacy.setUserComment(message); |
578 |
0 |
candidacy.setAdminId(documentReferenceSerializer.serialize(xcontext.getUserReference())); |
579 |
|
|
580 |
|
|
581 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(wikiId); |
582 |
|
|
583 |
|
|
584 |
0 |
try { |
585 |
0 |
int objectNumber = groupDoc.createXObject(WikiCandidateMemberClassInitializer.REFERENCE, xcontext); |
586 |
0 |
candidacy.setId(objectNumber); |
587 |
0 |
BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, objectNumber); |
588 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_USER, candidacy.getUserId()); |
589 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, candidacy.getAdminId()); |
590 |
0 |
object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, message); |
591 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, |
592 |
|
candidacy.getStatus().name().toLowerCase()); |
593 |
0 |
object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CREATION, |
594 |
|
candidacy.getDateOfCreation()); |
595 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE, |
596 |
|
candidacy.getType().name().toLowerCase()); |
597 |
|
} catch (XWikiException e) { |
598 |
0 |
throw new WikiUserManagerException("Failed to create a new invitation object.", e); |
599 |
|
} |
600 |
|
|
601 |
|
|
602 |
0 |
saveGroupDocument(groupDoc, String.format("[%s] is invited to join the wiki.", userId)); |
603 |
|
|
604 |
0 |
return candidacy; |
605 |
|
} |
606 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
607 |
0 |
@Override... |
608 |
|
public void acceptInvitation(MemberCandidacy invitation, String message) throws WikiUserManagerException |
609 |
|
{ |
610 |
|
|
611 |
0 |
addMember(invitation.getUserId(), invitation.getWikiId()); |
612 |
|
|
613 |
|
|
614 |
0 |
invitation.setUserComment(message); |
615 |
0 |
invitation.setStatus(MemberCandidacy.Status.ACCEPTED); |
616 |
0 |
invitation.setDateOfClosure(new Date()); |
617 |
|
|
618 |
|
|
619 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(invitation.getWikiId()); |
620 |
|
|
621 |
|
|
622 |
0 |
BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, invitation.getId()); |
623 |
|
|
624 |
|
|
625 |
0 |
object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, invitation.getUserComment()); |
626 |
0 |
object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE, invitation.getDateOfClosure()); |
627 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, |
628 |
|
invitation.getStatus().name().toLowerCase()); |
629 |
|
|
630 |
|
|
631 |
0 |
saveGroupDocument(groupDoc, String.format("User [%s] has accepted to join the wiki. ", invitation.getUserId())); |
632 |
|
} |
633 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
634 |
0 |
@Override... |
635 |
|
public void refuseInvitation(MemberCandidacy invitation, String message) throws WikiUserManagerException |
636 |
|
{ |
637 |
|
|
638 |
0 |
invitation.setUserComment(message); |
639 |
0 |
invitation.setStatus(MemberCandidacy.Status.REJECTED); |
640 |
0 |
invitation.setDateOfClosure(new Date()); |
641 |
|
|
642 |
|
|
643 |
0 |
XWikiDocument groupDoc = getMembersGroupDocument(invitation.getWikiId()); |
644 |
|
|
645 |
|
|
646 |
0 |
BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, invitation.getId()); |
647 |
|
|
648 |
|
|
649 |
0 |
object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, invitation.getUserComment()); |
650 |
0 |
object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE, invitation.getDateOfClosure()); |
651 |
0 |
object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, |
652 |
|
invitation.getStatus().name().toLowerCase()); |
653 |
|
|
654 |
|
|
655 |
0 |
saveGroupDocument(groupDoc, String.format("User [%s] has rejected the invitation to join the wiki.", |
656 |
|
invitation.getUserId())); |
657 |
|
} |
658 |
|
} |