Ejemplo n.º 1
0
    def handle(self, *args, **options):
        wp_editcount_updated = now()
        if options["datetime"]:
            wp_editcount_updated = datetime.fromisoformat(options["datetime"])

        # Getting all editors that are currently eligible or are staff or are superusers
        editors = Editor.objects.filter(wp_bundle_eligible=True)
        for editor in editors:
            if options["global_userinfo"]:
                global_userinfo = options["global_userinfo"]
            else:
                global_userinfo = editor_global_userinfo(
                    editor.wp_username, editor.wp_sub, True)
            if global_userinfo:
                (
                    editor.wp_editcount_prev_updated,
                    editor.wp_editcount_prev,
                    editor.wp_editcount_recent,
                    editor.wp_enough_recent_edits,
                ) = editor_recent_edits(
                    global_userinfo["editcount"],
                    editor.wp_editcount_updated,
                    editor.wp_editcount_prev_updated,
                    editor.wp_editcount_prev,
                    editor.wp_editcount_recent,
                    editor.wp_enough_recent_edits,
                )
                editor.wp_editcount = global_userinfo["editcount"]
                editor.wp_editcount_updated = wp_editcount_updated
                editor.wp_enough_edits = editor_enough_edits(
                    editor.wp_editcount)
                editor.wp_not_blocked = editor_not_blocked(
                    global_userinfo["merged"])
                editor.wp_valid = editor_valid(
                    editor.wp_enough_edits,
                    # We could recalculate this, but we would only need to do that if upped the minimum required account age.
                    editor.wp_account_old_enough,
                    # editor.wp_not_blocked can only be rechecked on login, so we're going with the existing value.
                    editor.wp_not_blocked,
                    editor.ignore_wp_blocks,
                )
                editor.wp_bundle_eligible = editor_bundle_eligible(editor)

                editor.save()

                editor.update_bundle_authorization()
Ejemplo n.º 2
0
 def handle(self, **options):
     users = User.objects.all()
     for user in users:
         try:
             assert hasattr(user, "editor")
         except AssertionError:
             self.stdout.write(
                 "{username}: no editor object.".format(username=(user.username))
             )
             # Move on to the next user
             continue
         try:
             global_userinfo = editor_global_userinfo(
                 user.editor.wp_username, user.editor.wp_sub, True
             )
         except AssertionError:
             self.stdout.write(
                 "{name}: ID mismatch - local ID: {twlight_sub} remote ID: {sul_id}".format(
                     name=user.editor.wp_username,
                     twlight_sub=user.editor.wp_sub,
                     sul_id=global_userinfo["id"],
                 )
             )
Ejemplo n.º 3
0
 def get_global_userinfo(self, identity):
     return editor_global_userinfo(identity["username"], identity["sub"],
                                   True)
Ejemplo n.º 4
0
 def get_global_userinfo(self, identity):
     self.check_sub(identity["sub"])
     return editor_global_userinfo(identity["sub"])
Ejemplo n.º 5
0
    def handle(self, *args, **options):
        """
        Updates editor info and Bundle eligibility for currently-eligible Editors.
        Parameters
        ----------
        args
        options

        Returns
        -------
        None
        """

        # Default behavior is to use current datetime for timestamps to check all editors.
        now_or_datetime = now()
        datetime_override = None
        timedelta_days = 0
        wp_username = None
        editors = Editor.objects.all()

        # This may be overridden so that values may be treated as if they were valid for an arbitrary datetime.
        # This is also passed to the model method.
        if options["datetime"]:
            datetime_override = now_or_datetime.fromisoformat(
                options["datetime"])
            now_or_datetime = datetime_override

        # These are used to limit the set of editors updated by the command.
        # Nothing is passed to the model method.
        if options["timedelta_days"]:
            timedelta_days = int(options["timedelta_days"])

        # Get editors that haven't been updated in the specified time range, with an option to limit on wp_username.
        if timedelta_days:
            editors = editors.exclude(
                editorlogs__timestamp__gt=now_or_datetime -
                timedelta(days=timedelta_days), )

        # Optional wp_username filter.
        if options["wp_username"]:
            editors = editors.filter(wp_username=str(options["wp_username"]))

        for editor in editors:
            # `global_userinfo` data may be overridden.
            if options["global_userinfo"]:
                global_userinfo = options["global_userinfo"]
                editor.check_sub(global_userinfo["id"])
            # Default behavior is to fetch live `global_userinfo`
            else:
                global_userinfo = editor_global_userinfo(editor.wp_sub)
            if global_userinfo:
                editor.update_editcount(global_userinfo["editcount"],
                                        datetime_override)
                # Determine editor validity.
                editor.wp_enough_edits = editor_enough_edits(
                    editor.wp_editcount)
                editor.wp_not_blocked = editor_not_blocked(
                    global_userinfo["merged"])
                editor.wp_valid = editor_valid(
                    editor.wp_enough_edits,
                    # We could recalculate this, but we would only need to do that if upped the minimum required account age.
                    editor.wp_account_old_enough,
                    # editor.wp_not_blocked can only be rechecked on login, so we're going with the existing value.
                    editor.wp_not_blocked,
                    editor.ignore_wp_blocks,
                )
                # Determine Bundle eligibility.
                editor.wp_bundle_eligible = editor_bundle_eligible(editor)
                # Save editor.
                editor.save()
                # Prune EditorLogs, with daily_prune_range set to only check the previous day to improve performance.
                editor.prune_editcount(current_datetime=datetime_override,
                                       daily_prune_range=2)
                # Update bundle authorizations.
                editor.update_bundle_authorization()