source: indico/indico/MaKaC/webinterface/rh/collaboration.py @ 7f8da8

burotelhello-world-walkthroughipv6new-webexprov-dual-interfacev0.97-seriesv0.98-seriesv0.98.2v0.98.3v0.98b1v0.98b2v0.99v1.0v1.1
Last change on this file since 7f8da8 was 7f8da8, checked in by David Martín Clavo <david.martin.clavo@…>, 4 years ago

[FIX] Fix for some RC classes when user is not logged in

  • Property mode set to 100644
File size: 11.4 KB
Line 
1# -*- coding: utf-8 -*-
2##
3## $Id: collaboration.py,v 1.13 2009/04/28 14:08:41 dmartinc Exp $
4##
5## This file is part of CDS Indico.
6## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
7##
8## CDS Indico is free software; you can redistribute it and/or
9## modify it under the terms of the GNU General Public License as
10## published by the Free Software Foundation; either version 2 of the
11## License, or (at your option) any later version.
12##
13## CDS Indico is distributed in the hope that it will be useful, but
14## WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16## General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with CDS Indico; if not, write to the Free Software Foundation, Inc.,
20## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21
22from MaKaC.webinterface.rh.conferenceModif import RHConferenceModifBase
23from MaKaC.errors import MaKaCError, PluginError
24from MaKaC.webinterface.pages import conferences
25from MaKaC.webinterface.pages import collaboration
26from MaKaC.webinterface import urlHandlers
27from MaKaC.i18n import _
28from MaKaC.plugins.base import PluginsHolder, Plugin
29from MaKaC.plugins.Collaboration.collaborationTools import CollaborationTools
30from MaKaC.webinterface.rh.admins import RCAdmin, RHAdminBase
31from MaKaC.webinterface.rh.conferenceDisplay import RHConferenceBaseDisplay
32
33class RCCollaborationAdmin(object):
34    @staticmethod
35    def hasRights(request = None, user = None):
36        """ Returns True if the user is a Server Admin or a Collaboration admin
37            request: an RH or Service object
38            user: an Avatar object
39            If user is not None, the request object will be used to check the user's privileges.
40            Otherwise the user will be retrieved from the request object
41        """
42        if not PluginsHolder().hasPluginType("Collaboration"):
43            return False
44       
45        if user is None:
46            if request is None:
47                return False
48            else:
49                user = request._getUser()
50       
51        # check if user is Server Admin, Collaboration Admin
52        collaborationAdmins = PluginsHolder().getPluginType('Collaboration').getOption('collaborationAdmins').getValue()
53       
54        return RCAdmin.hasRights(None, user) or user in collaborationAdmins
55       
56class RCCollaborationPluginAdmin(object):
57    @staticmethod
58    def hasRights(request = None, user = None, plugins = []):
59        """ Returns True if the user is an admin of one of the plugins corresponding to pluginNames
60            plugins: a list of Plugin objects (e.g. EVO, RecordingRequest) or strings with the plugin name ('EVO', 'RecordingRequest')
61        """
62        if not PluginsHolder().hasPluginType("Collaboration"):
63            return False
64       
65        if user is None:
66            if request is None:
67                return False
68            else:
69                user = request._getUser()
70       
71        coll = PluginsHolder().getPluginType('Collaboration')
72       
73        if plugins:
74            for plugin in plugins:
75                if not isinstance(plugin, Plugin):
76                    plugin = coll.getPlugin(plugin)
77               
78                if user in plugin.getOption('admins').getValue():
79                    return True
80               
81        return False
82   
83   
84class RCVideoServicesManager(object):
85    @staticmethod
86    def hasRights(request, plugins = []):
87        """ Returns True if the logged in user has rights to operate with bookings of at least one of a list of plugins, for an event.
88            This is true if:
89                -the user is a Video Services manager (can operate with all plugins)
90                -the user is a plugin manager of one of the plugins
91            Of course, it's also true if the user is event manager or server admin, but this class does not cover that case.
92             
93            request: an RH or Service object
94            plugins: either a list of plugin names, or Plugin objects (we will then check if the user is manager of any of those plugins),
95                     or the string 'any' (we will then check if the user is manager of any plugin),
96                     or nothing (we will then check if the user is a Video Services manager).
97        """
98        if not PluginsHolder().hasPluginType("Collaboration"):
99            return False
100       
101        user = request.getAW().getUser()
102       
103        csbm = request._conf.getCSBookingManager()
104        if csbm.isVideoServicesManager(user):
105            return True
106       
107        if plugins == 'any':
108            return csbm.isPluginManagerOfAnyPlugin(user)
109       
110        for plugin in plugins:
111            if isinstance(plugin, Plugin):
112                plugin = plugin.getName()
113            if csbm.isPluginManager(plugin, user):
114                return True
115           
116        return False
117   
118################################################### Server Wide pages #########################################
119class RHAdminCollaboration(RHAdminBase):
120    _uh = urlHandlers.UHAdminCollaboration
121   
122    def _checkParams( self, params ):
123        RHAdminBase._checkParams( self, params )
124        self._queryParams = {}
125        self._queryParams["queryOnLoad"] = (params.get('queryOnLoad', None) == 'true')
126        self._queryParams["page"] = params.get("page", 1)
127        self._queryParams["resultsPerPage"] = params.get("resultsPerPage", 10)
128        self._queryParams["indexName"] = params.get('indexName', None)
129        self._queryParams["viewBy"] = params.get('viewBy', 'modificationDate')
130        self._queryParams["orderBy"] = params.get('orderBy', '')
131        self._queryParams["sinceDate"] = params.get('sinceDate', '').strip()
132        self._queryParams["toDate"] = params.get('toDate', '').strip()
133        self._queryParams["fromDays"] = params.get('fromDays', '').strip()
134        self._queryParams["toDays"] = params.get('toDays', '').strip()
135        self._queryParams["fromTitle"] = params.get('fromTitle', '').strip()
136        self._queryParams["toTitle"] = params.get('toTitle', '').strip()
137        self._queryParams["onlyPending"] = (params.get('onlyPending', None) == 'true')
138        self._queryParams["conferenceId"] = params.get('conferenceId', '').strip()
139        self._queryParams["categoryId"] = params.get('categoryId', '').strip()
140   
141    def _checkProtection( self ):
142        if not PluginsHolder().hasPluginType("Collaboration"):
143            raise PluginError("Collaboration plugin system is not active")
144        if not RCCollaborationAdmin.hasRights(self, None): #and not RCCollaborationPluginAdmin.hasRights(self, None, self._tabPlugins)
145            RHAdminBase._checkProtection(self)
146           
147    def _process(self):
148        p = collaboration.WPAdminCollaboration( self , self._queryParams)
149        return p.display()
150       
151   
152################################################### Event Modification Request Handlers ####################################                     
153
154class RHConfModifCSBase(RHConferenceModifBase):
155    def _checkParams(self, params):
156        RHConferenceModifBase._checkParams(self, params)
157       
158        self._activeTabName = params.get("tab", None)
159       
160        self._canSeeAllPluginTabs = self._target.canModify(self.getAW()) or RCCollaborationAdmin.hasRights(self) or RCVideoServicesManager.hasRights(self)
161       
162        # we build the list 'allowedTabs', a list of all tabs that the user can see
163        if self._canSeeAllPluginTabs:
164            #if the logged in user is event manager, server admin or collaboration admin: we show all plugin tabs
165            allowedTabs = CollaborationTools.getTabs(self._conf)
166        else:
167            #else we show only the tabs of plugins of which the user is admin
168            allowedTabs = CollaborationTools.getTabs(self._conf, self._getUser())
169           
170        if self._target.canModify(self.getAW()) or RCVideoServicesManager.hasRights(self):
171            allowedTabs.append('Managers')
172           
173        # we order the list of allowedTabs into the self._tabs list
174        tabOrder = CollaborationTools.getCollaborationOptionValue('tabOrder')
175        self._tabs = []
176       
177        for tabName in tabOrder:
178            if tabName in allowedTabs:
179                self._tabs.append(tabName)
180                allowedTabs.remove(tabName)
181               
182        for tabName in allowedTabs:
183            if tabName != 'Managers':
184                self._tabs.append(tabName)
185
186        if 'Managers' in allowedTabs:
187            self._tabs.append('Managers')
188       
189
190class RHConfModifCSBookings(RHConfModifCSBase):
191    _uh = urlHandlers.UHConfModifCollaboration
192
193    def _checkParams(self, params):
194        RHConfModifCSBase._checkParams(self, params)
195       
196        if self._activeTabName and not self._activeTabName in self._tabs:
197            raise MaKaCError(_("That Video Services tab doesn't exist or you cannot access it"), _("Video Services"))
198        elif not self._activeTabName and self._tabs:
199            self._activeTabName = self._tabs[0]
200           
201        if self._canSeeAllPluginTabs:
202            self._tabPlugins = CollaborationTools.getPluginsByTab(self._activeTabName, self._conf)
203        else:
204            self._tabPlugins = CollaborationTools.getPluginsByTab(self._activeTabName, self._conf, self._getUser())
205   
206    def _checkProtection(self):
207        if not PluginsHolder().hasPluginType("Collaboration"):
208            raise PluginError("Collaboration plugin system is not active")
209       
210        hasRights = RCCollaborationAdmin.hasRights(self, None) or \
211                    RCCollaborationPluginAdmin.hasRights(self, None, self._tabPlugins) or \
212                    RCVideoServicesManager.hasRights(self, self._tabPlugins)
213       
214        if not hasRights:
215            RHConferenceModifBase._checkProtection(self)
216       
217    def _process( self ):
218       
219        if self._conf.isClosed():
220            p = conferences.WPConferenceModificationClosed( self, self._target )
221            return p.display()
222        else:
223            ph = PluginsHolder()
224            if ph.getPluginType('Collaboration').getOption("useHTTPS").getValue():
225                self._tohttps = True
226                if self._checkHttpsRedirect():
227                    return ""
228           
229            p = collaboration.WPConfModifCollaboration( self, self._conf)
230            return p.display()
231       
232
233class RHConfModifCSProtection(RHConfModifCSBase):
234    _uh = urlHandlers.UHConfModifCollaborationManagers
235
236    def _checkParams(self, params):
237        RHConfModifCSBase._checkParams(self, params)
238        self._activeTabName = 'Managers'
239   
240    def _checkProtection(self):
241        if not PluginsHolder().hasPluginType("Collaboration"):
242            raise PluginError("Collaboration plugin system is not active")
243        if not RCVideoServicesManager.hasRights(self):
244            RHConferenceModifBase._checkProtection(self)
245       
246    def _process( self ):
247       
248        if self._conf.isClosed():
249            p = conferences.WPConferenceModificationClosed( self, self._target )
250            return p.display()
251        else:
252            p = collaboration.WPConfModifCollaborationProtection( self, self._conf)
253            return p.display()
254       
255
256################################################### Event Display Request Handlers ####################################
257class RHCollaborationDisplay(RHConferenceBaseDisplay):
258    _uh = urlHandlers.UHCollaborationDisplay
259   
260    def _process( self ):
261        p = collaboration.WPCollaborationDisplay( self, self._target )
262        return p.display()
Note: See TracBrowser for help on using the repository browser.