예제 #1
0
def request(userid, submitid, otherid):
    query = d.engine.execute(
        "SELECT userid, rating, settings "
        "FROM submission WHERE submitid = %(submission)s",
        submission=submitid).first()

    rating = d.get_rating(userid)

    if not query or "h" in query.settings:
        raise WeasylError("Unexpected")
    if otherid != query.userid:
        raise WeasylError("Unexpected")

    # not checking for blocktags here because if you want to collect
    # something with a tag you don't like that's your business
    if rating < query.rating:
        raise WeasylError("RatingExceeded")
    if "f" in query.settings:
        raise WeasylError("collectionUnacceptable")
    if ignoreuser.check(otherid, userid):
        raise WeasylError("IgnoredYou")
    if ignoreuser.check(userid, otherid):
        raise WeasylError("YouIgnored")
    if _check_throttle(userid, otherid):
        raise WeasylError("collectionThrottle")

    settings = d.get_profile_settings(otherid)
    if not settings.allow_collection_requests:
        raise WeasylError("Unexpected")

    request_settings = "r"
    try:
        d.engine.execute(
            "INSERT INTO collection (userid, submitid, unixtime, settings) "
            "VALUES (%(userid)s, %(submitid)s, %(now)s, %(settings)s)",
            userid=userid,
            submitid=submitid,
            now=d.get_time(),
            settings=request_settings)
    except PostgresError:
        raise WeasylError("collectionExists")

    welcome.collectrequest_insert(userid, otherid, submitid)
예제 #2
0
파일: collection.py 프로젝트: 0x15/weasyl
def request(userid, submitid, otherid):
    query = d.engine.execute("SELECT userid, rating, settings "
                             "FROM submission WHERE submitid = %(submission)s",
                             submission=submitid).first()

    rating = d.get_rating(userid)

    if not query or "h" in query.settings:
        raise WeasylError("Unexpected")
    if otherid != query.userid:
        raise WeasylError("Unexpected")

    # not checking for blocktags here because if you want to collect
    # something with a tag you don't like that's your business
    if rating < query.rating:
        raise WeasylError("RatingExceeded")
    if "f" in query.settings:
        raise WeasylError("collectionUnacceptable")
    if ignoreuser.check(otherid, userid):
        raise WeasylError("IgnoredYou")
    if ignoreuser.check(userid, otherid):
        raise WeasylError("YouIgnored")
    if _check_throttle(userid, otherid):
        raise WeasylError("collectionThrottle")

    settings = d.get_profile_settings(otherid)
    if not settings.allow_collection_requests:
        raise WeasylError("Unexpected")

    request_settings = "r"
    try:
        d.engine.execute("INSERT INTO collection (userid, submitid, unixtime, settings) "
                         "VALUES (%(userid)s, %(submitid)s, %(now)s, %(settings)s)",
                         userid=userid, submitid=submitid, now=d.get_time(), settings=request_settings)
    except PostgresError:
        raise WeasylError("collectionExists")

    welcome.collectrequest_insert(userid, otherid, submitid)
예제 #3
0
 def can_notify(other):
     other_jsonb = d.get_profile_settings(other)
     allow_notify = other_jsonb.allow_collection_notifs
     not_ignored = not ignoreuser.check(other, userid)
     return allow_notify and not_ignored
예제 #4
0
def select_view(userid, submitid, rating, ignore=True, anyway=None):
    query = d.execute("""
        SELECT
            su.userid, pr.username, su.folderid, su.unixtime, su.title, su.content, su.subtype, su.rating, su.settings,
            su.page_views, su.sorttime, pr.config, fd.title
        FROM submission su
            INNER JOIN profile pr USING (userid)
            LEFT JOIN folder fd USING (folderid)
        WHERE su.submitid = %i
    """, [submitid],
                      options=["single", "list"])

    # Sanity check
    if query and userid in staff.MODS and anyway == "true":
        pass
    elif not query or "h" in query[8]:
        raise WeasylError("submissionRecordMissing")
    elif query[7] > rating and (
        (userid != query[0] and userid not in staff.MODS) or d.is_sfw_mode()):
        raise WeasylError("RatingExceeded")
    elif "f" in query[8] and not frienduser.check(userid, query[0]):
        raise WeasylError("FriendsOnly")
    elif ignore and ignoreuser.check(userid, query[0]):
        raise WeasylError("UserIgnored")
    elif ignore and blocktag.check(userid, submitid=submitid):
        raise WeasylError("TagBlocked")

    # Get submission filename
    submitfile = media.get_submission_media(submitid).get(
        'submission', [None])[0]

    # Get submission text
    if submitfile and submitfile['file_type'] in ['txt', 'htm']:
        submittext = files.read(submitfile['full_file_path'])
    else:
        submittext = None

    embedlink = d.text_first_line(query[5]) if "v" in query[8] else None

    google_doc_embed = None
    if 'D' in query[8]:
        db = d.connect()
        gde = d.meta.tables['google_doc_embeds']
        q = (sa.select([gde.c.embed_url]).where(gde.c.submitid == submitid))
        results = db.execute(q).fetchall()
        if not results:
            raise WeasylError("can't find embed information")
        google_doc_embed = results[0]

    tags, artist_tags = searchtag.select_with_artist_tags(submitid)
    settings = d.get_profile_settings(query[0])

    return {
        "submitid":
        submitid,
        "userid":
        query[0],
        "username":
        query[1],
        "folderid":
        query[2],
        "unixtime":
        query[3],
        "title":
        query[4],
        "content": (d.text_first_line(query[5], strip=True)
                    if "v" in query[8] else query[5]),
        "subtype":
        query[6],
        "rating":
        query[7],
        "settings":
        query[8],
        "page_views": (query[9] + 1 if d.common_view_content(
            userid, 0 if anyway == "true" else submitid, "submit") else
                       query[9]),
        "fave_count":
        d.execute(
            "SELECT COUNT(*) FROM favorite WHERE (targetid, type) = (%i, 's')",
            [submitid], ["element"]),
        "mine":
        userid == query[0],
        "reported":
        report.check(submitid=submitid),
        "favorited":
        favorite.check(userid, submitid=submitid),
        "friends_only":
        "f" in query[8],
        "hidden_submission":
        "h" in query[8],
        "collectors":
        collection.find_owners(submitid),
        "no_request":
        not settings.allow_collection_requests,
        "text":
        submittext,
        "sub_media":
        media.get_submission_media(submitid),
        "user_media":
        media.get_user_media(query[0]),
        "submit":
        submitfile,
        "embedlink":
        embedlink,
        "embed":
        embed.html(embedlink) if embedlink is not None else None,
        "google_doc_embed":
        google_doc_embed,
        "tags":
        tags,
        "artist_tags":
        artist_tags,
        "removable_tags":
        searchtag.removable_tags(userid, query[0], tags, artist_tags),
        "can_remove_tags":
        searchtag.can_remove_tags(userid, query[0]),
        "folder_more":
        select_near(userid, rating, 1, query[0], query[2], submitid),
        "folder_title":
        query[12] if query[12] else "Root",
        "comments":
        comment.select(userid, submitid=submitid),
    }
예제 #5
0
파일: submission.py 프로젝트: dzamie/weasyl
def select_view(userid, submitid, rating, ignore=True, anyway=None):
    query = d.execute("""
        SELECT
            su.userid, pr.username, su.folderid, su.unixtime, su.title, su.content, su.subtype, su.rating, su.settings,
            su.page_views, su.sorttime, pr.config, fd.title
        FROM submission su
            INNER JOIN profile pr USING (userid)
            LEFT JOIN folder fd USING (folderid)
        WHERE su.submitid = %i
    """, [submitid], options=["single", "list"])

    # Sanity check
    if query and userid in staff.MODS and anyway == "true":
        pass
    elif not query or "h" in query[8]:
        raise WeasylError("submissionRecordMissing")
    elif query[7] > rating and ((userid != query[0] and userid not in staff.MODS) or d.is_sfw_mode()):
        raise WeasylError("RatingExceeded")
    elif "f" in query[8] and not frienduser.check(userid, query[0]):
        raise WeasylError("FriendsOnly")
    elif ignore and ignoreuser.check(userid, query[0]):
        raise WeasylError("UserIgnored")
    elif ignore and blocktag.check(userid, submitid=submitid):
        raise WeasylError("TagBlocked")

    # Get submission filename
    submitfile = media.get_submission_media(submitid).get('submission', [None])[0]

    # Get submission text
    if submitfile and submitfile['file_type'] in ['txt', 'htm']:
        submittext = files.read(submitfile['full_file_path'])
    else:
        submittext = None

    embedlink = d.text_first_line(query[5]) if "v" in query[8] else None

    google_doc_embed = None
    if 'D' in query[8]:
        db = d.connect()
        gde = d.meta.tables['google_doc_embeds']
        q = (sa.select([gde.c.embed_url])
             .where(gde.c.submitid == submitid))
        results = db.execute(q).fetchall()
        if not results:
            raise WeasylError("can't find embed information")
        google_doc_embed = results[0]

    tags, artist_tags = searchtag.select_with_artist_tags(submitid)
    settings = d.get_profile_settings(query[0])

    return {
        "submitid": submitid,
        "userid": query[0],
        "username": query[1],
        "folderid": query[2],
        "unixtime": query[3],
        "title": query[4],
        "content": (d.text_first_line(query[5], strip=True) if "v" in query[8] else query[5]),
        "subtype": query[6],
        "rating": query[7],
        "settings": query[8],
        "page_views": (
            query[9] + 1 if d.common_view_content(userid, 0 if anyway == "true" else submitid, "submit") else query[9]),
        "fave_count": d.execute(
            "SELECT COUNT(*) FROM favorite WHERE (targetid, type) = (%i, 's')",
            [submitid], ["element"]),


        "mine": userid == query[0],
        "reported": report.check(submitid=submitid),
        "favorited": favorite.check(userid, submitid=submitid),
        "friends_only": "f" in query[8],
        "hidden_submission": "h" in query[8],
        "collectors": collection.find_owners(submitid),
        "no_request": not settings.allow_collection_requests,

        "text": submittext,
        "sub_media": media.get_submission_media(submitid),
        "user_media": media.get_user_media(query[0]),
        "submit": submitfile,
        "embedlink": embedlink,
        "embed": embed.html(embedlink) if embedlink is not None else None,
        "google_doc_embed": google_doc_embed,


        "tags": tags,
        "artist_tags": artist_tags,
        "removable_tags": searchtag.removable_tags(userid, query[0], tags, artist_tags),
        "can_remove_tags": searchtag.can_remove_tags(userid, query[0]),
        "folder_more": select_near(userid, rating, 1, query[0], query[2], submitid),
        "folder_title": query[12] if query[12] else "Root",


        "comments": comment.select(userid, submitid=submitid),
    }
예제 #6
0
파일: favorite.py 프로젝트: weykent/weasyl
 def can_notify(other):
     other_jsonb = d.get_profile_settings(other)
     allow_notify = other_jsonb.allow_collection_notifs
     not_ignored = not ignoreuser.check(other, userid)
     return allow_notify and not_ignored