예제 #1
0
    def context(self):
        """See soc.views.template.Template.context for full specification."""
        assert access_checker.isSet(self.data.conversation)
        assert access_checker.isSet(self.data.user)

        query = gciconversation_logic.queryConversationUserForConversationAndUser(
            self.data.conversation.key, ndb.Key.from_old_key(self.data.user.key())
        )
        conv_user_results = query.fetch(1)
        assert conv_user_results

        conv_user = conv_user_results[0]

        self.data.redirect.id()

        url = self.data.redirect.urlOf(url_names.GCI_CONVERSATION_NOTIFICATION_TOGGLE)

        enable_notifications = toggle_button_view.ToggleButtonTemplate(
            self.data,
            "on_off",
            translation.ugettext("Enable Notifications"),
            "notifications-enabled",
            url,
            checked=conv_user.enable_notifications,
            help_text=self.DEF_ENABLE_NOTIFICATIONS_HELP,
            labels={"checked": "Yes", "unchecked": "No"},
        )
        self.toggle_buttons.append(enable_notifications)

        return {"title": translation.ugettext("Conversation Actions"), "toggle_buttons": self.toggle_buttons}
예제 #2
0
  def isUserInConversation(self):
    """Checks if the user is part of a conversation."""
    assert access_checker.isSet(self.data.conversation)
    assert access_checker.isSet(self.data.user)

    query = gciconversation_logic.queryConversationUserForConversationAndUser(
        self.data.conversation.key, ndb.Key.from_old_key(self.data.user.key()))

    if query.count() == 0:
      raise exception.Forbidden(message=DEF_NOT_IN_CONVERSATION)
예제 #3
0
    def toggleNotificationsEnabled(self, data, value):
        """Makes email notifications enabled or disabled.

    Args:
      data: A RequestData describing the current request.
      value: can be either "checked" or "unchecked".
    """
        assert access_checker.isSet(data.conversation)
        assert access_checker.isSet(data.user)

        query = gciconversation_logic.queryConversationUserForConversationAndUser(
            data.conversation.key, ndb.Key.from_old_key(data.user.key()))
        conv_user_results = query.fetch(1)
        assert conv_user_results
        conv_user = conv_user_results[0]

        if value != 'checked' and value != 'unchecked':
            raise exception.BadRequest(
                message='Invalid post data. Value must be checked or unchecked.'
            )
        if value == 'checked' and not conv_user.enable_notifications:
            raise exception.BadRequest(
                message='Notifications were already disabled.')
        if value == 'unchecked' and conv_user.enable_notifications:
            raise exception.BadRequest(
                message='Notifications were already enabled.')

        conv_user_key = conv_user.key

        # TODO(nathaniel): Remove the suppression on the following line when
        # https://bitbucket.org/logilab/pylint.org/issue/6/false-positive-no
        # is fixed.
        @ndb.transactional(xg=True)  # pylint: disable=no-value-for-parameter
        def set_notifications_enabled_txn():
            # transactionally get latest GCIConversationUser
            conv_user = conv_user_key.get()
            if value == 'unchecked':
                conv_user.enable_notifications = True
            elif value == 'checked':
                conv_user.enable_notifications = False

            conv_user.put()

        set_notifications_enabled_txn()
예제 #4
0
    def toggleNotificationsEnabled(self, data, value):
        """Makes email notifications enabled or disabled.

    Args:
      data: A RequestData describing the current request.
      value: can be either "checked" or "unchecked".
    """
        assert access_checker.isSet(data.conversation)
        assert access_checker.isSet(data.user)

        query = gciconversation_logic.queryConversationUserForConversationAndUser(
            data.conversation.key, ndb.Key.from_old_key(data.user.key())
        )
        conv_user_results = query.fetch(1)
        assert conv_user_results
        conv_user = conv_user_results[0]

        if value != "checked" and value != "unchecked":
            raise exception.BadRequest(message="Invalid post data. Value must be checked or unchecked.")
        if value == "checked" and not conv_user.enable_notifications:
            raise exception.BadRequest(message="Notifications were already disabled.")
        if value == "unchecked" and conv_user.enable_notifications:
            raise exception.BadRequest(message="Notifications were already enabled.")

        conv_user_key = conv_user.key

        # TODO(nathaniel): Remove the suppression on the following line when
        # https://bitbucket.org/logilab/pylint.org/issue/6/false-positive-no
        # is fixed.
        @ndb.transactional(xg=True)  # pylint: disable=no-value-for-parameter
        def set_notifications_enabled_txn():
            # transactionally get latest GCIConversationUser
            conv_user = conv_user_key.get()
            if value == "unchecked":
                conv_user.enable_notifications = True
            elif value == "checked":
                conv_user.enable_notifications = False

            conv_user.put()

        set_notifications_enabled_txn()
예제 #5
0
    def context(self):
        """See soc.views.template.Template.context for full specification."""
        assert access_checker.isSet(self.data.conversation)
        assert access_checker.isSet(self.data.user)

        query = gciconversation_logic.queryConversationUserForConversationAndUser(
            self.data.conversation.key,
            ndb.Key.from_old_key(self.data.user.key()))
        conv_user_results = query.fetch(1)
        assert conv_user_results

        conv_user = conv_user_results[0]

        self.data.redirect.id()

        url = self.data.redirect.urlOf(
            url_names.GCI_CONVERSATION_NOTIFICATION_TOGGLE)

        enable_notifications = toggle_button_view.ToggleButtonTemplate(
            self.data,
            'on_off',
            translation.ugettext('Enable Notifications'),
            'notifications-enabled',
            url,
            checked=conv_user.enable_notifications,
            help_text=self.DEF_ENABLE_NOTIFICATIONS_HELP,
            labels={
                'checked': 'Yes',
                'unchecked': 'No'
            })
        self.toggle_buttons.append(enable_notifications)

        return {
            'title': translation.ugettext('Conversation Actions'),
            'toggle_buttons': self.toggle_buttons,
        }