source: indico/indico/MaKaC/webinterface/rh/collaboration.py @ 0e0c28

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 0e0c28 was 0e0c28, checked in by Jose Benito <jose.benito.gonzalez@…>, 3 years ago

[FIXED] Webcast admins access

fixes #78: Webcast admins should have access rights to every event
fixes #79: Webcast admins should see the "Video Services Overview"

  • Property mode set to 100644
File size: 11.8 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                     or the string 'any' (we will then check if the user is manager of any plugin),
62        """
63        if not PluginsHolder().hasPluginType("Collaboration"):
64            return False
65       
66        if user is None:
67            if request is None:
68                return False
69            else:
70                user = request._getUser()
71       
72        coll = PluginsHolder().getPluginType('Collaboration')
73       
74        if plugins == 'any':
75            plugins = []
76            for p in CollaborationTools.getCollaborationPluginType().getPluginList():
77                plugins.append(p.getName())
78       
79        if plugins:
80            for plugin in plugins:
81                if not isinstance(plugin, Plugin):
82                    plugin = coll.getPlugin(plugin)
83               
84                if user in plugin.getOption('admins').getValue():
85                    return True
86               
87        return False
88   
89   
90class RCVideoServicesManager(object):
91    @staticmethod
92    def hasRights(request, plugins = []):
93        """ 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.
94            This is true if:
95                -the user is a Video Services manager (can operate with all plugins)
96                -the user is a plugin manager of one of the plugins
97            Of course, it's also true if the user is event manager or server admin, but this class does not cover that case.
98             
99            request: an RH or Service object
100            plugins: either a list of plugin names, or Plugin objects (we will then check if the user is manager of any of those plugins),
101                     or the string 'any' (we will then check if the user is manager of any plugin),
102                     or nothing (we will then check if the user is a Video Services manager).
103        """
104        if not PluginsHolder().hasPluginType("Collaboration"):
105            return False
106       
107        user = request.getAW().getUser()
108       
109        csbm = request._conf.getCSBookingManager()
110        if csbm.isVideoServicesManager(user):
111            return True
112       
113        if plugins == 'any':
114            return csbm.isPluginManagerOfAnyPlugin(user)
115       
116        for plugin in plugins:
117            if isinstance(plugin, Plugin):
118                plugin = plugin.getName()
119            if csbm.isPluginManager(plugin, user):
120                return True
121           
122        return False
123   
124################################################### Server Wide pages #########################################
125class RHAdminCollaboration(RHAdminBase):
126    _uh = urlHandlers.UHAdminCollaboration
127   
128    def _checkParams( self, params ):
129        RHAdminBase._checkParams( self, params )
130        self._queryParams = {}
131        self._queryParams["queryOnLoad"] = (params.get('queryOnLoad', None) == 'true')
132        self._queryParams["page"] = params.get("page", 1)
133        self._queryParams["resultsPerPage"] = params.get("resultsPerPage", 10)
134        self._queryParams["indexName"] = params.get('indexName', None)
135        self._queryParams["viewBy"] = params.get('viewBy', 'modificationDate')
136        self._queryParams["orderBy"] = params.get('orderBy', '')
137        self._queryParams["sinceDate"] = params.get('sinceDate', '').strip()
138        self._queryParams["toDate"] = params.get('toDate', '').strip()
139        self._queryParams["fromDays"] = params.get('fromDays', '').strip()
140        self._queryParams["toDays"] = params.get('toDays', '').strip()
141        self._queryParams["fromTitle"] = params.get('fromTitle', '').strip()
142        self._queryParams["toTitle"] = params.get('toTitle', '').strip()
143        self._queryParams["onlyPending"] = (params.get('onlyPending', None) == 'true')
144        self._queryParams["conferenceId"] = params.get('conferenceId', '').strip()
145        self._queryParams["categoryId"] = params.get('categoryId', '').strip()
146   
147    def _checkProtection( self ):
148        if not PluginsHolder().hasPluginType("Collaboration"):
149            raise PluginError("Collaboration plugin system is not active")
150       
151        if not RCCollaborationAdmin.hasRights(self, None) and not RCCollaborationPluginAdmin.hasRights(self, plugins = "any"): #RCCollaborationPluginAdmin.hasRights(self, None, self._tabPlugins):
152            RHAdminBase._checkProtection(self)
153           
154    def _process(self):
155        p = collaboration.WPAdminCollaboration( self , self._queryParams)
156        return p.display()
157       
158   
159################################################### Event Modification Request Handlers ####################################                     
160
161class RHConfModifCSBase(RHConferenceModifBase):
162    def _checkParams(self, params):
163        RHConferenceModifBase._checkParams(self, params)
164       
165        self._activeTabName = params.get("tab", None)
166       
167        self._canSeeAllPluginTabs = self._target.canModify(self.getAW()) or RCCollaborationAdmin.hasRights(self) or RCVideoServicesManager.hasRights(self)
168       
169        # we build the list 'allowedTabs', a list of all tabs that the user can see
170        if self._canSeeAllPluginTabs:
171            #if the logged in user is event manager, server admin or collaboration admin: we show all plugin tabs
172            allowedTabs = CollaborationTools.getTabs(self._conf)
173        else:
174            #else we show only the tabs of plugins of which the user is admin
175            allowedTabs = CollaborationTools.getTabs(self._conf, self._getUser())
176           
177        if self._target.canModify(self.getAW()) or RCVideoServicesManager.hasRights(self):
178            allowedTabs.append('Managers')
179           
180        # we order the list of allowedTabs into the self._tabs list
181        tabOrder = CollaborationTools.getCollaborationOptionValue('tabOrder')
182        self._tabs = []
183       
184        for tabName in tabOrder:
185            if tabName in allowedTabs:
186                self._tabs.append(tabName)
187                allowedTabs.remove(tabName)
188               
189        for tabName in allowedTabs:
190            if tabName != 'Managers':
191                self._tabs.append(tabName)
192
193        if 'Managers' in allowedTabs:
194            self._tabs.append('Managers')
195       
196
197class RHConfModifCSBookings(RHConfModifCSBase):
198    _uh = urlHandlers.UHConfModifCollaboration
199
200    def _checkParams(self, params):
201        RHConfModifCSBase._checkParams(self, params)
202       
203        if self._activeTabName and not self._activeTabName in self._tabs:
204            raise MaKaCError(_("That Video Services tab doesn't exist or you cannot access it"), _("Video Services"))
205        elif not self._activeTabName and self._tabs:
206            self._activeTabName = self._tabs[0]
207           
208        if self._canSeeAllPluginTabs:
209            self._tabPlugins = CollaborationTools.getPluginsByTab(self._activeTabName, self._conf)
210        else:
211            self._tabPlugins = CollaborationTools.getPluginsByTab(self._activeTabName, self._conf, self._getUser())
212   
213    def _checkProtection(self):
214        if not PluginsHolder().hasPluginType("Collaboration"):
215            raise PluginError("Collaboration plugin system is not active")
216       
217        hasRights = RCCollaborationAdmin.hasRights(self, None) or \
218                    RCCollaborationPluginAdmin.hasRights(self, None, self._tabPlugins) or \
219                    RCVideoServicesManager.hasRights(self, self._tabPlugins)
220       
221        if not hasRights:
222            RHConferenceModifBase._checkProtection(self)
223       
224    def _process( self ):
225       
226        if self._conf.isClosed():
227            p = conferences.WPConferenceModificationClosed( self, self._target )
228            return p.display()
229        else:
230            ph = PluginsHolder()
231            if ph.getPluginType('Collaboration').getOption("useHTTPS").getValue():
232                self._tohttps = True
233                if self._checkHttpsRedirect():
234                    return ""
235           
236            p = collaboration.WPConfModifCollaboration( self, self._conf)
237            return p.display()
238       
239
240class RHConfModifCSProtection(RHConfModifCSBase):
241    _uh = urlHandlers.UHConfModifCollaborationManagers
242
243    def _checkParams(self, params):
244        RHConfModifCSBase._checkParams(self, params)
245        self._activeTabName = 'Managers'
246   
247    def _checkProtection(self):
248        if not PluginsHolder().hasPluginType("Collaboration"):
249            raise PluginError("Collaboration plugin system is not active")
250        if not RCVideoServicesManager.hasRights(self):
251            RHConferenceModifBase._checkProtection(self)
252       
253    def _process( self ):
254       
255        if self._conf.isClosed():
256            p = conferences.WPConferenceModificationClosed( self, self._target )
257            return p.display()
258        else:
259            p = collaboration.WPConfModifCollaborationProtection( self, self._conf)
260            return p.display()
261       
262
263################################################### Event Display Request Handlers ####################################
264class RHCollaborationDisplay(RHConferenceBaseDisplay):
265    _uh = urlHandlers.UHCollaborationDisplay
266   
267    def _process( self ):
268        p = collaboration.WPCollaborationDisplay( self, self._target )
269        return p.display()
Note: See TracBrowser for help on using the repository browser.