source: indico/indico/MaKaC/services/implementation/collaboration.py @ e3634a

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 e3634a 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: 18.1 KB
Line 
1# -*- coding: utf-8 -*-
2##
3## $Id: collaboration.py,v 1.14 2009/06/18 15:14:43 pferreir 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 datetime import timedelta
23from MaKaC.services.implementation.base import ParameterManager, AdminService
24from MaKaC.services.implementation.conference import ConferenceModifBase
25from MaKaC.common.PickleJar import DictPickler
26from MaKaC.plugins.Collaboration.base import CollaborationException, CollaborationServiceException
27from MaKaC.webinterface.rh.collaboration import RCCollaborationAdmin,\
28    RCCollaborationPluginAdmin, RCVideoServicesManager
29from MaKaC.i18n import _
30from MaKaC.common.indexes import IndexesHolder
31from MaKaC.plugins.base import PluginsHolder
32from MaKaC.common.timezoneUtils import nowutc, setAdjustedDate
33from MaKaC.common.utils import parseDateTime
34from MaKaC.plugins.Collaboration.collaborationTools import CollaborationTools
35from MaKaC.webinterface.user import UserListModificationBase,\
36    UserModificationBase
37
38
39## Base classes
40class CollaborationBase(ConferenceModifBase):
41    """ This base class stores the _CSBookingManager attribute
42        so that inheriting classes can use it.
43    """
44    def _checkParams(self):
45        ConferenceModifBase._checkParams(self) #sets self._target = self._conf = the Conference object
46        self._checkCollaborationEnabled()
47        self._CSBookingManager = self._conf.getCSBookingManager()
48   
49    def _checkCollaborationEnabled(self):
50        """ Checks if the Collaboration plugin system is active
51        """
52        if not PluginsHolder().hasPluginType("Collaboration"):
53            raise CollaborationServiceException("Collaboration plugin system is not active")
54       
55    def process(self):
56        try:
57            return ConferenceModifBase.process(self)
58        except CollaborationException, e:
59            raise CollaborationServiceException(e.getMsg(), str(e.getInner()))
60       
61class CollaborationBookingModifBase(CollaborationBase):
62    """ Base class for services that are passed a booking id.
63        It is stored in self._bookingId
64    """
65    def _checkParams(self):
66        CollaborationBase._checkParams(self)
67        if self._params.has_key('bookingId'):
68            self._bookingId = self._params['bookingId']
69            booking = self._CSBookingManager.getBooking(self._bookingId)
70            self._bookingType = booking.getType()
71            self._bookingPlugin = booking.getPlugin()
72           
73        else:
74            raise CollaborationException(_("Booking id not set when trying to modify a booking on meeting ") + str(self._conf.getId()) + _(" with the service ") + str(self.__class__) )
75       
76    def _checkProtection(self):
77        hasRights = RCCollaborationAdmin.hasRights(self) or \
78                    RCCollaborationPluginAdmin.hasRights(self, None, [self._bookingPlugin]) or \
79                    RCVideoServicesManager.hasRights(self, [self._bookingPlugin])
80       
81        if not hasRights:
82            CollaborationBase._checkProtection(self)
83
84class CollaborationAdminBookingModifBase(CollaborationBookingModifBase):
85   
86    def _checkProtection(self):
87        if not RCCollaborationAdmin.hasRights(self) and not RCCollaborationPluginAdmin.hasRights(self, None, [self._bookingPlugin]):
88            raise CollaborationException(_("You don't have the rights to perform this operation on this booking"))
89
90class AdminCollaborationBase(AdminService):
91   
92    def _checkParams(self):
93        AdminService._checkParams(self)
94        if not PluginsHolder().hasPluginType("Collaboration"):
95            raise CollaborationServiceException(_("Collaboration plugin system is not active"))
96
97    def _checkProtection(self):
98        if not RCCollaborationAdmin.hasRights(self, None):
99            AdminService._checkProtection(self)
100
101##! End of base classes
102
103
104class CollaborationCreateCSBooking(CollaborationBase):
105    """ Adds a new booking
106    """
107    def _checkParams(self):
108        CollaborationBase._checkParams(self)
109       
110        if 'type' in self._params:
111            self._type = self._params['type']
112        else:
113            raise CollaborationException(_("type parameter not set when trying to create a booking on meeting ") + str(self._conf.getId() ))
114       
115        if 'bookingParams' in self._params:
116            pm = ParameterManager(self._params)
117            self._bookingParams = pm.extract("bookingParams", pType=dict, allowEmpty = True)
118        else:
119            raise CollaborationException(_("Custom parameters for plugin ") + str(self._type) + _(" not set when trying to create a booking on meeting ") + str(self._conf.getId() ))
120       
121    def _checkProtection(self):
122        hasRights = RCCollaborationAdmin.hasRights(self) or \
123                    RCCollaborationPluginAdmin.hasRights(self, None, [self._type]) or \
124                    RCVideoServicesManager.hasRights(self, [self._type])
125           
126        if not hasRights:
127            CollaborationBase._checkProtection(self)
128   
129    def _getAnswer(self):
130        return DictPickler.pickle(self._CSBookingManager.createBooking(self._type, bookingParams = self._bookingParams),
131                                  timezone = self._conf.getTimezone())
132   
133class CollaborationRemoveCSBooking(CollaborationBookingModifBase):
134    """ Removes a booking
135    """
136    def _getAnswer(self):
137        return DictPickler.pickle(self._CSBookingManager.removeBooking(self._bookingId),
138                                  timezone = self._conf.getTimezone())
139       
140       
141class CollaborationEditCSBooking(CollaborationBookingModifBase):
142    """ Edits a booking
143    """
144    def _checkParams(self):
145        CollaborationBookingModifBase._checkParams(self)
146       
147        if self._params.has_key('bookingParams'):
148            pm = ParameterManager(self._params)
149            self._bookingParams = pm.extract("bookingParams", pType=dict, allowEmpty = True)
150        else:
151            raise CollaborationException(_("Custom parameters for booking ") + str(self._bookingId) + _(" not set when trying to edit a booking on meeting ") + str(self._conf.getId() ))
152
153    def _getAnswer(self):
154        return DictPickler.pickle(self._CSBookingManager.changeBooking(self._bookingId, self._bookingParams),
155                                  timezone = self._conf.getTimezone())
156   
157   
158class CollaborationStartCSBooking(CollaborationBookingModifBase):
159    """ Performs server-side actions when a booking is started
160    """
161    def _getAnswer(self):
162        return DictPickler.pickle(self._CSBookingManager.startBooking(self._bookingId),
163                                  timezone = self._conf.getTimezone())
164
165class CollaborationStopCSBooking(CollaborationBookingModifBase):
166    """ Performs server-side actions when a booking is started
167    """
168    def _getAnswer(self):
169        return DictPickler.pickle(self._CSBookingManager.stopBooking(self._bookingId),
170                                  timezone = self._conf.getTimezone())
171
172class CollaborationCheckCSBookingStatus(CollaborationBookingModifBase):
173    """ Performs server-side actions when a booking is started
174    """
175    def _getAnswer(self):
176        return DictPickler.pickle(self._CSBookingManager.checkBookingStatus(self._bookingId),
177                                  timezone = self._conf.getTimezone())
178       
179class CollaborationAcceptCSBooking(CollaborationAdminBookingModifBase):
180    """ Performs server-side actions when a booking is started
181    """
182    def _getAnswer(self):
183        return DictPickler.pickle(self._CSBookingManager.acceptBooking(self._bookingId),
184                                  timezone = self._conf.getTimezone())
185       
186class CollaborationRejectCSBooking(CollaborationAdminBookingModifBase):
187    """ Performs server-side actions when a booking is started
188    """
189    def _checkParams(self):
190        CollaborationAdminBookingModifBase._checkParams(self)
191        self._reason = self._params.get("reason", "")
192   
193    def _getAnswer(self):
194        return DictPickler.pickle(self._CSBookingManager.rejectBooking(self._bookingId, self._reason),
195                                  timezone = self._conf.getTimezone())
196       
197class CollaborationChangePluginManagersBase(CollaborationBase):
198   
199    def _checkParams(self):
200        CollaborationBase._checkParams(self)
201        if self._params.has_key('plugin'):
202            self._plugin = self._params['plugin']
203        else:
204            raise CollaborationException(_("Plugin name not set when trying to add a manager on event: ") + str(self._conf.getId()) + _(" with the service ") + str(self.__class__) )
205       
206    def _checkProtection(self):
207        if not RCVideoServicesManager.hasRights(self):
208            CollaborationBase._checkProtection(self)
209
210class CollaborationAddPluginManager(CollaborationChangePluginManagersBase, UserListModificationBase):
211   
212    def _checkParams(self):
213        CollaborationChangePluginManagersBase._checkParams(self)
214        UserListModificationBase._checkParams(self)
215       
216    def _getAnswer(self):
217        existingManagerIds = set([u.getId() for u in self._CSBookingManager.getPluginManagers(self._plugin)])
218        for u in self._avatars:
219            if not u.getId() in existingManagerIds:
220                self._CSBookingManager.addPluginManager(self._plugin, u)
221       
222        return True
223   
224
225class CollaborationRemovePluginManager(CollaborationChangePluginManagersBase, UserModificationBase):
226   
227    def _checkParams(self):
228        CollaborationChangePluginManagersBase._checkParams(self)
229        UserModificationBase._checkParams(self)
230       
231    def _getAnswer(self):
232        self._CSBookingManager.removePluginManager(self._plugin, self._targetUser)       
233        return True
234
235   
236class CollaborationBookingIndexQuery(AdminCollaborationBase):
237    """
238    """
239   
240    def _checkProtection(self):
241        if not RCCollaborationPluginAdmin.hasRights(self, None, "any"):
242            AdminCollaborationBase._checkProtection(self)
243           
244    def _checkParams(self):
245        AdminCollaborationBase._checkParams(self)
246        user = self.getAW().getUser()
247        if user: #someone is logged in. if not, AdminCollaborationBase's _checkProtection will take care of it
248            self._tz = user.getTimezone()
249           
250            try:
251                self._page = self._params.get("page", None)
252                self._resultsPerPage = self._params.get("resultsPerPage", None)
253                self._indexName = self._params['indexName']
254                self._viewBy = self._params['viewBy']
255                self._orderBy = self._params['orderBy']
256               
257                minKey = None
258                maxKey = None
259                if self._params['sinceDate']:
260                    minKey = setAdjustedDate(parseDateTime(self._params['sinceDate'].strip()), tz = self._tz)
261                if self._params['toDate']:
262                    maxKey = setAdjustedDate(parseDateTime(self._params['toDate'].strip()), tz = self._tz)
263                if self._params['fromTitle']:
264                    minKey = self._params['fromTitle'].strip()
265                if self._params['toTitle']:
266                    maxKey = self._params['toTitle'].strip()
267                if self._params['fromDays']:
268                    try:
269                        fromDays = int(self._params['fromDays'])
270                    except ValueError, e:
271                        raise CollaborationException(_("Parameter 'fromDays' is not an integer"), inner = e)
272                    minKey = nowutc() - timedelta(days = fromDays)
273                if self._params['toDays']:
274                    try:
275                        toDays = int(self._params['toDays'])
276                    except ValueError, e:
277                        raise CollaborationException(_("Parameter 'toDays' is not an integer"), inner = e)
278                    maxKey = nowutc() + timedelta(days = toDays)
279                   
280                self._minKey = minKey
281                self._maxKey = maxKey
282                   
283                self._onlyPending = self._params['onlyPending']
284                categoryId = self._params['categoryId'].strip()
285                if categoryId:
286                    self._categoryId = categoryId
287                else:
288                    self._categoryId = None
289                conferenceId = self._params['conferenceId'].strip()
290                if conferenceId:
291                    self._conferenceId = conferenceId
292                else:
293                    self._conferenceId = None
294                   
295            except KeyError, e:
296                raise CollaborationException(_("One of the necessary parameters to query the booking index is missing"), inner = e)
297       
298    def _getAnswer(self):
299        ci = IndexesHolder().getById('collaboration')
300       
301        return ci.getBookings(self._indexName,
302                              self._viewBy,
303                              self._orderBy,
304                              self._minKey,
305                              self._maxKey,
306                              tz = self._tz,
307                              onlyPending = self._onlyPending,
308                              conferenceId = self._conferenceId,
309                              categoryId = self._categoryId,
310                              pickle = True,
311                              dateFormat='%a %d %b %Y',
312                              page = self._page,
313                              resultsPerPage = self._resultsPerPage)
314   
315class CollaborationCustomPluginService(CollaborationBase):
316    """ Class to support plugin-defined services.
317        Plugins have to call 'collaboration.pluginService' and
318        specify a 'plugin' and 'service' arguments.
319        Then they have to create a class that inherits from
320        CollaborationPluginServiceBase with the same name
321        as the 'service' argument, plus 'Service' at the end.
322        The classes can have _checkParams, _checkProtetion methods,
323        and must have a _getAnswer method.
324        They will have the following attributes available:
325        _params, _aw, _conf, _target, _CSBookingManager.
326    """
327   
328    def _checkParams(self):
329        CollaborationBase._checkParams(self)
330       
331        self._pluginName = self._params.pop('plugin')
332        if not self._pluginName:
333            raise CollaborationException(_("No 'plugin' paramater in CollaborationPluginService"))
334       
335        serviceName = self._params.pop('service')
336        if not serviceName:
337            raise CollaborationException(_("No 'service' paramater in CollaborationPluginService"))
338       
339        self._serviceClass = CollaborationTools.getServiceClass(self._pluginName, serviceName)
340        if not self._serviceClass:
341            raise CollaborationException(_("Service " + str(serviceName) + _("Service not found for plugin ") + str(self._pluginName) + _("in CollaborationPluginService")))
342   
343    def _checkProtection(self):
344        hasRights = RCCollaborationAdmin.hasRights(self) or \
345                    RCCollaborationPluginAdmin.hasRights(self, None, [self._pluginName]) or \
346                    RCVideoServicesManager.hasRights(self, [self._pluginName])
347           
348        if not hasRights:
349            CollaborationBase._checkProtection(self)
350   
351    def _getAnswer(self):
352        serviceObject = self._serviceClass(self._params, self._aw)
353        serviceObject._checkParams()
354        serviceObject._checkProtection()
355        return serviceObject._getAnswer()
356   
357
358class CollaborationPluginServiceBase(CollaborationBase):
359    """ Base class that plugin-defined services need to inherit from.
360        The _params and _aw attributes will be available from them,
361        and also _target and _conf and _CSBookingManager from CollaborationBase.
362        If they implement a _checkParams method, they need to call
363        their parent's (this class's) method first.
364        This class _checkParam method calls CollaborationBase's
365    """
366
367    def __init__(self, params, aw):
368        self._params = params
369        self._aw = aw
370       
371    def _checkParams(self):
372        CollaborationBase._checkParams(self)
373   
374    def _checkProtection(self):
375        pass
376   
377    def _getAnswer(self):
378        raise CollaborationException("No answer was returned")
379   
380       
381class CollaborationCreateTestCSBooking(CollaborationCreateCSBooking):
382    """ Service that creates a 'test' booking for performance test.
383        Avoids to use any of the plugins except DummyPlugin
384    """
385    def _checkParams(self):
386        CollaborationBase._checkParams(self)
387               
388        if 'bookingParams' in self._params:
389            pm = ParameterManager(self._params)
390            self._bookingParams = pm.extract("bookingParams", pType=dict, allowEmpty = True)
391        else:
392            raise CollaborationException(_("Custom parameters for plugin ") + str(self._type) + _(" not set when trying to create a booking on meeting ") + str(self._conf.getId() ))
393   
394    def _getAnswer(self):
395        return DictPickler.pickle(self._CSBookingManager.createTestBooking(bookingParams = self._bookingParams),
396                                  timezone = self._conf.getTimezone())
397
398
399methodMap = {
400    "createCSBooking": CollaborationCreateCSBooking,
401    "removeCSBooking": CollaborationRemoveCSBooking,
402    "editCSBooking": CollaborationEditCSBooking,
403    "startCSBooking": CollaborationStartCSBooking,
404    "stopCSBooking": CollaborationStopCSBooking,
405    "checkCSBookingStatus": CollaborationCheckCSBookingStatus,
406    "acceptCSBooking": CollaborationAcceptCSBooking,
407    "rejectCSBooking": CollaborationRejectCSBooking,
408    "bookingIndexQuery": CollaborationBookingIndexQuery,
409    "addPluginManager": CollaborationAddPluginManager,
410    "removePluginManager": CollaborationRemovePluginManager,
411    "pluginService": CollaborationCustomPluginService
412}
Note: See TracBrowser for help on using the repository browser.