bellroy / lesswrong

Less Wrong platform
http://lesswrong.org/
Other
49 stars 23 forks source link

Admins access to a list of users #574

Open e1red opened 8 years ago

e1red commented 8 years ago

Currently sockpuppet accounts are easy to create because no one can see the creation of a new account. I propose that within the admin panel, similar to the list of banned users; a list of users with creation date should be visible to the admins.

vaniver commented 8 years ago

This is something StackExchange lets everyone see (for example, here ) and so it looks fine to me.

xrpd commented 8 years ago

absent a nice new user report, a hack could be to send a private message to an admin inbox when a new user confirms their email ( after c.user.email_validated = True in api.py )

e1red commented 8 years ago

I AM NOT A CODER AND DO NOT KNOW WHAT I AM DOING. There will probably be syntax errors and really stupid mistakes in this outline of how to solve this.

http://lesswrong.com/r/discussion/about/editors

The editors list is now only the current active moderators, if a notification can be sent to all the users in the editor class, that would be fine. I think it's called EditorList.

Details for the EditorList:

class EditorList(UserList):
    """Editor list for a reddit."""
    type = 'editor'

    def user_ids(self):
        return c.site.moderators

So I think something like user_ids.EditorList should return the editors.


looks like the code for sending a message looks like this:

    def _send_post_notifications(self, link, comment, parent):
        dashto = []
        for subscriber in Subscription._query(Subscription.c._thing2_id == (link._id),
                                              Subscription.c._name == 'subscription'):
            if not subscriber._thing1_id == comment.author_id:
                dashto.append(Account._byID(subscriber._thing1_id))
        if link.notify_on_comment and not link.author_id == comment.author_id:
                dashto.append(Account._byID(link.author_id))

        for user in dashto:
            s = SubscriptionStorage(user, comment, name='subscriptionstorage')
            s._commit()

        to = []
        if parent:
            if not parent.author_id == comment.author_id:
                to.append(Account._byID(parent.author_id))
            for subscriber in CommentSubscription._query(CommentSubscription.c._thing2_id == (parent._id),
                                                  CommentSubscription.c._name == 'commentsubscription'):
                if not subscriber._thing1_id == comment.author_id:
                    to.append(Account._byID(subscriber._thing1_id))
        else:
            for subscriber in Subscription._query(Subscription.c._thing2_id == (link._id),
                                                  Subscription.c._name == 'subscription'):
                if not subscriber._thing1_id == comment.author_id:
                    to.append(Account._byID(subscriber._thing1_id))
            if link.notify_on_comment and not link.author_id == comment.author_id:
                to.append(Account._byID(link.author_id))
        if len(to) == 0:
            return None
        # only global admins can be message spammed.
        if self._spam and to.name not in g.admins:
            return None

        for user in to:
            Inbox._add(user, self, 'inbox')

        return True

From: https://github.com/tricycle/lesswrong/blob/dfdc6e30f8f149651d679e209bc3fa24beea51b7/r2/r2/models/link.py

Or also in Link.py - the class for a message:

class Message(Thing, Printable):
    _defaults = dict(reported = 0,)
    _data_int_props = Thing._data_int_props + ('reported', )

    @classmethod
    def _new(cls, author, to, subject, body, ip, spam = False):
        m = Message(subject = subject,
                    body = body,
                    author_id = author._id,
                    ip = ip)
        m._spam = spam
        m.to_id = to._id
        m._commit()

        #author = Author(author, m, 'author')
        #author._commit()

        # only global admins can be message spammed.
        inbox_rel = None
        if (not author.messagebanned) and ((not m._spam) or to.name in g.admins):
            inbox_rel = Inbox._add(to, m, 'inbox')

        return (m, inbox_rel)

    @classmethod
    def add_props(cls, user, wrapped):
        #TODO global-ish functions that shouldn't be here?
        #reset msgtime after this request
        msgtime = c.have_messages

        #load the "to" field if required
        to_ids = set(w.to_id for w in wrapped)
        tos = Account._byID(to_ids, True) if to_ids else {}

        for item in wrapped:
            item.to = tos[item.to_id]
            if msgtime and item._date >= msgtime:
                item.new = True
            else:
                item.new = False
            item.score_fmt = Score.none

The formatting for a message:

 m = Message(subject = subject,
                    body = body,
                    author_id = author._id,
                    ip = ip)

Not sure but I think this line, or something close to it - would do it:

Inbox._add(The_editors_list, The_message, 'inbox')

Or more specifically:

            Inbox._add(EditorList, Message(subject = "new user",
                    body = user,
                    author_id = "New_User_Registration",
                    ip = ip), 'inbox')

(let me know how I did)

e1red commented 8 years ago

GJM suggests something like:

msg = Message(subject='new user registration', author_id=c.user._id, body='user name '+c.user.name, ip=ip)
for userid in c.site.editors:
   user = Account._byID(userid)
   Inbox._add(user, msg, 'inbox')

which looks a lot more like it will do the thing than my jumble.

alexpear commented 7 years ago

I know Python but i have so far been unable to complete installation of the LW stack locally. On the off chance there is someone with the counterpart to my skillset (uncertain about Python but able to run builds), here is an explicit version of the changes discussed above:

Apply the following modification at line 200 of lesswrong/r2/r2/controllers/api.py:

        else:
            c.user.email_validated = True

            msg = Message(
                subject = 'New User Registration',
                author_id = c.user._id,
                body = 'Username: ' + c.user.name,
                ip = ip)
            for userid in c.site.editors:
                user = Account._byID(userid)
                Inbox._add(user, msg, 'inbox')

            c.user._commit()
            res._success()

This definitely needs testing & i can't guarantee anything. I'm just summarizing the above.