1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.distribution.internal

File DistributionAction.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

6
13
2
1
79
37
5
0.38
6.5
2
2.5

Classes

Class Line # Actions
DistributionAction 35 13 0% 5 21
0.00%
 

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.extension.distribution.internal;
21   
22    import com.xpn.xwiki.XWiki;
23    import com.xpn.xwiki.XWikiContext;
24    import com.xpn.xwiki.XWikiException;
25    import com.xpn.xwiki.web.Utils;
26    import com.xpn.xwiki.web.XWikiAction;
27   
28    /**
29    * Action used to apply various distribution related actions. We create a special action to make sure to execute the
30    * template with the current user rights.
31    *
32    * @version $Id: e7db0cc8f951f450c73b4bed62effd10aa4513d5 $
33    * @since 4.2M3
34    */
 
35    public class DistributionAction extends XWikiAction
36    {
37    /**
38    * The identifier of the distribution action.
39    *
40    * @todo need an enumerated class for actions.
41    */
42    public static final String DISTRIBUTION_ACTION = "distribution";
43   
 
44  0 toggle @Override
45    public boolean action(XWikiContext context) throws XWikiException
46    {
47  0 context.put("action", DISTRIBUTION_ACTION);
48   
49    // Make sure DW skip all skins
50  0 context.put(XWiki.CKEY_SKIN, XWiki.DEFAULT_SKIN);
51  0 context.put(XWiki.CKEY_BASESKIN, "");
52   
53    // Disallow template override with xpage parameter.
54  0 if (!DISTRIBUTION_ACTION.equals(Utils.getPage(context.getRequest(), DISTRIBUTION_ACTION))) {
55  0 throw new XWikiException(XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_ACCESS_DENIED,
56    String.format("Template may not be overriden with 'xpage' in [%s] action.", DISTRIBUTION_ACTION));
57    }
58   
59    // Make sure the user has the right to access the distribution action
60  0 DistributionManager distributionManager = Utils.getComponent(DistributionManager.class);
61  0 if (!distributionManager.canDisplayDistributionWizard()) {
62  0 if (context.getUserReference() == null) {
63  0 context.getWiki().getAuthService().showLogin(context);
64  0 return false;
65    } else {
66  0 throw new XWikiException(XWikiException.MODULE_XWIKI, XWikiException.ERROR_XWIKI_ACCESS_DENIED,
67    String.format("Current user need proper rights to access action [%s].", DISTRIBUTION_ACTION));
68    }
69    }
70   
71  0 return true;
72    }
73   
 
74  0 toggle @Override
75    public String render(XWikiContext context) throws XWikiException
76    {
77  0 return DISTRIBUTION_ACTION;
78    }
79    }