def oauth_uri(cls, callback, **kwargs): cls.last_callback = kwargs.get('raw_callback', callback) return 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id={}&nonce={}&scope=openid+profile+User.Read&response_type=code&redirect_uri={}{}'.format( MICROSOFT_CLIENT_ID, time.time(), quote(kwargs.get('raw_callback', callback)), Option.from_call(kwargs.get, 'state').map(json.dumps).map( '&state={}'.format).get_or(''))
def upsert_record(application, key, content, all, username, role, raw_payload): raw_content = raw_payload.get('content') content = raw_content if raw_content is not None: content = Option.from_call(json.dumps, raw_content).get_or(raw_content) result = PluginStorageManager \ .upsert_record(application, key, content, None if bool(all) else username, raw_payload.get('index')) return {'success': not not result}
def get_comments(p): limit = request.args.get('limit', None, int) page = request.args.get('page', 1, int) offset = (page - 1) * limit if limit and page else None p_int = Option.from_call(int, p) result = p_int \ .map(lambda pid: CommentManager.get_comments(p, limit, offset)) total_count = p_int \ .map(lambda pid: CommentManager.get_comment_count(pid)) total_pages = total_count \ .map(lambda count: count // limit + (count % limit > 0)) return { 'success': not result.empty, 'result': result.get_or(None), 'pages': total_pages.get_or(None), 'total': total_count.get_or(None) }
def remove_comment(comment, username, role, raw_payload): remove_token = raw_payload.get('remove_token', None) if username: stat = CommentManager.delete_comment(comment, username) elif remove_token: cid = dct_processor.check_remove_token(remove_token) if cid and Option.from_call(int, comment).filter(lambda x: x == cid).get_or(None): stat = CommentManager.force_delete_comment(cid) else: stat = False else: stat = False if stat: emit('comment_removed', { 'id': int(comment) }) return { 'success': stat }
def add_comment(username, role, content, to_post, raw_payload): nickname = raw_payload.get('nickname') name = username or nickname if not name: return { 'success': False, 'msg': 'Missing nickname or token expired.' } to_post = Option.from_call(int, to_post).get_or(None) if not to_post: return { 'success': False, 'msg': 'to_post should be a number' } state, msg = CommentManager.add_comment(to_post, content, raw_payload.get('to_comment'), username, nickname) if state: token = dct_processor.iss_remove_token(msg) emit('comment_added', { 'post_id': to_post, 'comment_id': msg }) raw_post = PostManager().get_db_post(to_post) author = raw_post.author.username if not nickname: name = UserManager.find_user(username).nickname emit('post_commented', { 'post_id': raw_post.post_id, 'title': raw_post.title, 'by_name': name }, room=author) else: token = '' return { 'success': state, 'msg': 'Success' if state else msg, 'comment_id': msg, 'remove_token': token }
def new_record(application, key, content, all, username, role, raw_payload): result = PluginStorageManager.new_record( application, key, Option.from_call(json.dumps, content).get_or(content), None if bool(all) else username, raw_payload.get('index')) return {'success': not not result}