Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backend/room wsc #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions backend_modules/rooms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: UTF-8 -*-

# COPYRIGHT (c) 2016 Cristóbal Ganter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should license this module as your own.

#
# GNU AFFERO GENERAL PUBLIC LICENSE
# Version 3, 19 November 2007
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from .wsclass import RoomsWSC # noqa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import is not used here

from . import patches # noqa
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see no reason to use noqa here.


class RoomIsNotDefined(AttributeError):
"""Raise when ``room`` is not defined.

``course`` should be defined in the current instance of
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

room should be defined ...
copy paste error

:class:`~controller.MSGHandler`.

.. automethod:: __init__
"""

def __init__(self, *args):
"""Initialize a new CourseIsNotDefined exception."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, bad copy paste

super().__init__(
'Attempted to use the `course` attribute, but '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bad copy paste

'the attribute is not assigned.',
*args
)
47 changes: 47 additions & 0 deletions backend_modules/rooms/patches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: UTF-8 -*-

# COPYRIGHT (c) 2016 Cristóbal Ganter
#
# GNU AFFERO GENERAL PUBLIC LICENSE
# Version 3, 19 November 2007
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from controller import MSGHandler
from src.db import Room
from .. import router
from .wsclass import RoomsWSC

MSGHandler._room = None

@property
def room(self):
"""Current room asociated with this MSGHandler."""
return self._room

@room.setter
def room(self, new_room):
self._room = new_room
self.room_msg_type = \
'message.filter.room({})'.format(new_room.id)
router_object = self.ws_objects[
router.RouterWSC]
rooms_object = self.ws_objects[RoomsWSC]

rooms_object.register_action_in(
self.room_msg_type,
action=router_object.to_local,
channels={'d'}
)
MSGHandler.room = room
29 changes: 29 additions & 0 deletions backend_modules/rooms/wsclass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: UTF-8 -*-

# COPYRIGHT (c) 2016 Cristóbal Ganter
#
# GNU AFFERO GENERAL PUBLIC LICENSE
# Version 3, 19 November 2007
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from tornado.gen import coroutine

import src
from src.wsclass import subscribe
from src.db import Course, User


class RoomsWSC(src.wsclass.WSClass):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why is this necessary.

pass
46 changes: 46 additions & 0 deletions panels/user/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,52 @@ def load_user(self, token):
)
raise ite from norfdb

@subscribe('message.filter.student', 'l')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be part of this branch.

@coroutine
def redirect_message_if_user_is_student(
self, message, content=True):
"""Redirects a message if the user is a student.

This coroutine redirects a message to the local
channel only if the current user is a student.

:param dict message:
The message that should be redirected if the
user is a student.

:param bool content:
If ``True``, just the object corresponding to
the ``'content'`` key of ``message`` will be
sent.
If ``False``, the whole message will be sent.

:raises MalformedMessageError:
If ``content`` is ``True``, but ``message``
doesn't have the ``'content'`` key.

:raises NotDictError:
If ``message`` is not a dictionary.

:raises NoMessageTypeError:
If the message or it's content doesn't have the
``'type'`` key.

:raises NoActionForMsgTypeError:
If ``send_function`` of the ``PubSub`` object
wasn't specified during object creation and
there's no registered action for this message
type.

:raises AttributeError:
If the user is not yet loaded or if the user is
``None``.
"""
try:
if self.handler.user.status == 'seat':
self.redirect_to('l', message, content)
except:
raise

@subscribe('teacherMessage', 'l')
@coroutine
def redirect_message_if_user_is_teacher(
Expand Down