def setUp(self): """ user_a -> admin user_b -> user2 user_a uploads shared file. We authenticate to the API with user_b. user_b subscribes to user_a's shake.] """ super(APIResourceRequests, self).setUp() self.user_a = User( name='admin', email='*****@*****.**', email_confirmed=1, is_paid=1, about="admin", website='https://mltshp.com') self.user_a.set_password('asdfasdf') self.user_a.save() self.sid = self.sign_in('admin', 'asdfasdf') self.xsrf = self.get_xsrf() self.test_file1_path = os.path.abspath("test/files/1.png") self.test_file1_sha1 = Sourcefile.get_sha1_file_key(self.test_file1_path) self.test_file1_content_type = "image/png" response = self.upload_file(file_path=self.test_file1_path, sha1=self.test_file1_sha1, content_type=self.test_file1_content_type, user_id=self.user_a.id, sid=self.sid, xsrf=self.xsrf) self.user_b = User(name='user2', email='*****@*****.**', email_confirmed=1, is_paid=1) self.user_b.set_password('asdfasdf') self.user_b.save() self.group_shake = self.user_b.create_group_shake(title='Group Shake', name='groupshake', description='This is a group shake.') self.group_shake_2 = self.user_a.create_group_shake(title='Another Group', name='anothergroup') # Add user_b to user_a's group shake, so we get it in user_b's /shakes endpoint. shake_manager = ShakeManager(user_id=self.user_b.id, shake_id=self.group_shake_2.id) shake_manager.save() self.app = App(user_id=self.user_a.id, title='An App', description='Nothing yet.', redirect_url='http://client.example.com/return') self.app.save() self.authorization = Authorizationcode.generate(self.app.id, self.app.redirect_url, self.user_b.id) self.access_token = Accesstoken.generate(self.authorization.id) extra_authorization = Authorizationcode.generate(self.app.id, self.app.redirect_url, self.user_b.id) self.ratelimited_access_token = Accesstoken.generate(extra_authorization.id) now_hour = datetime.utcnow().strftime('%Y-%m-%d %H:00:00') ratelimit = Apihit(accesstoken_id=self.ratelimited_access_token.id, hits=options.api_hits_per_hour - 2, hour_start=now_hour) ratelimit.save() #subscription self.user_b.subscribe(self.user_a.shake())
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_shake_accept_request_creates_editor(self): self.post_url('/shake/derp/request_invitation?json=1') self.sign_in("admin", "asdfasdf") response = self.post_url('/shake/derp/approve_invitation?json=1', arguments={'user_id': self.user.id}) manager = ShakeManager.get('user_id = %s', self.user.id) self.assertTrue(manager)
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 test_shake_decline_request_deletes_notification(self): self.post_url('/shake/derp/request_invitation?json=1') self.sign_in("admin", "asdfasdf") response = self.post_url('/shake/derp/decline_invitation?json=1', arguments={'user_id': self.user.id}) manager = ShakeManager.get('user_id = %s', self.user.id) self.assertFalse(manager) n = Notification.get('receiver_id = %s', self.manager.id) self.assertTrue(n.deleted)
def test_user_delete(self): self.user.create_group_shake(title='balrag', name="blahr", description="affafa") another_user = User(name='example2',email='*****@*****.**', \ verify_email_token = 'created', password='******', email_confirmed=1, paid=1) another_user.save() new_group_shake = another_user.create_group_shake(title='weiurywiuer', name="werqwerew", description="affafa") self.user.subscribe_to_user(another_user) new_group_shake.add_manager(self.user) self.user.delete() user = User.get('name=%s', 'example') self.assertEqual(user.email, '*****@*****.**' % (user.id)) self.assertEqual(user.tou_agreed, 1) self.assertEqual(user.hashed_password, 'deleteduseracct') self.assertEqual(user.about, '') self.assertEqual(user.website, '') self.assertEqual(user.nsfw, 1) self.assertEqual(user.recommended, 0) self.assertEqual(user.is_paid, 0) self.assertEqual(user.deleted, 1) self.assertEqual(user.verify_email_token, 'deleted') self.assertEqual(user.reset_password_token, 'deleted') self.assertEqual(user.profile_image, 0) self.assertEqual(user.disable_notifications, 1) self.assertEqual(user.invitation_count, 0) shared_files = Sharedfile.all() for shared_file in shared_files: self.assertEqual(shared_file.deleted, 1) ssfs = Shakesharedfile.all() for ssf in ssfs: self.assertEqual(ssf.deleted, 1) subscriptions = Subscription.where("user_id = %s", self.user.id) for sub in subscriptions: self.assertEqual(sub.deleted, 1) managing = ShakeManager.where("user_id = %s", self.user.id) for m in managing: self.assertEqual(m.deleted, 1)
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)