示例#1
0
 def test_no_actions_touevent_from_dict(self):
     # Register user acceptance for the ToU version in use
     tou = ToUEvent.from_dict(
         dict(
             version=self.config.tou_version,
             created_by='unit test',
             created_ts=datetime.utcnow(),
             event_id=bson.ObjectId(),
         ))
     self._test_no_actions(tou)
示例#2
0
 def tou_accepted(self, user, version, created_ts=None, modified_ts=None):
     event_id = ObjectId()
     if created_ts is None:
         created_ts = datetime.utcnow()
     user.tou.add(
         ToUEvent.from_dict(
             dict(
                 version=version,
                 created_by='eduid_tou_plugin',
                 created_ts=created_ts,
                 modified_ts=modified_ts,
                 event_id=event_id,
             )))
     self.app.central_userdb.save(user, check_sync=False)
示例#3
0
    def test_add_tou_action_already_accepted_other_version(self):
        event_id = bson.ObjectId()
        self.test_user.tou.add(
            ToUEvent.from_dict(
                dict(
                    version='mock-version-2',
                    created_by='test_tou_plugin',
                    created_ts=datetime.utcnow(),
                    event_id=event_id,
                )))
        self.actions.remove_action_by_id(self.test_action.action_id)
        from eduid_idp.tou_action import add_actions

        mock_ticket = make_login_ticket(req_class_ref=SWAMID_AL2,
                                        context=self.idp_app.context,
                                        key='mock-session')
        add_actions(self.idp_app.context, self.test_user, mock_ticket)
        self.assertEqual(
            len(self.actions.get_actions(self.test_user.eppn, 'mock-session')),
            1)
示例#4
0
    def perform_step(self, action: Action):
        if not request.get_json().get('accept', ''):
            raise self.ActionError(ActionsMsg.must_accept)

        eppn = action.eppn
        central_user = current_app.central_userdb.get_user_by_eppn(eppn)
        user = ToUUser.from_user(central_user, current_app.tou_db)
        current_app.logger.debug('Loaded ToUUser {} from db'.format(user))

        version = action.params['version']

        existing_tou = user.tou.find(version)
        if existing_tou:
            current_app.logger.info('ToU version {} reaccepted by user {}'.format(version, user))
            existing_tou.modified_ts = datetime.utcnow()
        else:
            current_app.logger.info('ToU version {} accepted by user {}'.format(version, user))
            user.tou.add(
                ToUEvent.from_dict(
                    dict(
                        version=version,
                        created_by='eduid_tou_plugin',
                        created_ts=datetime.utcnow(),
                        modified_ts=datetime.utcnow(),
                        event_id=ObjectId(),
                    )
                )
            )

        current_app.tou_db.save(user, check_sync=False)
        current_app.logger.debug("Asking for sync of {} by Attribute Manager".format(user))
        rtask = self._update_attributes.delay('eduid_tou', str(user.user_id))
        try:
            result = rtask.get(timeout=10)
            current_app.logger.debug("Attribute Manager sync result: {!r}".format(result))
            current_app.actions_db.remove_action_by_id(action.action_id)
            current_app.logger.info('Removed completed action {}'.format(action))
            return {}
        except Exception as e:
            current_app.logger.error("Failed Attribute Manager sync request: " + str(e))
            raise self.ActionError(ActionsMsg.sync_problem)
示例#5
0
def record_tou(user, source):
    """
    Record user acceptance of terms of use.

    :param user: the user that has accepted the ToU
    :type user: eduid_userdb.signup.SignupUser
    :param source: An identificator for the proccess during which
                   the user has accepted the ToU (e.g., "signup")
    :type source: str

    :return: None
    """
    event_id = ObjectId()
    created_ts = datetime.datetime.utcnow()
    tou_version = current_app.config.tou_version
    current_app.logger.info('Recording ToU acceptance {!r} (version {})'
                            ' for user {} (source: {})'.format(
                                event_id, tou_version, user, source))
    user.tou.add(
        ToUEvent.from_dict(
            dict(version=tou_version,
                 created_by=source,
                 created_ts=created_ts,
                 event_id=event_id)))