source: indico/indico/MaKaC/plugins/Collaboration/Vidyo/api/operations.py @ b9c821

hello-world-walkthroughipv6v0.98-seriesv0.98.2v0.98.3v0.98b2v0.99v1.0v1.1
Last change on this file since b9c821 was b9c821, checked in by Jose Benito <jose.benito.gonzalez@…>, 18 months ago

[FTR] Added permissions check creating Vydio room.

  • Added a new option with users and groups authorised.
  • Check in creating and modifying the booking this permissions.
  • The permissions are checked for the booking owner.
  • Property mode set to 100644
File size: 11.3 KB
Line 
1# -*- coding: utf-8 -*-
2##
3## This file is part of CDS Indico.
4## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
5##
6## CDS Indico is free software; you can redistribute it and/or
7## modify it under the terms of the GNU General Public License as
8## published by the Free Software Foundation; either version 2 of the
9## License, or (at your option) any later version.
10##
11## CDS Indico is distributed in the hope that it will be useful, but
12## WITHOUT ANY WARRANTY; without even the implied warranty of
13## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14## General Public License for more details.
15##
16## You should have received a copy of the GNU General Public License
17## along with CDS Indico; if not, write to the Free Software Foundation, Inc.,
18## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
19
20from MaKaC.plugins.Collaboration.Vidyo.common import getVidyoOptionValue, VidyoError, VidyoTools
21from MaKaC.plugins.Collaboration.Vidyo.api.factory import SOAPObjectFactory
22from MaKaC.plugins.Collaboration.Vidyo.api.api import AdminApi, UserApi
23from MaKaC.webinterface.rh.collaboration import RCCollaborationAdmin, RCVideoServicesUser
24from suds import WebFault
25
26class VidyoOperations(object):
27    """ This class has several class methods,
28        each of which represents a high-level operation,
29        which sometimes involve several actual SOAP service calls.
30
31        The objective is to not clutter the CSBooking methods with API logic.
32        None of these methods should change the Indico DB, so they should not set any value on any object.
33    """
34
35    @classmethod
36    def createRoom(cls, booking):
37        """ Attempts to create a public room in Vidyo.
38            Returns None on success. Will also set booking.setAccountName() if success, with the Indico & Vidyo login used successfully.
39            Returns a VidyoError instance if there are problems.
40
41            :param booking: the CSBooking object inside which we try to create the room
42            :type booking: MaKaC.plugins.Collaboration.Vidyo.collaboration.CSBooking
43        """
44        #we extract the different parameters
45        confId = booking.getConference().getId()
46        bookingId = booking.getId()
47        roomName = booking.getBookingParamByName("roomName")
48        description = booking.getBookingParamByName("roomDescription")
49        owner = booking.getOwnerObject()
50        pin = booking.getPin()
51
52        #we obtain the unicode object with the proper format for the room name
53        roomNameForVidyo = VidyoTools.roomNameForVidyo(roomName, confId)
54        if isinstance(roomNameForVidyo, VidyoError):
55            return roomNameForVidyo
56
57        #we turn the description into a unicode object
58        description = VidyoTools.descriptionForVidyo(description)
59        if isinstance(description, VidyoError):
60            return description
61
62        #we obtain the most probable extension
63        #TODO: there's a length limit for extensions, check this
64        baseExtension = getVidyoOptionValue("prefix") + confId
65        extension = baseExtension
66        extensionSuffix = 1
67
68        #we produce the list of possible account names. We will loop through them to attempt to create the room
69        possibleLogins = VidyoTools.getAvatarLoginList(owner)
70        if not possibleLogins:
71            return VidyoError("userHasNoAccounts", "create")
72
73        roomCreated = False
74        loginToUse = 0
75        while not roomCreated and loginToUse < len(possibleLogins):
76            #we loop changing the ownerName and the extension until room is created
77
78            newRoom = SOAPObjectFactory.createRoom(roomNameForVidyo, description, possibleLogins[loginToUse], extension, pin)
79            try:
80                AdminApi.addRoom(newRoom, confId, bookingId)
81                roomCreated = True
82
83            except WebFault, e:
84                faultString = e.fault.faultstring
85
86                if faultString.startswith('Room exist for name'):
87                    return VidyoError("duplicated", "create")
88
89                elif faultString.startswith('Member not found for ownerName'):
90                    loginToUse = loginToUse + 1
91
92                elif faultString.startswith('Room exist for extension'):
93                    extension = baseExtension + str(extensionSuffix)
94                    extensionSuffix = extensionSuffix + 1
95                else:
96                    raise
97
98        #if we could not create the room, the owner did not have any Vidyo accounts
99        if not roomCreated and loginToUse == len(possibleLogins):
100            return VidyoError("badOwner", "create")
101
102        # we retrieve the just created room; we need to do this because Vidyo will have
103        # added extra data like the room id, the url
104        searchFilter = SOAPObjectFactory.createFilter('admin', extension)
105        answer = AdminApi.getRooms(searchFilter, confId, bookingId)
106        createdRooms = answer.room
107
108        for room in createdRooms:
109            if str(room.extension) == extension:
110                return room
111
112        return None
113
114
115    @classmethod
116    def modifyRoom(cls, booking, oldBookingParams):
117
118        #we extract the different parameters
119        confId = booking.getConference().getId()
120        bookingId = booking.getId()
121        roomId = booking.getRoomId()
122        roomName = booking.getBookingParamByName("roomName")
123        description = booking.getBookingParamByName("roomDescription")
124        newOwner = booking.getOwnerObject() #an avatar object
125        ownerAccountName = booking.getOwnerAccount() #a str
126        oldOwner = oldBookingParams["owner"] #an IAvatarFossil fossil
127        pin = booking.getPin()
128
129        #we obtain the unicode object with the proper format for the room name
130        roomNameForVidyo = VidyoTools.roomNameForVidyo(roomName, confId)
131        if isinstance(roomNameForVidyo, VidyoError):
132            return roomNameForVidyo
133
134        #we turn the description into a unicode object
135        description = VidyoTools.descriptionForVidyo(description)
136        if isinstance(description, VidyoError):
137            return description
138
139        #(the extension will not change)
140
141        #we check if the owner has changed. If not, we reuse the same accountName
142        useOldAccountName = True
143        possibleLogins = []
144        if newOwner.getId() != oldOwner["id"]:
145            useOldAccountName = False
146            #we produce the list of possible account names. We will loop through them to attempt to create the room
147            possibleLogins = VidyoTools.getAvatarLoginList(newOwner)
148            if not possibleLogins:
149                return VidyoError("userHasNoAccounts", "modify")
150
151
152        roomModified = False
153        loginToUse = 0
154        while not roomModified and (useOldAccountName or loginToUse < len(possibleLogins)):
155
156            if not useOldAccountName:
157                ownerAccountName = possibleLogins[loginToUse]
158
159            newRoom = SOAPObjectFactory.createRoom(roomNameForVidyo, description, ownerAccountName, booking.getExtension(), pin)
160            try:
161                AdminApi.updateRoom(roomId, newRoom, confId, bookingId)
162                roomModified = True
163
164            except WebFault, e:
165                faultString = e.fault.faultstring
166
167                if faultString.startswith('Room not exist for roomID'):
168                    return VidyoError("unknownRoom", "modify")
169
170                elif faultString.startswith('Room exist for name'):
171                    return VidyoError("duplicated", "modify")
172
173                elif faultString.startswith('Member not found for ownerName'):
174                    if useOldAccountName:
175                        #maybe the user was deleted between the time the room was created and now
176                        return VidyoError("badOwner", "modify")
177                    else:
178                        loginToUse = loginToUse + 1
179
180                else:
181                    raise
182
183        #if we could not create the room, the owner did not have any Vidyo accounts
184        if not roomModified and loginToUse == len(possibleLogins):
185            return VidyoError("badOwner", "modify")
186
187
188        # we retrieve the just created room; we need to do this because Vidyo will have
189        # added extra data like the room id, the url
190        try:
191            modifiedRoom = AdminApi.getRoom(roomId, confId, bookingId)
192        except WebFault, e:
193            faultString = e.fault.faultstring
194            if faultString.startswith('Room not found for roomID'):
195                return VidyoError("unknownRoom", "modify")
196
197        return modifiedRoom
198
199
200    @classmethod
201    def queryRoom(cls, booking, roomId):
202        """ Searches for room information via the admin api's getRoom function and the
203            user api's search function (currently the admin api's getRoom is not reliable
204            to retrieve name, description and groupName).
205            Tries to find the room providing the extension as query (since only
206            the room name and extension are checked by the search op).
207            Returns None if not found
208        """
209        confId = booking.getConference().getId()
210        bookingId = booking.getId()
211
212        roomId = booking.getRoomId()
213
214        try:
215            adminApiRoom = AdminApi.getRoom(roomId, confId, bookingId)
216        except WebFault, e:
217            faultString = e.fault.faultstring
218            if faultString.startswith('Room not found for roomID'):
219                return VidyoError("unknownRoom", "checkStatus")
220            else:
221                raise
222
223        extension = str(adminApiRoom.extension)
224
225        searchFilter = SOAPObjectFactory.createFilter('user', extension)
226        userApiAnswer = UserApi.search(searchFilter, confId, bookingId)
227        foundEntities = userApiAnswer.Entity
228
229        userApiRoom = None
230        for entity in foundEntities:
231            if str(entity.extension) == extension and str(entity.entityID) == roomId:
232                userApiRoom = entity
233
234        return (adminApiRoom, userApiRoom)
235
236
237    @classmethod
238    def deleteRoom(cls, booking, roomId):
239        confId = booking.getConference().getId()
240        bookingId = booking.getId()
241
242        try:
243            AdminApi.deleteRoom(roomId, confId, bookingId)
244        except WebFault, e:
245            faultString = e.fault.faultstring
246            if faultString.startswith('Room not found for roomID'):
247                return VidyoError("unknownRoom", "delete")
248            else:
249                raise
250
251    @classmethod
252    def connectRoom(cls, booking, roomId, extension):
253        confId = booking.getConference().getId()
254        bookingId = booking.getId()
255        try:
256            searchFilter = SOAPObjectFactory.createFilter('user', extension)
257            userApiAnswer = UserApi.search(searchFilter, confId, bookingId)
258            legacyMember = userApiAnswer.Entity[0].entityID
259            AdminApi.connectRoom(roomId, confId, bookingId, legacyMember)
260        except WebFault, e:
261            faultString = e.fault.faultstring
262            if faultString.startswith('ConferenceID is invalid'):
263                return VidyoError("unknownRoom", "connect")
264            if faultString.startswith('Failed to Invite to Conference'):
265                message = _("The connection has failed.")
266                if getVidyoOptionValue("contactSupport"):
267                    message += _("""\nPlease try again or contact %s for help.""")%getVidyoOptionValue("contactSupport")
268                return VidyoError("connectFailed", "connect", message)
269            else:
270                raise
Note: See TracBrowser for help on using the repository browser.