コード例 #1
0
    def test_saving_validates_name(self):
        """
        Creates shakes with valid and invalid names
        """
        valid_names = [
            'a-b-c', 'qwerty', '1234', '2a93sfj', 'asdfgasdfgasdfgasdfgasdfg'
        ]
        invalid_names = [
            '',
            None,
            'a x',
            'AsDf',
            'static',  #asdf exists in the setup, static is reserved
            'asdfgasdfgasdfgasdfgasdfgx'
        ]  #too long

        for name in valid_names:
            self.assertTrue(
                Shake(user_id=self.user.id,
                      title="some text",
                      name=name,
                      type='group').save())
        for name in invalid_names:
            self.assertFalse(
                Shake(user_id=self.user.id,
                      title="some text",
                      name=name,
                      type='group').save())
コード例 #2
0
    def post(self):
        name = self.get_argument("name", '')
        description = self.get_argument("description", '')
        title = self.get_argument("title", '')
        user_object = self.get_current_user_object()

        if not user_object.is_plus():
            return self.redirect('/account/membership?upgrade=1')

        if len(user_object.shakes()) < 101:
            new_shake = Shake(name=name,
                              title=title,
                              description=description,
                              user_id=user_object.id,
                              type='group')
            try:
                if new_shake.save():
                    return self.redirect('/%s' % (new_shake.name))
            except torndb.IntegrityError:
                # This is a rare edge case, so we handle it lazily -- IK.
                pass
            self.add_errors(new_shake.errors)
            return self.render("shakes/create.html", shake=new_shake)
        else:
            return self.render("shakes/no-create.html")
コード例 #3
0
ファイル: account_tests.py プロジェクト: wjcstp/mltshp
    def test_quick_notifications(self):
        """
        /account/quick-notifications should return without error when populated with
        all possible  notification types.

        Page should also not be accessible if you're not signed in.
        """
        self.user2 = User(name='example2',email='*****@*****.**', \
            verify_email_token = 'created', password='******', email_confirmed=1,
            is_paid=1)
        self.user2.save()
        self.sourcefile = Sourcefile(width=20,height=20,file_key="asdf", \
            thumb_key="asdf_t")
        self.sourcefile.save()
        self.sharedfile = Sharedfile(source_id=self.sourcefile.id, name="my shared file", \
            user_id=self.user.id, content_type="image/png", share_key="ok")
        self.sharedfile.save()
        self.shake = Shake(user_id=self.user2.id,
                           name='asdf',
                           type='group',
                           title='My Test Shake',
                           description='Testing this shake test.')
        self.shake.save()

        # new subscription
        new_sub = Subscription(user_id=self.user2.id, shake_id=1)
        new_sub.save()
        new_subscriber = Notification.new_subscriber(sender=self.user2,
                                                     receiver=self.user,
                                                     action_id=new_sub.id)
        # new favorite
        new_favorite = Notification.new_favorite(sender=self.user2,
                                                 sharedfile=self.sharedfile)
        # new save
        new_save = Notification.new_save(sender=self.user2,
                                         sharedfile=self.sharedfile)
        # new comment
        new_comment = Comment(user_id=self.user2.id,
                              sharedfile_id=self.sharedfile.id,
                              body="Testing comment")
        new_comment.save()
        # new mention
        new_mention = Notification.new_mention(receiver=self.user,
                                               comment=new_comment)
        # new invitation
        new_mention = Notification.new_invitation(sender=self.user2,
                                                  receiver=self.user,
                                                  action_id=self.shake.id)

        response = self.fetch_url('/account/quick-notifications')
        self.assertEqual(200, response.code)
        self.sign_out()
        response = self.fetch_url('/account/quick-notifications',
                                  follow_redirects=False)
        self.assertEqual(302, response.code)
コード例 #4
0
ファイル: admin.py プロジェクト: wjcstp/mltshp
    def get(self, shake_id=None):
        shake = Shake.get('id=%s and type=%s', shake_id, 'group')
        shake_categories = ShakeCategory.all()
        featured_shakes = Shake.where('featured = 1')
        if not shake:
            return self.redirect("/admin/group-shakes")

        return self.render("admin/group-shake-view.html",
                           shake=shake,
                           shake_categories=shake_categories,
                           featured_shakes=featured_shakes)
コード例 #5
0
    def setUp(self):
        super(ShakeModelTests, self).setUp()
        self.user = User(name='admin',
                         email='*****@*****.**',
                         email_confirmed=1)
        self.user.set_password('asdfasdf')
        self.user.save()

        self.shake = Shake(user_id=self.user.id,
                           name='asdf',
                           type='group',
                           title='My Test Shake',
                           description='Testing this shake test.')
        self.shake.save()
コード例 #6
0
ファイル: account.py プロジェクト: wjcstp/mltshp
    def post(self):
        password = self.get_argument('password', "")
        name = self.get_argument('name', "")
        if password == "" or name == "":
            self.add_error('name', "I could not find that user name and password combination.")
            return self.render(self.use_template, name=name, next=self.next)

        user = User.authenticate(name, password)
        if user:
            self.log_user_in(user)
            if self.next:
                return self.redirect(self.next)
            else:
                return self.redirect("/")
        else:
            unmigrated_user = User.find_unmigrated_user(name, password)
            if unmigrated_user:
                # undelete the user account and log them in...
                unmigrated_user.deleted = 0
                unmigrated_user.save()

                # also, find their personal shake and restore that
                # specifically. does not restore any images within it--
                # the user will need to invoke a migration for that.
                shake = Shake.get(
                    'user_id=%s and type=%s and deleted=2', unmigrated_user.id, 'user')
                if shake is not None:
                    shake.deleted = 0
                    shake.save()

                self.log_user_in(unmigrated_user)
                return self.redirect("/account/welcome-to-mltshp")

            self.add_error('name', "I could not find that user name and password combination.")
            return self.render(self.use_template, name=name, next=self.next)
コード例 #7
0
    def post(self, share_key):
        sharedfile = Sharedfile.get_by_share_key(share_key)
        if not sharedfile:
            raise tornado.web.HTTPError(404)

        current_user = self.get_current_user_object()
        if not current_user:
            raise tornado.web.HTTPError(403)

        json = self.get_arguments('json', False)
        if not sharedfile.can_save(current_user):
            if json:
                return self.write({'error' : "Can't save that file."})
            else:
                return self.redirect("/p/%s" % sharedfile.share_key)

        count = sharedfile.save_count

        shake_id = self.get_argument('shake_id', None)
        if shake_id:
            shake = Shake.get("id = %s", shake_id)
            if shake and shake.can_update(current_user.id):
                new_sharedfile = sharedfile.save_to_shake(current_user, shake)
            else:
                return self.write({'error' : "Can't save that file."})
        else:
            new_sharedfile = sharedfile.save_to_shake(current_user)
        if json:
            return self.write({
                'new_share_key' : new_sharedfile.share_key,
                'share_key' : sharedfile.share_key,
                'count' : count + 1
            })
        else:
            return self.redirect("/p/%s" % new_sharedfile.share_key)
コード例 #8
0
    def get(self, user_name=None, page=None):
        user_object = User.get("name=%s", user_name)
        if not page:
            page = 1

        page = int(page)

        if user_object:
            following = user_object.following(page=page)
            following_objects = []
            for f in following:
                if f['type'] == 'user':
                    f['related_object'] = User.get('id=%s', f['id'])
                elif f['type'] == 'shake':
                    f['related_object'] = Shake.get('id=%s', f['id'])
                following_objects.append(f)

            following_count = user_object.following_count()

            url_format = '/user/%s/following/' % user_object.name
            url_format = url_format + '%d'
            return self.render("account/following.html",
                               following=following_objects,
                               user_info=user_object,
                               url_format=url_format,
                               following_count=following_count,
                               page=page)
        else:
            raise tornado.web.HTTPError(404)
コード例 #9
0
    def post(self, sharedfile_key):
        user = User.get('id=%s', self.oauth2_user_id)

        sharedfile = Sharedfile.get_by_share_key(sharedfile_key)
        if not sharedfile:
            self.set_status(404)
            return self.write({'error': 'No such file.'})

        if not sharedfile.can_save(user):
            self.set_status(400)
            return self.write({'error': "Can't save own file."})

        shake = None
        count = sharedfile.save_count
        shake_id = self.get_argument('shake_id', None)
        if shake_id:
            shake = Shake.get("id = %s", shake_id)
            if not shake:
                self.set_status(404)
                return self.write({'error': "No such shake."})

        if shake and not shake.can_update(user.id):
            self.set_status(403)
            return self.write({'error': "No permission to save to shake."})

        already_saved = user.saved_sharedfile(sharedfile)
        if already_saved:
            return self.write(sharedfile.as_json(user_context=user))

        new_sharedfile = sharedfile.save_to_shake(user, shake)
        sharedfile_json = sharedfile.as_json(user_context=user)
        sharedfile_json['saves'] = count + 1
        return self.write(sharedfile_json)
コード例 #10
0
    def get(self, type, resource=''):
        shake = None
        if type == 'shake_name':
            shake = Shake.get('name=%s and deleted=0', resource)
        elif type == 'shake_id':
            shake = Shake.get('id=%s and deleted=0', resource)
        elif type == 'shake_user':
            user = User.get('name=%s and deleted=0', resource)
            if user is not None:
                shake = user.shake()

        if not shake:
            self.set_status(404)
            return self.write({'error': "No such shake."})

        return self.write(shake.as_json(extended=True))
コード例 #11
0
ファイル: shake_crud_tests.py プロジェクト: wjcstp/mltshp
    def test_subscribe_unsubscribe_works(self):
        user_a = User(name='user_a',
                      email='*****@*****.**',
                      email_confirmed=1,
                      is_paid=1,
                      stripe_plan_id="mltshp-double")
        user_a.set_password('asdfasdf')
        user_a.save()
        self.sign_in('user_a', 'asdfasdf')
        arguments = {
            'name': 'asdf',
            'description': 'A shake test.',
            'title': 'Shake Test',
        }
        self.post_url('/shake/create', arguments=arguments)
        shake = Shake.get('name = %s', 'asdf')

        self.sign_in('admin', 'asdfasdf')
        self.post_url('/shake/%s/subscribe?json=1' % shake.id)

        #subscription #1 is the user subscribing to their own new shake
        subscription = Subscription.get('id=2')
        self.assertEqual(subscription.user_id, 1)
        self.assertEqual(subscription.deleted, 0)

        self.post_url('/shake/%s/unsubscribe?json=1' % shake.id)

        #subscription #1 is the user subscribing to their own new shake
        subscription = Subscription.get('id=2')
        self.assertEqual(subscription.user_id, 1)
        self.assertEqual(subscription.deleted, 1)
コード例 #12
0
 def get(self, shake_name):
     shake = Shake.get("name=%s", shake_name)
     if not shake:
         raise tornado.web.HTTPError(404)
     
     current_user = self.get_current_user_object()
     invitation, invitation_requests = _invitations(shake, current_user)
     
     #is this user a shake manager?
     managers = shake.managers()
     is_shake_manager = False
     if managers and current_user:
         for manager in managers:
             if manager.id == current_user.id:
                 is_shake_manager = True
                 break
     
     followers = shake.subscribers()
     follower_count = shake.subscriber_count()
     
     return self.render("shakes/members.html", shake=shake, invitation=invitation,
         managers=shake.managers(), current_user_obj=current_user,
         invitation_requests=invitation_requests, shake_editor=shake.owner(),
         is_shake_manager=is_shake_manager, followers=followers,
         follower_count=follower_count)
コード例 #13
0
    def setUp(self):
        super(CeleryTaskTests, self).setUp()  # register connection.

        #create two users.
        self.user_a = User(name='user_a',
                           email='*****@*****.**',
                           verify_email_token='created')
        self.user_a.save()
        self.user_b = User(name='user_b',
                           email='*****@*****.**',
                           verify_email_token='created')
        self.user_b.save()

        #have the second user follow the first
        self.shake_a = Shake.get('user_id = %s and type=%s', self.user_a.id,
                                 'user')
        self.user_b.subscribe(self.shake_a)

        #user one adds two files to their shake
        self.source = Sourcefile(width=20,
                                 height=20,
                                 file_key="asdf",
                                 thumb_key="asdf_t")
        self.source.save()

        self.shared_1 = Sharedfile(source_id=self.source.id, name="my shared file",user_id=self.user_a.id, \
            content_type="image/png", share_key="oj")
        self.shared_1.save()

        self.shared_2 = Sharedfile(source_id=self.source.id, name="my shared file",user_id=self.user_a.id, \
            content_type="image/png", share_key="ok")
        self.shared_2.save()
コード例 #14
0
    def post(self, shake_name=None):
        shake = Shake.get('name=%s', shake_name)
        current_user_object = self.get_current_user_object()
        requestor = User.get('id = %s', self.get_argument('user_id', None))
        
        if not shake:
            raise tornado.web.HTTPError(404)
            
        if not requestor:
            if self.get_argument('json', None):
                return self.write({'status':'error'})
            else:
                return self.redirect('/%s', shake.name)
        
        no = Notification.get('sender_id = %s and receiver_id = %s and action_id = %s and deleted = 0', requestor.id, current_user_object.id, shake.id)

        if not no:
            if self.get_argument('json', None):
                return self.write({'status':'error'})
            else:
                return self.redirect('/%s' % (shake.name))
        
        no.delete()
        
        if self.get_argument('json', None):
            return self.write({'status':'ok', 'count' : Notification.count_for_user_by_type(current_user_object.id, 'invitation_request')})
        else:
            return self.redirect('/%s' % (shake.name))
コード例 #15
0
ファイル: sharedfile_tests.py プロジェクト: vosechu/mltshp
    def test_sharedfile_saved_to_group_shake(self):
        test_files = os.path.join(os.path.dirname(os.path.dirname(__file__)), "files")
        file_key = Sourcefile.get_sha1_file_key(test_files + "/1.png")
        shutil.copyfile("%s/1.png" % (test_files), "/tmp/%s" % (file_key))

        #create a new shake
        group_shake = Shake(user_id=self.user.id, type='group', title='asdf', name='asdf')
        group_shake.save()

        a_shared_file = Sharedfile.create_from_file("/tmp/%s" % (file_key),"1.png", file_key, "image/png", self.user.id, group_shake.id)
        self.assertTrue(group_shake.can_update(self.user.id))

        a_shared_file.add_to_shake(self.user.shake())

        ssfs = Shakesharedfile.all()
        for ssf in ssfs:
            self.assertEqual(ssf.sharedfile_id, a_shared_file.id)
コード例 #16
0
 def post(self, shake_name=None):
     shake = Shake.get("name=%s", shake_name)
     if not shake:
         raise tornado.web.HTTPError(404)
     current_user_object = self.get_current_user_object()
     sm = ShakeManager.get('user_id=%s and shake_id=%s and deleted = 0', current_user_object.id, shake.id)
     if sm:
         sm.delete()
     return self.redirect(shake.path())
コード例 #17
0
ファイル: tools.py プロジェクト: billturner/mltshp
    def get(self, name):
        category = ShakeCategory.get("short_name = %s", name)
        if not category:
            raise tornado.web.HTTPError(404)

        user = self.get_current_user_object()
        shakes = Shake.for_category(category)
        return self.render("tools/find-shakes-quick-fetch-category.html",
                           shakes=shakes,
                           current_user_obj=user)
コード例 #18
0
ファイル: tools.py プロジェクト: billturner/mltshp
 def get(self):
     user = self.get_current_user_object()
     categories = ShakeCategory.all('ORDER BY name')
     users_sidebar = User.recommended_for_user(user)
     featured_shakes = Shake.featured_shakes(3)
     return self.render('tools/find-shakes.html',
                        current_user_obj=user,
                        users_sidebar=users_sidebar,
                        categories=categories,
                        featured_shakes=featured_shakes)
コード例 #19
0
ファイル: admin.py プロジェクト: wjcstp/mltshp
 def post(self, shake_id=None):
     shake = Shake.get('id=%s and type=%s', shake_id, 'group')
     if self.get_argument('shake_category_id', None):
         shake.shake_category_id = self.get_argument('shake_category_id', 0)
     if self.get_argument('featured', None):
         shake.featured = 1
     else:
         shake.featured = 0
     shake.save()
     return self.redirect('/admin/group-shake/%s' % (shake_id))
コード例 #20
0
    def get(self, shake_name=None):
        shake = Shake.get("name=%s", shake_name)
        if not shake:
            raise tornado.web.HTTPError(404)
        build_date = shake.feed_date()
        sharedfiles = shake.sharedfiles(per_page=20)
        if sharedfiles:
            build_date = sharedfiles[0].feed_date()

        self.set_header("Content-Type", "application/xml")
        return self.render("shakes/rss.html", shake=shake, sharedfiles=sharedfiles, build_date=build_date)
コード例 #21
0
ファイル: tools.py プロジェクト: billturner/mltshp
    def on_thumbnail_response(self, response):
        if response.code != 200:
            self.render(
                "tools/save-video-error.html",
                message=
                "We could not load the thumbnail for this file and therefore could not save this video. Please contact support."
            )
            return

        # save the response
        url = self.get_argument('url')
        current_user = self.get_current_user_object()

        sha1_key = Sourcefile.get_sha1_file_key(file_path=None, file_data=url)
        thumbnail_path = "%s/%s" % (options.uploaded_files, sha1_key)
        fh = open(thumbnail_path, 'wb')
        fh.write(response.body)
        fh.close()
        source_file = Sourcefile.create_from_json_oembed(
            link=url,
            oembed_doc=self.oembed_doc,
            thumbnail_file_path=thumbnail_path)
        #cleanup
        if not options.debug:
            try:
                os.remove(thumbnail_path)
            except:
                pass

        title = ''
        if self.oembed_doc.has_key('title'):
            title = self.oembed_doc['title']

        shared_file = Sharedfile(user_id=current_user.id,
                                 name=url,
                                 content_type='text/html',
                                 source_id=source_file.id,
                                 title=title,
                                 source_url=url)
        shared_file.save()

        share_key = base36encode(shared_file.id)
        shared_file.share_key = share_key
        shared_file.save()

        user_shake = Shake.get('user_id = %s and type=%s', current_user.id,
                               'user')
        shared_file.add_to_shake(self.destination_shake)

        if self.oembed_doc.has_key('description'):
            shared_file.description = self.oembed_doc['description']

        self.write({'path': "/p/%s" % (share_key)})
        self.finish()
コード例 #22
0
 def get(self):
     user_object = self.get_current_user_object()
     
     if not user_object.is_paid:
         return self.redirect('/account/subscribe')
     
     if len(user_object.shakes()) < 100:
         new_shake = Shake(name='', title='', description='')
         return self.render("shakes/create.html", shake=new_shake)
     else:
         return self.render("shakes/no-create.html")
コード例 #23
0
    def setUp(self):
        super(RequestInvitationTests, self).setUp()
        self.user = User(name='joe',
                         email='*****@*****.**',
                         email_confirmed=1)
        self.user.set_password('asdfasdf')
        self.user.save()
        self.sign_in("joe", "asdfasdf")

        self.manager = User(name='admin',
                            email='*****@*****.**',
                            email_confirmed=1)
        self.manager.set_password('asdfasdf')
        self.manager.save()

        self.shake = Shake(user_id=self.manager.id,
                           type='group',
                           title="derp",
                           name='derp')
        self.shake.save()
コード例 #24
0
ファイル: tools.py プロジェクト: billturner/mltshp
 def post(self):
     url = self.get_argument('url', None)
     if not url:
         self.render("tools/save-video.html",
                     url=url,
                     title=None,
                     description=None)
     url = Sourcefile.make_oembed_url(url.strip())
     if url:
         current_user = self.get_current_user_object()
         shake_id = self.get_argument('shake_id', None)
         if not shake_id:
             self.destination_shake = Shake.get('user_id=%s and type=%s',
                                                current_user.id, 'user')
         else:
             self.destination_shake = Shake.get('id=%s', shake_id)
             if not self.destination_shake:
                 return self.render(
                     "tools/save-video-error.html",
                     message=
                     "We couldn't save the video to specified shake. Please contact support."
                 )
             if not self.destination_shake.can_update(current_user.id):
                 return self.render(
                     "tools/save-video-error.html",
                     message=
                     "We couldn't save the video to specified shake. Please contact support."
                 )
             if current_user.email_confirmed != 1:
                 return self.render(
                     "tools/save-video-error.html",
                     message=
                     "You must confirm your email address before you can post."
                 )
         self.handle_oembed_url(url)
     else:
         self.render(
             "tools/save-video-error.html",
             message=
             "We could not load the embed code. The video server may be down. Please contact support."
         )
コード例 #25
0
ファイル: sharedfile_tests.py プロジェクト: vosechu/mltshp
    def test_can_user_delete_from_shake(self):
        """
        A user can only delete from a shake if they are the owner of the sharedfile
        or the owner of the shake.
        """
        user_shake = self.user.shake()
        self.sharedfile.add_to_shake(user_shake)
        self.assertEqual(True, self.sharedfile.can_user_delete_from_shake(self.user, user_shake))

        # A user that doesn't own the sharedfile
        new_user = User(name='new_user',email='*****@*****.**',verify_email_token='created', email_confirmed=0)
        new_user.save()
        self.assertEqual(False, self.sharedfile.can_user_delete_from_shake(new_user, user_shake))

        # Owner of a group shake, but file doesn't belong to them.
        group_shake = Shake(user_id=new_user.id, type='group', title='Bears', name='bears')
        group_shake.save()
        self.sharedfile.add_to_shake(group_shake)
        self.assertEqual(True, self.sharedfile.can_user_delete_from_shake(new_user, group_shake))
        # owner of file, but not of shake.
        self.assertEqual(True, self.sharedfile.can_user_delete_from_shake(self.user, group_shake))
コード例 #26
0
ファイル: admin.py プロジェクト: wjcstp/mltshp
 def post(self, type=None):
     shake_to_update = Shake.get("id = %s and type=%s",
                                 self.get_argument('shake_id', None),
                                 'group')
     if shake_to_update:
         if type == "recommend":
             shake_to_update.recommended = 1
             shake_to_update.save()
         elif type == 'unrecommend':
             shake_to_update.recommended = 0
             shake_to_update.save()
     return self.redirect("/admin/recommend-group-shake")
コード例 #27
0
    def test_saving_validates_title(self):
        """
        Creates shakes with valid and invalid titles
        """
        valid_titles = ['asdf', 'This is a test.']
        invalid_titles = ['', None]
        identifier = 1

        for title in valid_titles:
            self.assertTrue(
                Shake(user_id=self.user.id,
                      title=title,
                      name='testing%s' % (identifier),
                      type='group').save())
            identifier += 1
        for title in invalid_titles:
            self.assertFalse(
                Shake(user_id=self.user.id,
                      title=title,
                      name='testing%s' % (identifier),
                      type='group').save())
            identifier += 1
コード例 #28
0
 def post(self, share_key):
     current_user = self.get_current_user_object()
     sharedfile = Sharedfile.get_by_share_key(share_key)
     if not sharedfile:
         raise tornado.web.HTTPError(404)
     if current_user.id != sharedfile.user_id:
         raise tornado.web.HTTPError(403)
     shakes = self.get_arguments('shakes', [])
     for shake_id in shakes:
         shake = Shake.get("id = %s", shake_id)
         if shake.can_update(current_user.id):
             sharedfile.add_to_shake(shake)
     return self.redirect("/p/%s" % sharedfile.share_key)
コード例 #29
0
 def test_shake_create_success(self):
     """
     Create a shake for user admin. Should succeed and redirect to /short_name
     """
     arguments = {
         'name': 'yo',
         'description': 'My little corner of the world',
         'title': 'title'
     }
     response = self.post_url('/shake/create', arguments=arguments)
     s = Shake.get('name=%s', 'yo')
     self.assertEqual(response.effective_url, self.get_url('/yo'))
     self.assertTrue(s)
コード例 #30
0
    def test_shake_update_description(self):
        arguments = {
            'name': 'test1',
            'description': 'OLD OLD OLD',
            'title': 'indeed'
        }
        response = self.post_url('/shake/create', arguments=arguments)

        arguments = {'description': 'NEW NEW NEW'}

        response = self.post_url('/shake/test1/update', arguments=arguments)
        shake = Shake.get("name=%s", 'test1')
        self.assertEqual(arguments['description'], shake.description)