1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rest.internal.resources.wikis; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Named; |
24 |
|
import javax.inject.Provider; |
25 |
|
|
26 |
|
import org.xwiki.component.annotation.Component; |
27 |
|
import org.xwiki.model.EntityType; |
28 |
|
import org.xwiki.model.reference.DocumentReference; |
29 |
|
import org.xwiki.model.reference.EntityReference; |
30 |
|
import org.xwiki.rest.Relations; |
31 |
|
import org.xwiki.rest.XWikiResource; |
32 |
|
import org.xwiki.rest.XWikiRestException; |
33 |
|
import org.xwiki.rest.internal.DomainObjectFactory; |
34 |
|
import org.xwiki.rest.internal.Utils; |
35 |
|
import org.xwiki.rest.model.jaxb.Link; |
36 |
|
import org.xwiki.rest.model.jaxb.Wikis; |
37 |
|
import org.xwiki.rest.resources.wikis.WikisResource; |
38 |
|
import org.xwiki.rest.resources.wikis.WikisSearchQueryResource; |
39 |
|
import org.xwiki.security.authorization.ContextualAuthorizationManager; |
40 |
|
import org.xwiki.security.authorization.Right; |
41 |
|
import org.xwiki.wiki.descriptor.WikiDescriptorManager; |
42 |
|
import org.xwiki.wiki.user.MembershipType; |
43 |
|
import org.xwiki.wiki.user.UserScope; |
44 |
|
import org.xwiki.wiki.user.WikiUserManager; |
45 |
|
|
46 |
|
|
47 |
|
@version |
48 |
|
|
49 |
|
@Component |
50 |
|
@Named("org.xwiki.rest.internal.resources.wikis.WikisResourceImpl") |
|
|
| 88.2% |
Uncovered Elements: 2 (17) |
Complexity: 6 |
Complexity Density: 0.43 |
|
51 |
|
public class WikisResourceImpl extends XWikiResource implements WikisResource |
52 |
|
{ |
53 |
|
@Inject |
54 |
|
private WikiDescriptorManager wikiDescriptorManager; |
55 |
|
|
56 |
|
@Inject |
57 |
|
private ContextualAuthorizationManager authorizationManager; |
58 |
|
|
59 |
|
@Inject |
60 |
|
private WikiUserManager wikiUserManager; |
61 |
|
|
62 |
|
@Inject |
63 |
|
private Provider<DocumentReference> defaultDocumentReferenceProvider; |
64 |
|
|
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 6 |
Complexity Density: 0.43 |
|
65 |
233 |
@Override... |
66 |
|
public Wikis getWikis() throws XWikiRestException |
67 |
|
{ |
68 |
233 |
try { |
69 |
233 |
Wikis wikis = objectFactory.createWikis(); |
70 |
|
|
71 |
233 |
for (String wikiId : this.wikiDescriptorManager.getAllIds()) { |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
234 |
EntityReference absoluteCommentReference = |
82 |
|
new EntityReference(this.defaultDocumentReferenceProvider.get().getName(), EntityType.DOCUMENT, |
83 |
|
new EntityReference("XWiki", EntityType.SPACE, new EntityReference(wikiId, EntityType.WIKI))); |
84 |
234 |
DocumentReference currentUserReference = getXWikiContext().getUserReference(); |
85 |
234 |
if (this.authorizationManager.hasAccess(Right.VIEW, absoluteCommentReference) |
86 |
|
|| (this.wikiUserManager.getUserScope(wikiId) != UserScope.LOCAL_ONLY && this.wikiUserManager |
87 |
|
.getMembershipType(wikiId) != MembershipType.INVITE) |
88 |
|
|| this.wikiUserManager.hasPendingInvitation(currentUserReference, wikiId)) { |
89 |
234 |
wikis.getWikis().add(DomainObjectFactory.createWiki(objectFactory, uriInfo.getBaseUri(), wikiId)); |
90 |
|
} |
91 |
|
} |
92 |
|
|
93 |
233 |
String queryUri = Utils.createURI(uriInfo.getBaseUri(), WikisSearchQueryResource.class).toString(); |
94 |
233 |
Link queryLink = objectFactory.createLink(); |
95 |
233 |
queryLink.setHref(queryUri); |
96 |
233 |
queryLink.setRel(Relations.QUERY); |
97 |
233 |
wikis.getLinks().add(queryLink); |
98 |
|
|
99 |
233 |
return wikis; |
100 |
|
} catch (Exception e) { |
101 |
0 |
throw new XWikiRestException("Failed to get the list of wikis", e); |
102 |
|
} |
103 |
|
} |
104 |
|
} |