1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.objects.classes

File ViewableAllowedDBListValueFilter.java

 

Coverage histogram

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

Code metrics

12
14
2
1
86
51
9
0.64
7
2
4.5

Classes

Class Line # Actions
ViewableAllowedDBListValueFilter 46 14 0% 9 3
0.8928571389.3%
 

Contributing tests

This file is covered by 3 tests. .

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 com.xpn.xwiki.internal.objects.classes;
21   
22    import java.util.Arrays;
23    import java.util.LinkedList;
24    import java.util.List;
25   
26    import javax.inject.Inject;
27    import javax.inject.Named;
28    import javax.inject.Singleton;
29   
30    import org.xwiki.component.annotation.Component;
31    import org.xwiki.model.reference.DocumentReference;
32    import org.xwiki.model.reference.DocumentReferenceResolver;
33    import org.xwiki.query.QueryFilter;
34    import org.xwiki.security.authorization.ContextualAuthorizationManager;
35    import org.xwiki.security.authorization.Right;
36   
37    /**
38    * Filters the viewable values of a Database List property.
39    *
40    * @version $Id: 782d8532ba406c5d59e11d185237b39878df8dfc $
41    * @since 9.8RC1
42    */
43    @Component
44    @Named("viewableAllowedDBListPropertyValue")
45    @Singleton
 
46    public class ViewableAllowedDBListValueFilter implements QueryFilter
47    {
48    @Inject
49    private ContextualAuthorizationManager authorization;
50   
51    @Inject
52    @Named("current")
53    private DocumentReferenceResolver<String> documentReferenceResolver;
54   
 
55  95 toggle @Override
56    public String filterStatement(String statement, String language)
57    {
58    // We only filter the results.
59  95 return statement;
60    }
61   
 
62  96 toggle @Override
63    public List filterResults(List results)
64    {
65  96 List<Object> filteredResults = new LinkedList<>();
66  96 for (Object result : results) {
67  393 if (result instanceof String) {
68  2 DocumentReference documentReference = this.documentReferenceResolver.resolve((String) result);
69  2 if (this.authorization.hasAccess(Right.VIEW, documentReference)) {
70  1 filteredResults.add(result);
71    }
72  391 } else if (result instanceof Object[]) {
73  391 Object[] row = (Object[]) result;
74  391 if (row.length > 0 && row[0] instanceof String) {
75  391 DocumentReference documentReference = this.documentReferenceResolver.resolve((String) row[0]);
76  391 if (this.authorization.hasAccess(Right.VIEW, documentReference)) {
77    // The document full name column was added just to be able to check view right. We can discard
78    // it now and return only the relevant columns.
79  390 filteredResults.add(row.length > 1 ? Arrays.copyOfRange(row, 1, row.length) : row);
80    }
81    }
82    }
83    }
84  96 return filteredResults;
85    }
86    }