Exemple #1
0
    def test_submission_becomes_friends_only(self):
        """
        Submissions becoming friends-only should be removed from non-friends'
        notification lists.
        """
        # Initial behavior should match with normal.
        s = db_utils.create_submission(self.owner)
        welcome.submission_insert(self.owner, s)
        self.assertEqual(1, self._notification_count(self.friend))
        self.assertEqual(1, self._notification_count(self.nonfriend))
        self.assertEqual(1, self._notification_count(self.ignored))

        welcome.submission_became_friends_only(s, self.owner)
        self.assertEqual(1, self._notification_count(self.friend))
        self.assertEqual(0, self._notification_count(self.nonfriend))
        self.assertEqual(0, self._notification_count(self.ignored))
Exemple #2
0
    def test_submission_becomes_friends_only(self):
        """
        Submissions becoming friends-only should be removed from non-friends'
        notification lists.
        """
        # Initial behavior should match with normal.
        s = db_utils.create_submission(self.owner)
        welcome.submission_insert(self.owner, s)
        self.assertEquals(1, self._notification_count(self.friend))
        self.assertEquals(1, self._notification_count(self.nonfriend))
        self.assertEquals(1, self._notification_count(self.ignored))

        welcome.submission_became_friends_only(s, self.owner)
        self.assertEquals(1, self._notification_count(self.friend))
        self.assertEquals(0, self._notification_count(self.nonfriend))
        self.assertEquals(0, self._notification_count(self.ignored))
Exemple #3
0
def edit(userid,
         submission,
         embedlink=None,
         friends_only=False,
         critique=False):
    query = d.engine.execute(
        "SELECT userid, subtype, settings FROM submission WHERE submitid = %(id)s",
        id=submission.submitid).first()

    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, )))
Exemple #4
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,)))