Example #1
0
    def add_log(self, action, params, auth, foreign_user=None, log_date=None, save=True, request=None):
        AbstractNode = apps.get_model('osf.AbstractNode')
        user = None
        if auth:
            user = auth.user
        elif request:
            user = request.user

        params['node'] = params.get('node') or params.get('project') or self._id
        original_node = AbstractNode.load(params.get('node'))
        log = NodeLog(
            action=action, user=user, foreign_user=foreign_user,
            params=params, node=self, original_node=original_node
        )

        if log_date:
            log.date = log_date
        log.save()

        if self.logs.count() == 1:
            self.last_logged = log.date.replace(tzinfo=pytz.utc)
        else:
            self.last_logged = self.logs.first().date

        if save:
            self.save()
        if user and not self.is_collection:
            increment_user_activity_counters(user._primary_key, action, log.date.isoformat())

        return log
Example #2
0
    def test_increment_user_activity_counters(self):
        user = UserFactory()
        date = timezone.now()

        assert_equal(user.get_activity_points(), 0)
        analytics.increment_user_activity_counters(user._id, 'project_created', date.isoformat())
        assert_equal(user.get_activity_points(), 1)
Example #3
0
    def test_increment_user_activity_counters(self):
        user = UserFactory()
        date = timezone.now()

        assert_equal(user.get_activity_points(db=None), 0)
        analytics.increment_user_activity_counters(user._id, 'project_created', date.isoformat(), db=None)
        assert_equal(user.get_activity_points(db=None), 1)
Example #4
0
    def test_increment_user_activity_counters(self):
        user = UserFactory()
        date = datetime.utcnow()

        assert_equal(user.get_activity_points(db=self.db), 0)
        analytics.increment_user_activity_counters(user._id, 'project_created', date, db=self.db)
        assert_equal(user.get_activity_points(db=self.db), 1)
Example #5
0
    def add_log(self, action, params, auth, foreign_user=None, log_date=None, save=True, request=None):
        user = None
        if auth:
            user = auth.user
        elif request:
            user = request.user

        params['preprint'] = params.get('preprint') or self._id

        log = PreprintLog(
            action=action, user=user, foreign_user=foreign_user,
            params=params, preprint=self
        )

        log.save()

        if self.logs.count() == 1:
            self.last_logged = log.created.replace(tzinfo=pytz.utc)
        else:
            self.last_logged = self.logs.first().created

        if save:
            self.save()
        if user:
            increment_user_activity_counters(user._primary_key, action, log.created.isoformat())

        return log
Example #6
0
    def test_get_total_activity_count(self):
        user = UserFactory()
        date = timezone.now()

        assert_equal(analytics.get_total_activity_count(user._id), 0)
        assert_equal(analytics.get_total_activity_count(user._id), user.get_activity_points())

        analytics.increment_user_activity_counters(user._id, 'project_created', date.isoformat())

        assert_equal(analytics.get_total_activity_count(user._id), 1)
        assert_equal(analytics.get_total_activity_count(user._id), user.get_activity_points())
Example #7
0
    def test_get_total_activity_count(self):
        user = UserFactory()
        date = datetime.utcnow()

        assert_equal(analytics.get_total_activity_count(user._id), 0)
        assert_equal(analytics.get_total_activity_count(user._id), user.get_activity_points(db=self.db))

        analytics.increment_user_activity_counters(user._id, 'project_created', date.isoformat(), db=self.db)

        assert_equal(analytics.get_total_activity_count(user._id, db=self.db), 1)
        assert_equal(analytics.get_total_activity_count(user._id, db=self.db), user.get_activity_points(db=self.db))
Example #8
0
    def add_log(self,
                action,
                params,
                auth,
                foreign_user=None,
                log_date=None,
                save=True,
                request=None):
        global filelog
        AbstractNode = apps.get_model('osf.AbstractNode')
        user = None
        if auth:
            user = auth.user
        elif request:
            user = request.user

        params['node'] = params.get('node') or params.get(
            'project') or self._id
        original_node = AbstractNode.load(params.get('node'))
        log = NodeLog(action=action,
                      user=user,
                      foreign_user=foreign_user,
                      params=params,
                      node=self,
                      original_node=original_node)

        if user:
            try:
                if (('file' in action) or ('check' in action) or
                    ('osf_storage' in action)) and user._id:
                    if action not in 'rename':
                        filelog = FileLog(action=action,
                                          user=user,
                                          path=params['path'],
                                          project_id=self._id)
                        if log_date:
                            filelog.date = log_date
                        filelog.save()
                        ## RDM Logger ##
                        if user._id and original_node.title and params['path']:
                            rdmlogger = RdmLogger(rdmlog, {})
                            rdmlogger.info('RDM Project',
                                           RDMINFO='FileLog',
                                           action=action,
                                           user=user._id,
                                           project=original_node.title,
                                           file_path=params['path'])
                    else:
                        if 'osfstorage' in params['source']['provider']:
                            source_path = params['source']['materialized']
                        else:
                            source_path = params['source']['path']
                        filelog = FileLog(action=action,
                                          user=user,
                                          path=source_path,
                                          project_id=self._id)
                        if log_date:
                            filelog.date = log_date
                        filelog.save()
                        ## RDM Logger ##
                        if user._id and original_node.title and source_path:
                            rdmlogger = RdmLogger(rdmlog, {})
                            rdmlogger.info('RDM Project',
                                           RDMINFO='FileLog',
                                           action=action,
                                           user=user._id,
                                           project=original_node.title,
                                           file_path=source_path)
            except KeyError:
                print('KeyError')

        if log_date:
            log.date = log_date
        log.save()

        if self.logs.count() == 1:
            self.last_logged = log.date.replace(tzinfo=pytz.utc)
        else:
            self.last_logged = self.logs.first().date

        if save:
            self.save()
        if user and not self.is_collection:
            increment_user_activity_counters(user._primary_key, action,
                                             log.date.isoformat())

        return log