VC/Vidyo: Use new users

This commit is contained in:
Adrian Moennich 2015-05-08 19:42:15 +02:00
parent ef1bb8988e
commit 80001c40a0
11 changed files with 65 additions and 46 deletions

View File

@ -72,9 +72,8 @@ class VCRoomForm(VCRoomFormBase, VidyoAdvancedFormMixin):
'(audio and video)'))
def validate_owner(self, field):
avatar = retrieve_principal(field.data)
if not avatar:
user = retrieve_principal(field.data, allow_groups=False, legacy=False)
if not user:
raise ValidationError(_("Unable to find this user in Indico."))
if not next(iter_user_identities(avatar), None):
if not next(iter_user_identities(user), None):
raise ValidationError(_("This user does not have a suitable account to use Vidyo."))

View File

@ -0,0 +1,26 @@
"""Use FK for owned_by_id and make it NOT NULL
Revision ID: 3f376d68efc8
Revises: 3520616f8ff7
Create Date: 2015-05-08 19:34:25.491411
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = '3f376d68efc8'
down_revision = '3520616f8ff7'
def upgrade():
op.alter_column('vidyo_extensions', 'owned_by_id', nullable=False, schema='plugin_vc_vidyo')
op.create_foreign_key(None,
'vidyo_extensions', 'users',
['owned_by_id'], ['id'],
source_schema='plugin_vc_vidyo', referent_schema='users')
def downgrade():
op.drop_constraint('fk_vidyo_extensions_owned_by_id_users', 'vidyo_extensions', schema='plugin_vc_vidyo')
op.alter_column('vidyo_extensions', 'owned_by_id', nullable=True, schema='plugin_vc_vidyo')

View File

@ -18,7 +18,6 @@ from __future__ import unicode_literals
from indico.core.db.sqlalchemy import db
from indico.util.string import return_ascii
from MaKaC.user import AvatarHolder
class VidyoExtension(db.Model):
@ -37,7 +36,9 @@ class VidyoExtension(db.Model):
)
owned_by_id = db.Column(
db.Integer,
db.ForeignKey('users.users.id'),
index=True,
nullable=False
)
vc_room = db.relationship(
'VCRoom',
@ -45,15 +46,16 @@ class VidyoExtension(db.Model):
lazy=False
)
@property
def owned_by_user(self):
"""The Avatar who owns the vidyo room."""
return AvatarHolder().getById(str(self.owned_by_id))
@owned_by_user.setter
def owned_by_user(self, user):
self.owned_by_id = int(user.getId())
#: The user who owns the Vidyo room
owned_by_user = db.relationship(
'User',
lazy=True,
backref=db.backref(
'vc_rooms_vidyo',
lazy='dynamic'
)
)
@return_ascii
def __repr__(self):
return '<VidyoExtension({}, {}, {})>'.format(self.vc_room, self.extension, self.owned_by_id)
return '<VidyoExtension({}, {}, {})>'.format(self.vc_room, self.extension, self.owned_by_user)

View File

@ -158,7 +158,7 @@ class VidyoPlugin(VCPluginMixin, IndicoPlugin):
"""
client = AdminClient(self.settings)
owner = retrieve_principal(vc_room.data['owner'])
owner = retrieve_principal(vc_room.data['owner'], allow_groups=False, legacy=False)
login_gen = iter_user_identities(owner)
login = next(login_gen, None)
@ -225,8 +225,7 @@ class VidyoPlugin(VCPluginMixin, IndicoPlugin):
except RoomNotFoundAPIException:
raise VCRoomNotFoundError(_("This room has been deleted from Vidyo"))
owner = retrieve_principal(vc_room.data['owner'])
owner = retrieve_principal(vc_room.data['owner'], allow_groups=False, legacy=False)
changed_owner = room_obj.ownerName not in iter_user_identities(owner)
if changed_owner:
login_gen = iter_user_identities(owner)
@ -330,18 +329,18 @@ class VidyoPlugin(VCPluginMixin, IndicoPlugin):
return defaults
def can_manage_vc_room(self, user, room):
return (user == retrieve_principal(room.data['owner']) or
return (user == retrieve_principal(room.data['owner'], allow_groups=False, legacy=False) or
super(VidyoPlugin, self).can_manage_vc_room(user, room))
def _merge_users(self, user, merged, **kwargs):
super(VidyoPlugin, self)._merge_users(user, merged, **kwargs)
new_id = int(user.id)
old_id = int(merged.id)
for ext in VidyoExtension.find(owned_by_id=old_id):
ext.owned_by_id = new_id
target = user.user
source = merged.user
for ext in VidyoExtension.find(owned_by_user=source):
ext.owned_by_user = target
ext.vc_room.data['owner'] = user.user.as_principal
flag_modified(ext.vc_room, 'data')
def get_notification_cc_list(self, action, vc_room, event):
owner = retrieve_principal(vc_room.data['owner'])
return {owner.getEmail()} if owner else set()
owner = retrieve_principal(vc_room.data['owner'], allow_groups=False, legacy=False)
return {owner.email} if owner else set()

View File

@ -15,7 +15,7 @@ $(function() {
contentType: 'application/json',
data: JSON.stringify({
data: {
owner: ['Avatar', $('body').data('userId')]
owner: ['User', $('body').data('userId')]
}
})
}).done(function(result) {

View File

@ -49,22 +49,15 @@ def find_old_vidyo_rooms(max_room_event_age):
def notify_moderator(plugin, vc_room):
"""Notifies about the deletion of a Vidyo room from the Vidyo server.
:param room: the vc_room
:param event: the event
:param user: the user performing the action
"""
user = retrieve_principal(vc_room.data['owner'])
"""Notifies about the deletion of a Vidyo room from the Vidyo server."""
user = retrieve_principal(vc_room.data['owner'], allow_groups=False, legacy=False)
tpl = get_plugin_template_module('emails/remote_deleted.html', plugin=plugin, vc_room=vc_room, event=None,
vc_room_event=None, user=user)
_send('delete', user, plugin, None, vc_room, tpl.get_subject(), tpl.get_body())
class VidyoCleanupTask(PeriodicUniqueTask):
"""Gets rid of 'old' Vidyo rooms (not used in recent events)
"""
"""Gets rid of 'old' Vidyo rooms (not used in recent events)"""
DISABLE_ZODB_HOOK = True
@property

View File

@ -1,5 +1,5 @@
{% macro render_make_me_moderator(event, vc_room, event_vc_room, extra_classes='') %}
{% if event.canModify(session.avatar) and session.avatar.id != vc_room.data['owner'][1] %}
{% if event.canModify(session.user) and session.user.id != vc_room.data['owner'][1] %}
<a class="i-button highlight arrow {{ extra_classes }}" data-toggle="dropdown"></a>
<ul class="dropdown" data-level="level1">
<li>

View File

@ -1,5 +1,5 @@
{% from '_clipboard_input.html' import clipboard_input %}
{% set owner = retrieve_principal(vc_room.data.owner) %}
{% set owner = retrieve_principal(vc_room.data.owner, allow_groups=False, legacy=False) %}
{% set phone_link = settings.get('vidyo_phone_link') %}
<dl class="zeroclicboard-init">
<dt>{% trans %}Name{% endtrans %}</dt>
@ -12,7 +12,7 @@
{% endif %}
{% if owner %}
<dt>{% trans %}Moderator{% endtrans %}</dt>
<dd>{{ owner.getFullName() }}</dd>
<dd>{{ owner.full_name }}</dd>
{% endif %}
{% if event_vc_room.data.show_pin %}
<dt>{% trans %}Room PIN{% endtrans %}</dt>

View File

@ -1,6 +1,6 @@
{% from '_password.html' import password %}
{% from '_clipboard_input.html' import clipboard_input %}
{% set owner = retrieve_principal(vc_room.data.owner) %}
{% set owner = retrieve_principal(vc_room.data.owner, allow_groups=False, legacy=False) %}
{% set phone_link = settings.get('vidyo_phone_link') %}
<dl class="details-container zeroclicboard-init">
<dt>{% trans %}Description{% endtrans %}</dt>
@ -10,7 +10,7 @@
<dt>{% trans %}Moderator{% endtrans %}</dt>
<dd>
{% if owner %}
{{ owner.getFullName() }}
{{ owner.full_name }}
{% else %}
{{ vc_room.data.owner_account }} <em>(deleted)</em>
{% endif %}

View File

@ -34,24 +34,24 @@ authenticators_re = re.compile(r'\s*,\s*')
def get_auth_users():
"""Returns a list of authorized users
:return: list of Avatar/Group objects
:return: list of User/GroupProxy objects
"""
from indico_vc_vidyo.plugin import VidyoPlugin
return retrieve_principals(VidyoPlugin.settings.get('authorized_users'))
return retrieve_principals(VidyoPlugin.settings.get('authorized_users'), legacy=False)
def is_auth_user(user):
"""Checks if a user is authorized"""
return any(principal.containsUser(user) for principal in get_auth_users())
return any(user in principal for principal in get_auth_users())
def iter_user_identities(avatar):
def iter_user_identities(user):
"""Iterates over all existing user identities that can be used with Vidyo"""
from indico_vc_vidyo.plugin import VidyoPlugin
providers = authenticators_re.split(VidyoPlugin.settings.get('authenticators'))
done = set()
for provider in providers:
for _, identifier in avatar.user.iter_identifiers(check_providers=True, providers={provider}):
for _, identifier in user.iter_identifiers(check_providers=True, providers={provider}):
if identifier in done:
continue
done.add(identifier)

View File

@ -122,7 +122,7 @@ class VidyoImporter(Importer):
'moderation_pin': getattr(booking, '_moderatorPin', ''),
'vidyo_id': booking._roomId,
'url': booking._url,
'owner': ('Avatar', booking._owner.id),
'owner': ('User', int(booking._owner.id)),
'owner_identity': booking._ownerVidyoAccount,
'auto_mute': booking_params.get('autoMute', True)
}