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))
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)
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)
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)
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)
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)
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))
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)
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()
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())
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))
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)
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()
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)
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." )
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")
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)
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)
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)
def post(self, shake_name): is_json = self.get_argument('json', None) current_user_object = self.get_current_user_object() invitation_notification = Notification.get( 'id = %s and receiver_id = %s and type = %s and deleted = 0', self.get_argument('id', 0), current_user_object.id, 'invitation') if not invitation_notification: if is_json: return self.write({'error': 'error'}) else: return self.redirect("/") shake_object = Shake.get('id = %s', invitation_notification.action_id) shake_manager = ShakeManager.get('user_id = %s and shake_id = %s', current_user_object.id, shake_object.id) if shake_manager: shake_manager.deleted = 0 shake_manager.save() else: shake_manager = ShakeManager(user_id=current_user_object.id, shake_id=shake_object.id) shake_manager.save() invitation_notification.deleted = 1 invitation_notification.save() #send email to owner of shake #set all invitation notifications for this shake, user, to deleted all_notifications = Notification.where( 'sender_id = %s and action_id = %s and receiver_id = %s and deleted = 0', invitation_notification.sender_id, invitation_notification.action_id, invitation_notification.receiver_id) for n in all_notifications: n.deleted = 1 n.save() if is_json: remaining_notifications_count = Notification.where_count("type = %s and receiver_id = %s and deleted = 0", \ "invitation", current_user_object.id) return self.write({ 'response': 'ok', 'count': remaining_notifications_count }) else: return self.redirect("/%s", shake_object.name)
def test_creating_group_shake_creates_subscription(self): """ Create a shake for user admin. Admin should now have a subscription to that shake """ arguments = { 'name': 'yo', 'description': 'My little corner of the world', 'title': 'title' } self.post_url('/shake/create', arguments=arguments) sh = Shake.get('name=%s', arguments['name']) sub = Subscription.get('user_id=%s and shake_id=%s and deleted = 0', self.user.id, sh.id) self.assertTrue(sub)
def post(self, shake_name=None): shake = Shake.get('name=%s and user_id = %s', shake_name, self.current_user['id']) if not shake: raise tornado.web.HTTPError(404) sm = ShakeManager.get('user_id = %s and shake_id = %s and deleted = 0', self.get_argument('user_id', 0), shake.id) if sm: sm.delete() former_member = User.get('id=%s', self.get_argument('user_id')) Notification.send_shake_member_removal(shake, former_member) return self.write({'status':'ok'}) raise tornado.web.HTTPError(403)
def get(self, shake_name): shake = Shake.get("name=%s", shake_name) if not shake: raise tornado.web.HTTPError(404) value = { 'title' : escape.xhtml_escape(shake.title) if shake.title else '', 'title_raw' : shake.title if shake.title else '', 'description' : escape.xhtml_escape(shake.description) if shake.description else '', 'description_raw' : shake.description if shake.description else '' } # prevents IE from caching ajax requests. self.set_header("Cache-Control","no-store, no-cache, must-revalidate"); self.set_header("Pragma","no-cache"); self.set_header("Expires", 0); return self.write(escape.json_encode(value))
def post(self, shake_name): current_user = self.get_current_user_object() shake_to_update = Shake.get('name=%s and user_id=%s and type=%s', shake_name, current_user.id, 'group') new_title = self.get_argument('title', None) new_description = self.get_argument('description', None) if not shake_to_update: return self.write({'error':'No permission to update shake.'}) if new_title: shake_to_update.title = new_title if new_description: shake_to_update.description = new_description shake_to_update.save() return self.redirect('/shake/' + shake_to_update.name + '/quick-details')
def post(self, share_key, shake_id): current_user = self.get_current_user_object() sharedfile = Sharedfile.get_by_share_key(share_key) shake = Shake.get("id = %s", shake_id) if not sharedfile: raise tornado.web.HTTPError(404) if not shake: raise tornado.web.HTTPError(404) if not sharedfile.can_user_delete_from_shake(current_user, shake): raise tornado.web.HTTPError(403) sharedfile.delete_from_shake(shake) redirect_to = self.get_argument("redirect_to", None) if redirect_to: return self.redirect(redirect_to) else: return self.redirect("/p/%s" % sharedfile.share_key)
def get(self, shake_name=None, page=None): shake_object = Shake.get("name=%s", shake_name) if not page: page = 1 page = int(page) if not shake_object: raise tornado.web.HTTPError(404) followers = shake_object.subscribers(page=page) follower_count = shake_object.subscriber_count() url_format = '/shake/%s/followers/' % shake_object.name url_format = url_format + '%d' return self.render("shakes/followers.html", followers=followers, shake_info=shake_object, url_format=url_format, follower_count=follower_count, page=page)
def post(self, shake_name=None): shake = Shake.get('name=%s', shake_name) current_user_object = self.get_current_user_object() if not shake: raise tornado.web.HTTPError(404) if current_user_object.can_request_invitation_to_shake(shake.id): current_user_object.request_invitation_to_shake(shake.id) if self.get_argument('json', None): return self.write({'status':'ok'}) else: return self.redirect('/%s' % (shake.name)) else: if self.get_argument('json', None): return self.write({'status':'error', 'message':'not allowed'}) else: return self.redirect('/')
def post(self, shake_name=None): current_user = self.get_current_user_object() if current_user.email_confirmed != 1: return self.write({ 'error': 'You must confirm your email address to save this post.' }) if shake_name is None: shake_name = self.get_argument('shake_name', None) shake_to_update = Shake.get( 'name=%s and user_id=%s and type=%s and deleted=0', shake_name, current_user.id, 'group') json = self.get_argument('json', None) new_title = self.get_argument('title', None) new_description = self.get_argument('description', None) file_path = self.get_argument("file_path", None) file_name = self.get_argument("file_name", None) sha1_value = self.get_argument("file_sha1", None) content_type = self.get_argument("file_content_type", None) json_response = {} if not shake_to_update: if json: return self.write({'error': 'No permission to update shake.'}) else: return self.redirect("/") if new_title: shake_to_update.title = new_title if new_description: shake_to_update.description = new_description if file_name: shake_to_update.set_page_image(file_path, sha1_value) shake_to_update.save() if json: return self.write({'ok': 'Saved it!'}) else: return self.redirect("/%s" % (shake_name))
def post(self, shake_name): shake = Shake.get('name=%s and type=%s', shake_name, "group") if not shake: raise tornado.web.HTTPError(404) sender = self.get_current_user_object() receiver = User.get('name=%s', self.get_argument('name', None)) is_json = self.get_argument('json', None) if not receiver: if is_json: return self.write({'error':'error'}) else: return self.redirect('/%s' % (shake_name)) Notification.new_invitation(sender, receiver, shake.id) if is_json: return self.write({'invitation_status':True}) else: return self.redirect('/%s' % (shake_name))
def get(self, id_, before_or_after=None, base36_id=None): user = User.get('id = %s', int(self.oauth2_user_id)) shake = Shake.get('id = %s', id_) sharedfile_id = base36decode(base36_id) if base36_id else None if before_or_after == 'before': sharedfiles = shake.sharedfiles_paginated(max_id=sharedfile_id, per_page=10) elif before_or_after == 'after': sharedfiles = shake.sharedfiles_paginated(since_id=sharedfile_id, per_page=10) else: sharedfiles = shake.sharedfiles_paginated(per_page=10) sharedfiles_output = [] for sf in sharedfiles: sf_dict = sf.as_json(user_context=user) sharedfiles_output.append(sf_dict) return self.write({'sharedfiles': sharedfiles_output})