1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rest.internal.resources.wikis

File WikisResourceImpl.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

2
14
1
1
104
63
6
0.43
14
1
6

Classes

Class Line # Actions
WikisResourceImpl 51 14 0% 6 2
0.8823529588.2%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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 $Id: 1bdd50418bad28302821d9a775944c573da179ee $
48    */
49    @Component
50    @Named("org.xwiki.rest.internal.resources.wikis.WikisResourceImpl")
 
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   
 
65  233 toggle @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    // Allow listing a wiki if:
73    // - the user has view access to it
74    // - or the wiki accepts global users and is not an invitation-based wiki
75    // - or the current user has a pending invitation to the wiki
76    // Note 1: To check if a user has view access to a wiki we check if the user can access the home page
77    // of the "XWiki" space. We do this because this needs to be allowed in view for the wiki to
78    // work properly.
79    // Note 2: it would be nicer to have an API for this.
80    // Note 3: this strategy is copied from WikisLiveTableResults.xml
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    }