mirror of
https://github.com/lucaspalomodevelop/indico-plugins.git
synced 2026-03-18 17:54:47 +00:00
VC/Vidyo: VC Room refresh feature
This commit is contained in:
parent
e3e3e3e82b
commit
62ef1e9b12
@ -72,6 +72,13 @@ class AdminClient(ClientBase):
|
||||
def delete_room(self, room_id):
|
||||
self.soap.deleteRoom(room_id)
|
||||
|
||||
def get_automute(self, room_id):
|
||||
answer = self.soap.getRoomProfile(room_id)
|
||||
if answer:
|
||||
return answer.roomProfileName == AUTOMUTE_API_PROFILE
|
||||
else:
|
||||
return False
|
||||
|
||||
def set_automute(self, room_id, status):
|
||||
if status:
|
||||
self.soap.setRoomProfile(room_id, AUTOMUTE_API_PROFILE)
|
||||
|
||||
@ -36,7 +36,7 @@ from indico.web.forms.widgets import CKEditorWidget
|
||||
|
||||
from indico_vc_vidyo.api import AdminClient
|
||||
from indico_vc_vidyo.forms import VCRoomForm
|
||||
from indico_vc_vidyo.util import iter_user_identities, iter_extensions
|
||||
from indico_vc_vidyo.util import iter_user_identities, iter_extensions, update_room_from_obj
|
||||
from indico_vc_vidyo.models.vidyo_extensions import VidyoExtension
|
||||
|
||||
|
||||
@ -181,9 +181,9 @@ class VidyoPlugin(VCPluginMixin, IndicoPlugin):
|
||||
changed_moderator = room_obj.ownerName not in iter_user_identities(moderator)
|
||||
if changed_moderator:
|
||||
login_gen = iter_user_identities(moderator)
|
||||
login = next(login_gen)
|
||||
login = next(login_gen, None)
|
||||
if login is None:
|
||||
raise VCRoomError(_("No valid account found for this moderator"), 'moderator')
|
||||
raise VCRoomError(_("No valid account found for this moderator"), field='moderator')
|
||||
room_obj.ownerName = login
|
||||
|
||||
room_obj.name = vc_room.name
|
||||
@ -220,18 +220,27 @@ class VidyoPlugin(VCPluginMixin, IndicoPlugin):
|
||||
raise
|
||||
|
||||
else:
|
||||
updated_room = self.get_room(vc_room)
|
||||
updated_room_obj = self.get_room(vc_room)
|
||||
|
||||
vc_room.data.update({
|
||||
'url': updated_room.RoomMode.roomURL,
|
||||
'owner_identity': updated_room.ownerName
|
||||
})
|
||||
vc_room.vidyo_extension = VidyoExtension(vc_room_id=vc_room.id, value=int(updated_room.extension))
|
||||
update_room_from_obj(self.settings, vc_room, updated_room_obj)
|
||||
flag_modified(vc_room, 'data')
|
||||
|
||||
client.set_automute(vidyo_id, vc_room.data['auto_mute'])
|
||||
break
|
||||
|
||||
def refresh_room(self, vc_room, event):
|
||||
client = AdminClient(self.settings)
|
||||
try:
|
||||
room_obj = self.get_room(vc_room)
|
||||
except WebFault as err:
|
||||
err_msg = err.fault.faultstring
|
||||
if not err_msg.startswith('Room not found for roomID'):
|
||||
raise
|
||||
|
||||
update_room_from_obj(self.settings, vc_room, room_obj)
|
||||
vc_room.data['auto_mute'] = client.get_automute(room_obj.roomID)
|
||||
flag_modified(vc_room, 'data')
|
||||
|
||||
def delete_room(self, vc_room, event):
|
||||
client = AdminClient(self.settings)
|
||||
|
||||
|
||||
@ -16,7 +16,10 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from indico.util.user import retrieve_principals
|
||||
from indico.util.user import retrieve_principals, principal_to_tuple
|
||||
from indico.core.config import Config
|
||||
|
||||
from MaKaC.authentication.AuthenticationMgr import AuthenticatorMgr
|
||||
|
||||
|
||||
def get_auth_users():
|
||||
@ -43,10 +46,45 @@ def iter_user_identities(avatar):
|
||||
for identity in avatar.getIdentityByAuthenticatorId(auth))
|
||||
|
||||
|
||||
def get_avatar_from_identity(settings, identity):
|
||||
"""Get an actual avatar object from an auth identity"""
|
||||
authenticators = list(auth.strip() for auth in settings.get('authenticators').split(','))
|
||||
return next((avatar for auth_id, avatar in AuthenticatorMgr().getAvatarByLogin(identity, authenticators).iteritems()
|
||||
if avatar is not None), None)
|
||||
|
||||
|
||||
def iter_extensions(prefix, event_id):
|
||||
"""Return extension (prefix + event_id) with an optional suffix which is
|
||||
incremented step by step in case of collision
|
||||
"""
|
||||
extension = '{prefix}{event_id}'.format(prefix=prefix, event_id=event_id,)
|
||||
yield extension
|
||||
suffix = 1
|
||||
while True:
|
||||
yield '{extension}{suffix}'.format(extension=extension, suffix=suffix)
|
||||
suffix += 1
|
||||
|
||||
|
||||
def update_room_from_obj(settings, vc_room, room_obj):
|
||||
"""Updates a VCRoom DB object using a SOAP room object returned by the API"""
|
||||
config = Config.getInstance()
|
||||
|
||||
vc_room.name = room_obj.name
|
||||
|
||||
if room_obj.ownerName != vc_room.data['owner_identity']:
|
||||
print room_obj.ownerName
|
||||
avatar = get_avatar_from_identity(settings, room_obj.ownerName)
|
||||
# if the moderator does not exist any more (e.g. was changed on the server),
|
||||
# use the janitor user as a placeholder
|
||||
vc_room.data['moderator'] = (('Avatar', config.getJanitorUserId()) if avatar is None
|
||||
else principal_to_tuple(avatar))
|
||||
|
||||
vc_room.data.update({
|
||||
'description': room_obj.description,
|
||||
'vidyo_id': unicode(room_obj.roomID),
|
||||
'url': room_obj.RoomMode.roomURL,
|
||||
'owner_identity': room_obj.ownerName,
|
||||
'room_pin': room_obj.RoomMode.roomPIN if room_obj.RoomMode.hasPIN else "",
|
||||
'moderator_pin': room_obj.RoomMode.moderatorPIN if room_obj.RoomMode.hasModeratorPIN else "",
|
||||
})
|
||||
vc_room.vidyo_extension.value = int(room_obj.extension)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user