コード例 #1
0
ファイル: journal.py プロジェクト: Syfaro/weasyl
def edit(userid, journal, friends_only=False):
    if not journal.title:
        raise WeasylError("titleInvalid")
    elif not journal.content:
        raise WeasylError("contentInvalid")
    elif not journal.rating:
        raise WeasylError("ratingInvalid")
    profile.check_user_rating_allowed(userid, journal.rating)

    query = d.execute("SELECT userid, settings FROM journal WHERE journalid = %i", [journal.journalid], options="single")

    if not query or "h" in query[1]:
        raise WeasylError("Unexpected")
    elif userid != query[0] and userid not in staff.MODS:
        raise WeasylError("InsufficientPermissions")

    settings = [query[1].replace("f", "")]
    settings.append("f" if friends_only else "")
    settings = "".join(settings)

    if "f" in settings:
        welcome.journal_remove(journal.journalid)

    d.execute("UPDATE journal SET (title, content, rating, settings) = ('%s', '%s', %i, '%s') WHERE journalid = %i",
              [journal.title, journal.content, journal.rating.code, settings, journal.journalid])

    if userid != query[0]:
        moderation.note_about(
            userid, query[0], 'The following journal was edited:',
            '- ' + text.markdown_link(journal.title, '/journal/%s?anyway=true' % (journal.journalid,)))
コード例 #2
0
ファイル: profile.py プロジェクト: weykent/weasyl
def edit_streaming_settings(my_userid,
                            userid,
                            profile,
                            set_stream=None,
                            stream_length=0):

    if set_stream == 'start':
        try:
            stream_length = int(stream_length)
        except:
            raise WeasylError("streamDurationOutOfRange")

        if stream_length < 1 or stream_length > 360:
            raise WeasylError("streamDurationOutOfRange")

    if set_stream == 'start' and not profile.stream_url:
        raise WeasylError("streamLocationNotSet")

    # unless we're specifically still streaming, clear the user_streams record
    if set_stream != 'still':
        d.execute("DELETE FROM user_streams WHERE userid = %i", [userid])

    settings_flag = ''
    stream_status = None
    # if we're starting to stream, update user_streams to reflect that
    if set_stream == 'start':
        now = d.get_time()
        stream_end = now + stream_length * 60  # stream_length is minutes; we need seconds
        d.execute("INSERT INTO user_streams VALUES (%i, %i, %i)",
                  [userid, now, stream_end])
        stream_status = 'n'
    # if we're going to stream later, update profile.settings to reflect that
    elif set_stream == 'later':
        settings_flag = stream_status = 'l'

    # if stream_status is None, any rows in `welcome` will get cleared. but, if
    # the user is still streaming, that shouldn't happen. otherwise, `welcome`
    # will get updated with the current stream state.
    if set_stream != 'still':
        welcome.stream_insert(userid, stream_status)

    d.execute(
        "UPDATE profile "
        "SET (stream_text, stream_url, settings) = ('%s', '%s', REGEXP_REPLACE(settings, '[nli]', '') || '%s') "
        "WHERE userid = %i",
        [profile.stream_text, profile.stream_url, settings_flag, userid])

    if my_userid != userid:
        from weasyl import moderation
        note_body = ('- Stream url: %s\n'
                     '- Stream description: %s\n'
                     '- Stream status: %s' %
                     (profile.stream_url, profile.stream_text,
                      STREAMING_ACTION_MAP[set_stream]))
        moderation.note_about(my_userid, userid, 'Streaming settings updated:',
                              note_body)
コード例 #3
0
ファイル: profile.py プロジェクト: guptaarth87/weasyl
def edit_streaming_settings(my_userid,
                            userid,
                            profile,
                            set_stream=None,
                            stream_length=0):

    if set_stream == 'start':
        if stream_length < 1 or stream_length > 360:
            raise WeasylError("streamDurationOutOfRange")

        if not profile.stream_url:
            raise WeasylError("streamLocationNotSet")

    # unless we're specifically still streaming, clear the user_streams record
    if set_stream != 'still':
        d.execute("DELETE FROM user_streams WHERE userid = %i", [userid])

    settings_flag = ''
    stream_status = None
    # if we're starting to stream, update user_streams to reflect that
    if set_stream == 'start':
        now = d.get_time()
        stream_end = now + stream_length * 60  # stream_length is minutes; we need seconds
        d.execute("INSERT INTO user_streams VALUES (%i, %i, %i)",
                  [userid, now, stream_end])
        stream_status = 'n'
    # if we're going to stream later, update profile.settings to reflect that
    elif set_stream == 'later':
        settings_flag = stream_status = 'l'

    # if stream_status is None, any rows in `welcome` will get cleared. but, if
    # the user is still streaming, that shouldn't happen. otherwise, `welcome`
    # will get updated with the current stream state.
    if set_stream != 'still':
        welcome.stream_insert(userid, stream_status)

    pr = d.meta.tables['profile']
    d.engine.execute(pr.update().where(pr.c.userid == userid).values({
        'stream_text':
        profile.stream_text,
        'stream_url':
        profile.stream_url,
        'settings':
        sa.func.regexp_replace(pr.c.settings, "[nli]",
                               "").concat(settings_flag),
    }))

    if my_userid != userid:
        from weasyl import moderation
        note_body = ('- Stream url: %s\n'
                     '- Stream description: %s\n'
                     '- Stream status: %s' %
                     (profile.stream_url, profile.stream_text,
                      STREAMING_ACTION_MAP[set_stream]))
        moderation.note_about(my_userid, userid, 'Streaming settings updated:',
                              note_body)
コード例 #4
0
ファイル: profile.py プロジェクト: dzamie/weasyl
def edit_streaming_settings(my_userid, userid, profile, set_stream=None, stream_length=0):

    if set_stream == 'start':
        try:
            stream_length = int(stream_length)
        except:
            raise WeasylError("streamDurationOutOfRange")

        if stream_length < 1 or stream_length > 360:
            raise WeasylError("streamDurationOutOfRange")

    if set_stream == 'start' and not profile.stream_url:
        raise WeasylError("streamLocationNotSet")

    # unless we're specifically still streaming, clear the user_streams record
    if set_stream != 'still':
        d.execute("DELETE FROM user_streams WHERE userid = %i", [userid])

    settings_flag = ''
    stream_status = None
    # if we're starting to stream, update user_streams to reflect that
    if set_stream == 'start':
        now = d.get_time()
        stream_end = now + stream_length * 60  # stream_length is minutes; we need seconds
        d.execute("INSERT INTO user_streams VALUES (%i, %i, %i)", [userid, now, stream_end])
        stream_status = 'n'
    # if we're going to stream later, update profile.settings to reflect that
    elif set_stream == 'later':
        settings_flag = stream_status = 'l'

    # if stream_status is None, any rows in `welcome` will get cleared. but, if
    # the user is still streaming, that shouldn't happen. otherwise, `welcome`
    # will get updated with the current stream state.
    if set_stream != 'still':
        welcome.stream_insert(userid, stream_status)

    d.execute(
        "UPDATE profile "
        "SET (stream_text, stream_url, settings) = ('%s', '%s', REGEXP_REPLACE(settings, '[nli]', '') || '%s') "
        "WHERE userid = %i",
        [profile.stream_text, profile.stream_url, settings_flag, userid])

    if my_userid != userid:
        from weasyl import moderation
        note_body = (
            '- Stream url: %s\n'
            '- Stream description: %s\n'
            '- Stream status: %s' % (profile.stream_url, profile.stream_text, STREAMING_ACTION_MAP[set_stream]))
        moderation.note_about(my_userid, userid, 'Streaming settings updated:', note_body)
コード例 #5
0
ファイル: moderation.py プロジェクト: Locynaeh/weasyl
def modcontrol_copynotetostaffnotes_post_(request):
    form = request.web_input(noteid=None)

    notedata = note.select_view(request.userid, int(form.noteid))

    staff_note_title = u"Received note from {sender}, dated {date}, with subject: “{subj}”.".format(
        sender=notedata['sendername'],
        date=arrow.get(notedata['unixtime']).format('YYYY-MM-DD HH:mm:ss ZZ'),
        subj=notedata['title'],
    )

    moderation.note_about(
        userid=request.userid,
        target_user=notedata['senderid'],
        title=staff_note_title,
        message=notedata['content'],
    )
    raise HTTPSeeOther("/staffnotes/" + notedata['sendername'])
コード例 #6
0
ファイル: moderation.py プロジェクト: makyo/weasyl
def modcontrol_copynotetostaffnotes_post_(request):
    form = request.web_input(noteid=None)

    notedata = note.select_view(request.userid, int(form.noteid))

    staff_note_title = u"Received note from {sender}, dated {date}, with subject: “{subj}”.".format(
        sender=notedata['sendername'],
        date=arrow.get(notedata['unixtime']).format('YYYY-MM-DD HH:mm:ss ZZ'),
        subj=notedata['title'],
    )

    moderation.note_about(
        userid=request.userid,
        target_user=notedata['senderid'],
        title=staff_note_title,
        message=notedata['content'],
    )
    raise HTTPSeeOther("/staffnotes/" + notedata['sendername'])
コード例 #7
0
def edit(userid, journal, friends_only=False):
    if not journal.title:
        raise WeasylError("titleInvalid")
    elif not journal.content:
        raise WeasylError("contentInvalid")
    elif not journal.rating:
        raise WeasylError("ratingInvalid")
    profile.check_user_rating_allowed(userid, journal.rating)

    query = d.engine.execute(
        "SELECT userid, settings FROM journal WHERE journalid = %(id)s",
        id=journal.journalid,
    ).first()

    if not query or "h" in query[1]:
        raise WeasylError("Unexpected")
    elif userid != query[0] and userid not in staff.MODS:
        raise WeasylError("InsufficientPermissions")

    settings = query[1].replace("f", "")

    if friends_only:
        settings += "f"
        welcome.journal_remove(journal.journalid)

    jo = d.meta.tables['journal']
    d.engine.execute(
        jo.update().where(jo.c.journalid == journal.journalid).values({
            'title':
            journal.title,
            'content':
            journal.content,
            'rating':
            journal.rating,
            'settings':
            settings,
        }))

    if userid != query[0]:
        moderation.note_about(
            userid, query[0], 'The following journal was edited:',
            '- ' + text.markdown_link(
                journal.title, '/journal/%s?anyway=true' %
                (journal.journalid, )))
コード例 #8
0
def edit(userid, character, friends_only):
    query = define.execute(
        "SELECT userid, settings FROM character WHERE charid = %i",
        [character.charid],
        options="single")

    if not query or "h" in query[1]:
        raise WeasylError("Unexpected")
    elif userid != query[0] and userid not in staff.MODS:
        raise WeasylError("InsufficientPermissions")
    elif not character.char_name:
        raise WeasylError("characterNameInvalid")
    elif not character.rating:
        raise WeasylError("Unexpected")
    profile.check_user_rating_allowed(userid, character.rating)

    # Assign settings
    settings = [query[1].replace("f", "")]
    settings.append("f" if friends_only else "")
    settings = "".join(settings)

    if "f" in settings:
        welcome.character_remove(character.charid)

    define.execute(
        """
            UPDATE character
            SET (char_name, age, gender, height, weight, species, content, rating, settings) =
                ('%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, '%s')
            WHERE charid = %i
        """, [
            character.char_name, character.age, character.gender,
            character.height, character.weight, character.species,
            character.content, character.rating.code, settings,
            character.charid
        ])

    if userid != query[0]:
        from weasyl import moderation
        moderation.note_about(
            userid, query[0], 'The following character was edited:',
            '- ' + text.markdown_link(
                character.char_name, '/character/%s?anyway=true' %
                (character.charid, )))
コード例 #9
0
ファイル: character.py プロジェクト: guptaarth87/weasyl
def edit(userid, character, friends_only):
    query = define.engine.execute("SELECT userid, settings FROM character WHERE charid = %(id)s",
                                  id=character.charid).first()

    if not query or "h" in query[1]:
        raise WeasylError("Unexpected")
    elif userid != query[0] and userid not in staff.MODS:
        raise WeasylError("InsufficientPermissions")
    elif not character.char_name:
        raise WeasylError("characterNameInvalid")
    elif not character.rating:
        raise WeasylError("Unexpected")
    profile.check_user_rating_allowed(userid, character.rating)

    # Assign settings
    settings = query[1].replace("f", "")

    if friends_only:
        settings += "f"
        welcome.character_remove(character.charid)

    ch = define.meta.tables["character"]
    define.engine.execute(
        ch.update()
        .where(ch.c.charid == character.charid)
        .values({
            'char_name': character.char_name,
            'age': character.age,
            'gender': character.gender,
            'height': character.height,
            'weight': character.weight,
            'species': character.species,
            'content': character.content,
            'rating': character.rating,
            'settings': settings,
        })
    )

    if userid != query[0]:
        from weasyl import moderation
        moderation.note_about(
            userid, query[0], 'The following character was edited:',
            '- ' + text.markdown_link(character.char_name, '/character/%s?anyway=true' % (character.charid,)))
コード例 #10
0
ファイル: journal.py プロジェクト: taedixon/weasyl
def edit(userid, journal, friends_only=False):
    if not journal.title:
        raise WeasylError("titleInvalid")
    elif not journal.content:
        raise WeasylError("contentInvalid")
    elif not journal.rating:
        raise WeasylError("ratingInvalid")
    profile.check_user_rating_allowed(userid, journal.rating)

    query = d.execute(
        "SELECT userid, settings FROM journal WHERE journalid = %i",
        [journal.journalid],
        options="single")

    if not query or "h" in query[1]:
        raise WeasylError("Unexpected")
    elif userid != query[0] and userid not in staff.MODS:
        raise WeasylError("InsufficientPermissions")

    settings = [query[1].replace("f", "")]
    settings.append("f" if friends_only else "")
    settings = "".join(settings)

    if "f" in settings:
        welcome.journal_remove(journal.journalid)

    # TODO(kailys): use ORM
    d.execute(
        "UPDATE journal SET (title, rating, settings) = ('%s', %i, '%s') WHERE journalid = %i",
        [journal.title, journal.rating.code, settings, journal.journalid])

    # Write journal file
    files.write(
        files.make_resource(userid, journal.journalid, "journal/submit"),
        journal.content)

    if userid != query[0]:
        from weasyl import moderation
        moderation.note_about(
            userid, query[0], 'The following journal was edited:',
            '- ' + text.markdown_link(
                journal.title, '/journal/%s?anyway=true' %
                (journal.journalid, )))
コード例 #11
0
ファイル: character.py プロジェクト: BaxterOttoman/weasyl
def edit(userid, character, friends_only):
    query = define.execute("SELECT userid, settings FROM character WHERE charid = %i",
                           [character.charid], options="single")

    if not query or "h" in query[1]:
        raise WeasylError("Unexpected")
    elif userid != query[0] and userid not in staff.MODS:
        raise WeasylError("InsufficientPermissions")
    elif not character.char_name:
        raise WeasylError("characterNameInvalid")
    elif not character.rating:
        raise WeasylError("Unexpected")
    profile.check_user_rating_allowed(userid, character.rating)

    # Assign settings
    settings = [query[1].replace("f", "")]
    settings.append("f" if friends_only else "")
    settings = "".join(settings)

    if "f" in settings:
        welcome.character_remove(character.charid)

    define.execute(
        """
            UPDATE character
            SET (char_name, age, gender, height, weight, species, content, rating, settings) =
                ('%s', '%s', '%s', '%s', '%s', '%s', '%s', %i, '%s')
            WHERE charid = %i
        """,
        [character.char_name, character.age, character.gender, character.height, character.weight, character.species,
         character.content, character.rating.code, settings, character.charid])

    if userid != query[0]:
        from weasyl import moderation
        moderation.note_about(
            userid, query[0], 'The following character was edited:',
            '- ' + text.markdown_link(character.char_name, '/character/%s?anyway=true' % (character.charid,)))
コード例 #12
0
ファイル: profile.py プロジェクト: weykent/weasyl
def do_manage(my_userid,
              userid,
              username=None,
              full_name=None,
              catchphrase=None,
              birthday=None,
              gender=None,
              country=None):
    updates = []

    # Username
    if username is not None:
        if not d.get_sysname(username):
            raise WeasylError("usernameInvalid")
        elif d.execute(
                "SELECT EXISTS (SELECT 0 FROM login WHERE login_name = '%s')",
            [d.get_sysname(username)], ["bool"]):
            raise WeasylError("usernameExists")
        elif d.execute(
                "SELECT EXISTS (SELECT 0 FROM useralias WHERE alias_name = '%s')",
            [d.get_sysname(username)], ["bool"]):
            raise WeasylError("usernameExists")
        elif d.execute(
                "SELECT EXISTS (SELECT 0 FROM logincreate WHERE login_name = '%s')",
            [d.get_sysname(username)], ["bool"]):
            raise WeasylError("usernameExists")

        d.execute("UPDATE login SET login_name = '%s' WHERE userid = %i",
                  [d.get_sysname(username), userid])
        d._get_display_name.invalidate(userid)
        d.execute("UPDATE profile SET username = '******' WHERE userid = %i",
                  [username, userid])
        updates.append('- Username: %s' % (username, ))

    # Full name
    if full_name is not None:
        d.execute("UPDATE profile SET full_name = '%s' WHERE userid = %i",
                  [full_name, userid])
        updates.append('- Full name: %s' % (full_name, ))

    # Catchphrase
    if catchphrase is not None:
        d.execute("UPDATE profile SET catchphrase = '%s' WHERE userid = %i",
                  [catchphrase, userid])
        updates.append('- Catchphrase: %s' % (catchphrase, ))

    # Birthday
    if birthday is not None and d.convert_inputdate(birthday):
        unixtime = d.convert_inputdate(birthday)
        age = d.convert_age(unixtime)

        d.execute("UPDATE userinfo SET birthday = %i WHERE userid = %i",
                  [unixtime, userid])

        if age < ratings.MODERATE.minimum_age:
            max_rating = ratings.GENERAL.code
            rating_flag = ""
        elif age < ratings.EXPLICIT.minimum_age:
            max_rating = ratings.MODERATE.code
            rating_flag = "m"
        else:
            max_rating = ratings.EXPLICIT.code

        if d.get_rating(userid) > max_rating:
            d.execute(
                """
                UPDATE profile
                SET config = REGEXP_REPLACE(config, '[map]', '', 'g') || '%s'
                WHERE userid = %i
                """, [rating_flag, userid])
            d._get_config.invalidate(userid)
        updates.append('- Birthday: %s' % (birthday, ))

    # Gender
    if gender is not None:
        d.execute("UPDATE userinfo SET gender = '%s' WHERE userid = %i",
                  [gender, userid])
        updates.append('- Gender: %s' % (gender, ))

    # Location
    if country is not None:
        d.execute("UPDATE userinfo SET country = '%s' WHERE userid = %i",
                  [country, userid])
        updates.append('- Country: %s' % (country, ))

    if updates:
        from weasyl import moderation
        moderation.note_about(my_userid, userid,
                              'The following fields were changed:',
                              '\n'.join(updates))
コード例 #13
0
def do_manage(my_userid,
              userid,
              username=None,
              full_name=None,
              catchphrase=None,
              birthday=None,
              gender=None,
              country=None,
              remove_social=None,
              permission_tag=None):
    """Updates a user's information from the admin user management page.
    After updating the user it records all the changes into the mod notes.

    If an argument is None it will not be updated.

    Args:
        my_userid (int): ID of user making changes to other user.
        userid (int): ID of user to modify.
        username (str): New username for user. Defaults to None.
        full_name (str): New full name for user. Defaults to None.
        catchphrase (str): New catchphrase for user. Defaults to None.
        birthday (str): New birthday for user, in format for convert_inputdate. Defaults to None.
        gender (str): New gender for user. Defaults to None.
        country (str): New country for user. Defaults to None.
        remove_social (list): Items to remove from the user's social/contact links. Defaults to None.
        permission_tag (bool): New tagging permission for user. Defaults to None.

    Returns:
        Does not return.
    """
    updates = []

    # Username
    if username is not None:
        if not d.get_sysname(username):
            raise WeasylError("usernameInvalid")
        elif d.execute(
                "SELECT EXISTS (SELECT 0 FROM login WHERE login_name = '%s')",
            [d.get_sysname(username)], ["bool"]):
            raise WeasylError("usernameExists")
        elif d.execute(
                "SELECT EXISTS (SELECT 0 FROM useralias WHERE alias_name = '%s')",
            [d.get_sysname(username)], ["bool"]):
            raise WeasylError("usernameExists")
        elif d.execute(
                "SELECT EXISTS (SELECT 0 FROM logincreate WHERE login_name = '%s')",
            [d.get_sysname(username)], ["bool"]):
            raise WeasylError("usernameExists")

        d.execute("UPDATE login SET login_name = '%s' WHERE userid = %i",
                  [d.get_sysname(username), userid])
        d._get_display_name.invalidate(userid)
        d.execute("UPDATE profile SET username = '******' WHERE userid = %i",
                  [username, userid])
        updates.append('- Username: %s' % (username, ))

    # Full name
    if full_name is not None:
        d.execute("UPDATE profile SET full_name = '%s' WHERE userid = %i",
                  [full_name, userid])
        updates.append('- Full name: %s' % (full_name, ))

    # Catchphrase
    if catchphrase is not None:
        d.execute("UPDATE profile SET catchphrase = '%s' WHERE userid = %i",
                  [catchphrase, userid])
        updates.append('- Catchphrase: %s' % (catchphrase, ))

    # Birthday
    if birthday is not None and d.convert_inputdate(birthday):
        unixtime = d.convert_inputdate(birthday)
        age = d.convert_age(unixtime)

        d.execute("UPDATE userinfo SET birthday = %i WHERE userid = %i",
                  [unixtime, userid])

        if age < ratings.EXPLICIT.minimum_age:
            max_rating = ratings.GENERAL.code
            rating_flag = ""
        else:
            max_rating = ratings.EXPLICIT.code

        if d.get_rating(userid) > max_rating:
            d.execute(
                """
                UPDATE profile
                SET config = REGEXP_REPLACE(config, '[ap]', '', 'g') || '%s'
                WHERE userid = %i
                """, [rating_flag, userid])
            d._get_config.invalidate(userid)
        updates.append('- Birthday: %s' % (birthday, ))

    # Gender
    if gender is not None:
        d.execute("UPDATE userinfo SET gender = '%s' WHERE userid = %i",
                  [gender, userid])
        updates.append('- Gender: %s' % (gender, ))

    # Location
    if country is not None:
        d.execute("UPDATE userinfo SET country = '%s' WHERE userid = %i",
                  [country, userid])
        updates.append('- Country: %s' % (country, ))

    # Social and contact links
    if remove_social:
        for social_link in remove_social:
            d.engine.execute(
                "DELETE FROM user_links WHERE userid = %(userid)s AND link_type = %(link)s",
                userid=userid,
                link=social_link)
            updates.append('- Removed social link for %s' % (social_link, ))

    # Permissions
    if permission_tag is not None:
        if permission_tag:
            query = (
                "UPDATE profile SET config = replace(config, 'g', '') "
                "WHERE userid = %(user)s AND position('g' in config) != 0")
        else:
            query = ("UPDATE profile SET config = config || 'g' "
                     "WHERE userid = %(user)s AND position('g' in config) = 0")

        if d.engine.execute(query, user=userid).rowcount != 0:
            updates.append('- Permission to tag: ' +
                           ('yes' if permission_tag else 'no'))
            d._get_config.invalidate(userid)

    if updates:
        from weasyl import moderation
        moderation.note_about(my_userid, userid,
                              'The following fields were changed:',
                              '\n'.join(updates))
コード例 #14
0
def edit(userid,
         submission,
         embedlink=None,
         friends_only=False,
         critique=False):
    query = d.execute(
        "SELECT userid, subtype, settings FROM submission WHERE submitid = %i",
        [submission.submitid], ["single"])

    if not query or "h" in query[2]:
        raise WeasylError("Unexpected")
    elif "a" in query[2] and userid not in staff.MODS:
        raise WeasylError("AdminLocked")
    elif userid != query[0] and userid not in staff.MODS:
        raise WeasylError("InsufficientPermissions")
    elif not submission.title:
        raise WeasylError("titleInvalid")
    elif not submission.rating:
        raise WeasylError("Unexpected")
    elif not folder.check(query[0], submission.folderid):
        raise WeasylError("Unexpected")
    elif submission.subtype / 1000 != query[1] / 1000:
        raise WeasylError("Unexpected")
    elif 'v' in query[2] and not embed.check_valid(embedlink):
        raise WeasylError("embedlinkInvalid")
    elif 'D' in query[2]:
        check_google_doc_embed_data(embedlink)
    profile.check_user_rating_allowed(userid, submission.rating)

    # Assign settings
    settings = [query[2].replace("f", "").replace("q", "")]
    settings.append("f" if friends_only else "")
    settings.append("q" if critique else "")
    settings = "".join(settings)

    if "v" in settings:
        submission.content = "%s\n%s" % (embedlink, submission.content)

    if "f" in settings:
        welcome.submission_became_friends_only(submission.submitid, userid)

    # TODO(kailys): maintain ORM object
    db = d.connect()
    su = d.meta.tables['submission']
    q = (su.update().values(
        folderid=submission.folderid,
        title=submission.title,
        content=submission.content,
        subtype=submission.subtype,
        rating=submission.rating,
        settings=settings,
    ).where(su.c.submitid == submission.submitid))
    db.execute(q)

    if 'D' in settings:
        db = d.connect()
        gde = d.meta.tables['google_doc_embeds']
        q = (gde.update().values(embed_url=embedlink).where(
            gde.c.submitid == submission.submitid))
        db.execute(q)

    if userid != query[0]:
        from weasyl import moderation
        moderation.note_about(
            userid, query[0], 'The following submission was edited:',
            '- ' + text.markdown_link(
                submission.title, '/submission/%s?anyway=true' %
                (submission.submitid, )))
コード例 #15
0
ファイル: profile.py プロジェクト: makyo/weasyl
def do_manage(my_userid, userid, username=None, full_name=None, catchphrase=None,
              birthday=None, gender=None, country=None, remove_social=None,
              permission_tag=None):
    """Updates a user's information from the admin user management page.
    After updating the user it records all the changes into the mod notes.

    If an argument is None it will not be updated.

    Args:
        my_userid (int): ID of user making changes to other user.
        userid (int): ID of user to modify.
        username (str): New username for user. Defaults to None.
        full_name (str): New full name for user. Defaults to None.
        catchphrase (str): New catchphrase for user. Defaults to None.
        birthday (str): New birthday for user, in format for convert_inputdate. Defaults to None.
        gender (str): New gender for user. Defaults to None.
        country (str): New country for user. Defaults to None.
        remove_social (list): Items to remove from the user's social/contact links. Defaults to None.
        permission_tag (bool): New tagging permission for user. Defaults to None.

    Returns:
        Does not return.
    """
    updates = []

    # Username
    if username is not None:
        if not d.get_sysname(username):
            raise WeasylError("usernameInvalid")
        elif d.execute("SELECT EXISTS (SELECT 0 FROM login WHERE login_name = '%s')",
                       [d.get_sysname(username)], ["bool"]):
            raise WeasylError("usernameExists")
        elif d.execute("SELECT EXISTS (SELECT 0 FROM useralias WHERE alias_name = '%s')",
                       [d.get_sysname(username)], ["bool"]):
            raise WeasylError("usernameExists")
        elif d.execute("SELECT EXISTS (SELECT 0 FROM logincreate WHERE login_name = '%s')",
                       [d.get_sysname(username)], ["bool"]):
            raise WeasylError("usernameExists")

        d.execute("UPDATE login SET login_name = '%s' WHERE userid = %i",
                  [d.get_sysname(username), userid])
        d._get_display_name.invalidate(userid)
        d.execute("UPDATE profile SET username = '******' WHERE userid = %i",
                  [username, userid])
        updates.append('- Username: %s' % (username,))

    # Full name
    if full_name is not None:
        d.execute("UPDATE profile SET full_name = '%s' WHERE userid = %i",
                  [full_name, userid])
        updates.append('- Full name: %s' % (full_name,))

    # Catchphrase
    if catchphrase is not None:
        d.execute("UPDATE profile SET catchphrase = '%s' WHERE userid = %i",
                  [catchphrase, userid])
        updates.append('- Catchphrase: %s' % (catchphrase,))

    # Birthday
    if birthday is not None and d.convert_inputdate(birthday):
        unixtime = d.convert_inputdate(birthday)
        age = d.convert_age(unixtime)

        d.execute("UPDATE userinfo SET birthday = %i WHERE userid = %i", [unixtime, userid])

        if age < ratings.MODERATE.minimum_age:
            max_rating = ratings.GENERAL.code
            rating_flag = ""
        elif age < ratings.EXPLICIT.minimum_age:
            max_rating = ratings.MODERATE.code
            rating_flag = "m"
        else:
            max_rating = ratings.EXPLICIT.code

        if d.get_rating(userid) > max_rating:
            d.execute(
                """
                UPDATE profile
                SET config = REGEXP_REPLACE(config, '[map]', '', 'g') || '%s'
                WHERE userid = %i
                """,
                [rating_flag, userid]
            )
            d._get_config.invalidate(userid)
        updates.append('- Birthday: %s' % (birthday,))

    # Gender
    if gender is not None:
        d.execute("UPDATE userinfo SET gender = '%s' WHERE userid = %i",
                  [gender, userid])
        updates.append('- Gender: %s' % (gender,))

    # Location
    if country is not None:
        d.execute("UPDATE userinfo SET country = '%s' WHERE userid = %i",
                  [country, userid])
        updates.append('- Country: %s' % (country,))

    # Social and contact links
    if remove_social:
        for social_link in remove_social:
            d.engine.execute("DELETE FROM user_links WHERE userid = %(userid)s AND link_type = %(link)s", userid=userid, link=social_link)
            updates.append('- Removed social link for %s' % (social_link,))

    # Permissions
    if permission_tag is not None:
        if permission_tag:
            query = (
                "UPDATE profile SET config = replace(config, 'g', '') "
                "WHERE userid = %(user)s AND position('g' in config) != 0")
        else:
            query = (
                "UPDATE profile SET config = config || 'g' "
                "WHERE userid = %(user)s AND position('g' in config) = 0")

        if d.engine.execute(query, user=userid).rowcount != 0:
            updates.append('- Permission to tag: ' + ('yes' if permission_tag else 'no'))
            d._get_config.invalidate(userid)

    if updates:
        from weasyl import moderation
        moderation.note_about(my_userid, userid, 'The following fields were changed:', '\n'.join(updates))
コード例 #16
0
ファイル: submission.py プロジェクト: Syfaro/weasyl
def edit(userid, submission, embedlink=None, friends_only=False, critique=False):
    query = d.execute(
        "SELECT userid, subtype, settings FROM submission WHERE submitid = %i",
        [submission.submitid], ["single"])

    if not query or "h" in query[2]:
        raise WeasylError("Unexpected")
    elif "a" in query[2] and userid not in staff.MODS:
        raise WeasylError("AdminLocked")
    elif userid != query[0] and userid not in staff.MODS:
        raise WeasylError("InsufficientPermissions")
    elif not submission.title:
        raise WeasylError("titleInvalid")
    elif not submission.rating:
        raise WeasylError("Unexpected")
    elif not folder.check(query[0], submission.folderid):
        raise WeasylError("Unexpected")
    elif submission.subtype / 1000 != query[1] / 1000:
        raise WeasylError("Unexpected")
    elif 'v' in query[2] and not embed.check_valid(embedlink):
        raise WeasylError("embedlinkInvalid")
    elif 'D' in query[2]:
        check_google_doc_embed_data(embedlink)
    profile.check_user_rating_allowed(userid, submission.rating)

    # Assign settings
    settings = [query[2].replace("f", "").replace("q", "")]
    settings.append("f" if friends_only else "")
    settings.append("q" if critique else "")
    settings = "".join(settings)

    if "v" in settings:
        submission.content = "%s\n%s" % (embedlink, submission.content)

    if "f" in settings:
        welcome.submission_became_friends_only(submission.submitid, userid)

    # TODO(kailys): maintain ORM object
    db = d.connect()
    su = d.meta.tables['submission']
    q = (
        su.update()
        .values(
            folderid=submission.folderid,
            title=submission.title,
            content=submission.content,
            subtype=submission.subtype,
            rating=submission.rating,
            settings=settings,
        )
        .where(su.c.submitid == submission.submitid))
    db.execute(q)

    if 'D' in settings:
        db = d.connect()
        gde = d.meta.tables['google_doc_embeds']
        q = (gde.update()
             .values(embed_url=embedlink)
             .where(gde.c.submitid == submission.submitid))
        db.execute(q)

    if userid != query[0]:
        from weasyl import moderation
        moderation.note_about(
            userid, query[0], 'The following submission was edited:',
            '- ' + text.markdown_link(submission.title, '/submission/%s?anyway=true' % (submission.submitid,)))
コード例 #17
0
ファイル: profile.py プロジェクト: dzamie/weasyl
def do_manage(my_userid, userid, username=None, full_name=None, catchphrase=None,
              birthday=None, gender=None, country=None):
    updates = []

    # Username
    if username is not None:
        if not d.get_sysname(username):
            raise WeasylError("usernameInvalid")
        elif d.execute("SELECT EXISTS (SELECT 0 FROM login WHERE login_name = '%s')",
                       [d.get_sysname(username)], ["bool"]):
            raise WeasylError("usernameExists")
        elif d.execute("SELECT EXISTS (SELECT 0 FROM useralias WHERE alias_name = '%s')",
                       [d.get_sysname(username)], ["bool"]):
            raise WeasylError("usernameExists")
        elif d.execute("SELECT EXISTS (SELECT 0 FROM logincreate WHERE login_name = '%s')",
                       [d.get_sysname(username)], ["bool"]):
            raise WeasylError("usernameExists")

        d.execute("UPDATE login SET login_name = '%s' WHERE userid = %i",
                  [d.get_sysname(username), userid])
        d._get_display_name.invalidate(userid)
        d.execute("UPDATE profile SET username = '******' WHERE userid = %i",
                  [username, userid])
        updates.append('- Username: %s' % (username,))

    # Full name
    if full_name is not None:
        d.execute("UPDATE profile SET full_name = '%s' WHERE userid = %i",
                  [full_name, userid])
        updates.append('- Full name: %s' % (full_name,))

    # Catchphrase
    if catchphrase is not None:
        d.execute("UPDATE profile SET catchphrase = '%s' WHERE userid = %i",
                  [catchphrase, userid])
        updates.append('- Catchphrase: %s' % (catchphrase,))

    # Birthday
    if birthday is not None and d.convert_inputdate(birthday):
        unixtime = d.convert_inputdate(birthday)
        age = d.convert_age(unixtime)

        d.execute("UPDATE userinfo SET birthday = %i WHERE userid = %i", [unixtime, userid])

        if age < ratings.MODERATE.minimum_age:
            max_rating = ratings.GENERAL.code
            rating_flag = ""
        elif age < ratings.EXPLICIT.minimum_age:
            max_rating = ratings.MODERATE.code
            rating_flag = "m"
        else:
            max_rating = ratings.EXPLICIT.code

        if d.get_rating(userid) > max_rating:
            d.execute(
                """
                UPDATE profile
                SET config = REGEXP_REPLACE(config, '[map]', '', 'g') || '%s'
                WHERE userid = %i
                """,
                [rating_flag, userid]
            )
            d._get_config.invalidate(userid)
        updates.append('- Birthday: %s' % (birthday,))

    # Gender
    if gender is not None:
        d.execute("UPDATE userinfo SET gender = '%s' WHERE userid = %i",
                  [gender, userid])
        updates.append('- Gender: %s' % (gender,))

    # Location
    if country is not None:
        d.execute("UPDATE userinfo SET country = '%s' WHERE userid = %i",
                  [country, userid])
        updates.append('- Country: %s' % (country,))

    if updates:
        from weasyl import moderation
        moderation.note_about(my_userid, userid, 'The following fields were changed:', '\n'.join(updates))
コード例 #18
0
ファイル: profile.py プロジェクト: guptaarth87/weasyl
def do_manage(my_userid,
              userid,
              username=None,
              full_name=None,
              catchphrase=None,
              birthday=None,
              gender=None,
              country=None,
              remove_social=None,
              permission_tag=None):
    """Updates a user's information from the admin user management page.
    After updating the user it records all the changes into the mod notes.

    If an argument is None it will not be updated.

    Args:
        my_userid (int): ID of user making changes to other user.
        userid (int): ID of user to modify.
        username (str): New username for user. Defaults to None.
        full_name (str): New full name for user. Defaults to None.
        catchphrase (str): New catchphrase for user. Defaults to None.
        birthday (str): New birthday for user, in HTML5 date format (ISO 8601 yyyy-mm-dd). Defaults to None.
        gender (str): New gender for user. Defaults to None.
        country (str): New country for user. Defaults to None.
        remove_social (list): Items to remove from the user's social/contact links. Defaults to None.
        permission_tag (bool): New tagging permission for user. Defaults to None.

    Returns:
        Does not return.
    """
    updates = []

    # Username
    if username is not None:
        login.change_username(
            acting_user=my_userid,
            target_user=userid,
            bypass_limit=True,
            new_username=username,
        )

        updates.append('- Username: %s' % (username, ))

    # Full name
    if full_name is not None:
        d.engine.execute(
            "UPDATE profile SET full_name = %(full_name)s WHERE userid = %(user)s",
            full_name=full_name,
            user=userid)
        updates.append('- Full name: %s' % (full_name, ))

    # Catchphrase
    if catchphrase is not None:
        d.engine.execute(
            "UPDATE profile SET catchphrase = %(catchphrase)s WHERE userid = %(user)s",
            catchphrase=catchphrase,
            user=userid)
        updates.append('- Catchphrase: %s' % (catchphrase, ))

    # Birthday
    if birthday is not None:
        # HTML5 date format is yyyy-mm-dd
        split = birthday.split("-")
        if len(split) != 3 or d.convert_unixdate(
                day=split[2], month=split[1], year=split[0]) is None:
            raise WeasylError("birthdayInvalid")
        unixtime = d.convert_unixdate(day=split[2],
                                      month=split[1],
                                      year=split[0])
        age = d.convert_age(unixtime)

        d.execute("UPDATE userinfo SET birthday = %i WHERE userid = %i",
                  [unixtime, userid])

        if age < ratings.EXPLICIT.minimum_age:
            max_rating = ratings.GENERAL.code
            rating_flag = ""
        else:
            max_rating = ratings.EXPLICIT.code

        if d.get_rating(userid) > max_rating:
            d.engine.execute(
                """
                UPDATE profile
                SET config = REGEXP_REPLACE(config, '[ap]', '', 'g') || %(rating_flag)s
                WHERE userid = %(user)s
                """,
                rating_flag=rating_flag,
                user=userid,
            )
            d._get_all_config.invalidate(userid)
        updates.append('- Birthday: %s' % (birthday, ))

    # Gender
    if gender is not None:
        d.engine.execute(
            "UPDATE userinfo SET gender = %(gender)s WHERE userid = %(user)s",
            gender=gender,
            user=userid)
        updates.append('- Gender: %s' % (gender, ))

    # Location
    if country is not None:
        d.engine.execute(
            "UPDATE userinfo SET country = %(country)s WHERE userid = %(user)s",
            country=country,
            user=userid)
        updates.append('- Country: %s' % (country, ))

    # Social and contact links
    if remove_social:
        for social_link in remove_social:
            d.engine.execute(
                "DELETE FROM user_links WHERE userid = %(userid)s AND link_type = %(link)s",
                userid=userid,
                link=social_link)
            updates.append('- Removed social link for %s' % (social_link, ))

    # Permissions
    if permission_tag is not None:
        if permission_tag:
            query = (
                "UPDATE profile SET config = replace(config, 'g', '') "
                "WHERE userid = %(user)s AND position('g' in config) != 0")
        else:
            query = ("UPDATE profile SET config = config || 'g' "
                     "WHERE userid = %(user)s AND position('g' in config) = 0")

        if d.engine.execute(query, user=userid).rowcount != 0:
            updates.append('- Permission to tag: ' +
                           ('yes' if permission_tag else 'no'))
            d._get_all_config.invalidate(userid)

    if updates:
        from weasyl import moderation
        moderation.note_about(my_userid, userid,
                              'The following fields were changed:',
                              '\n'.join(updates))