def sharing(project_url): api = system_util.pillar_api() # Fetch the project or 404 try: project = Project.find_one({ 'where': '{"url" : "%s"}' % (project_url)}, api=api) except ResourceNotFound: return abort(404) # Fetch users that are part of the admin group users = project.get_users(api=api) for user in users['_items']: user['avatar'] = gravatar(user['email']) if request.method == 'POST': user_id = request.form['user_id'] action = request.form['action'] if action == 'add': user = project.add_user(user_id, api=api) elif action == 'remove': user = project.remove_user(user_id, api=api) # Add gravatar to user user['avatar'] = gravatar(user['email']) return jsonify(user) attach_project_pictures(project, api) return render_template('projects/sharing.html', api=api, title="sharing", project=project, users=users['_items'])
def sharing(project_url): api = system_util.pillar_api() # Fetch the project or 404 try: project = Project.find_one({'where': '{"url" : "%s"}' % (project_url)}, api=api) except ResourceNotFound: return abort(404) # Fetch users that are part of the admin group users = project.get_users(api=api) for user in users['_items']: user['avatar'] = gravatar(user['email']) if request.method == 'POST': user_id = request.form['user_id'] action = request.form['action'] if action == 'add': user = project.add_user(user_id, api=api) elif action == 'remove': user = project.remove_user(user_id, api=api) # Add gravatar to user user['avatar'] = gravatar(user['email']) return jsonify(user) attach_project_pictures(project, api) return render_template('projects/sharing.html', api=api, title="sharing", project=project, users=users['_items'])
def format_comment(comment, is_reply=False, is_team=False, replies=None): """Format a comment node into a simpler dictionary. :param comment: the comment object :param is_reply: True if the comment is a reply to another comment :param is_team: True if the author belongs to the group that owns the node :param replies: list of replies (formatted with this function) """ is_own = current_user.objectid == comment.user._id is_rated = False is_rated_positive = None if comment.properties.ratings: for rating in comment.properties.ratings: if rating.user == current_user.objectid: is_rated = True is_rated_positive = rating.is_positive continue return dict(_id=comment._id, gravatar=gravatar(comment.user.email), time_published=comment._created, rating_up=comment.properties.rating_positive, rating_down=comment.properties.rating_negative, author=comment.user.username, content=comment.properties.content, is_reply=is_reply, is_own=is_own, is_rated=is_rated, is_rated_positive=is_rated_positive, is_team=is_team, replies=replies)
def index(): api = system_util.pillar_api() projects_user = Project.all({ 'where': {'user': current_user.objectid}, 'sort': '-_created' }, api=api) projects_shared = Project.all({ 'where': {'user': {'$ne': current_user.objectid}, 'permissions.groups.group': {'$in': current_user.groups}, 'is_private': True}, 'sort': '-_created', 'embedded': {'user': 1}, }, api=api) # Attach project images for project in projects_user['_items']: attach_project_pictures(project, api) for project in projects_shared['_items']: attach_project_pictures(project, api) return render_template( 'projects/index_dashboard.html', gravatar=gravatar(current_user.email, size=128), title='dashboard', projects_user=projects_user['_items'], projects_shared=projects_shared['_items'], api=system_util.pillar_api())
def __init__(self, name): self.api = SystemUtility.attract_api() # Check if organization exists user = Organization.find_first({ 'where': '{"url" : "%s"}' % (name), }, api=self.api) if user: self.is_organization = True self.name = user.name self.url = user.url self.description = user.description self.gravatar = gravatar(user.email) else: # Check if user exists user = User.find_first({ 'where': '{"username" : "%s"}' % (name), }, api=self.api) if user: self.is_organization = False self.name = user.first_name self.url = user.username else: return abort(404) self._id = user._id
def index(): api = system_util.pillar_api() projects_user = Project.all( { 'where': { 'user': current_user.objectid }, 'sort': '-_created' }, api=api) projects_shared = Project.all( { 'where': { 'user': { '$ne': current_user.objectid }, 'permissions.groups.group': { '$in': current_user.groups }, 'is_private': True }, 'sort': '-_created', 'embedded': { 'user': 1 }, }, api=api) # Attach project images for project in projects_user['_items']: attach_project_pictures(project, api) for project in projects_shared['_items']: attach_project_pictures(project, api) return render_template('projects/index_dashboard.html', gravatar=gravatar(current_user.email, size=128), title='dashboard', projects_user=projects_user['_items'], projects_shared=projects_shared['_items'], api=system_util.pillar_api())
def format_comment(comment, is_reply=False, is_team=False, replies=None): """Format a comment node into a simpler dictionary. :param comment: the comment object :param is_reply: True if the comment is a reply to another comment :param is_team: True if the author belongs to the group that owns the node :param replies: list of replies (formatted with this function) """ try: is_own = (current_user.objectid == comment.user._id) \ if current_user.is_authenticated() else False except AttributeError: bugsnag.notify(Exception('Missing user for embedded user ObjectId'), meta_data={'nodes_info': { 'node_id': comment['_id'] }}) return is_rated = False is_rated_positive = None if comment.properties.ratings: for rating in comment.properties.ratings: if current_user.is_authenticated( ) and rating.user == current_user.objectid: is_rated = True is_rated_positive = rating.is_positive continue return dict(_id=comment._id, gravatar=gravatar(comment.user.email, size=32), time_published=pretty_date(comment._created), rating_up=comment.properties.rating_positive, rating_down=comment.properties.rating_negative, author=comment.user.full_name, content=comment.properties.content, is_reply=is_reply, is_own=is_own, is_rated=is_rated, is_rated_positive=is_rated_positive, is_team=is_team, replies=replies)
def format_comment(comment, is_reply=False, is_team=False, replies=None): """Format a comment node into a simpler dictionary. :param comment: the comment object :param is_reply: True if the comment is a reply to another comment :param is_team: True if the author belongs to the group that owns the node :param replies: list of replies (formatted with this function) """ try: is_own = (current_user.objectid == comment.user._id) \ if current_user.is_authenticated() else False except AttributeError: bugsnag.notify(Exception('Missing user for embedded user ObjectId'), meta_data={'nodes_info': {'node_id': comment['_id']}}) return is_rated = False is_rated_positive = None if comment.properties.ratings: for rating in comment.properties.ratings: if current_user.is_authenticated() and rating.user == current_user.objectid: is_rated = True is_rated_positive = rating.is_positive continue return dict(_id=comment._id, gravatar=gravatar(comment.user.email, size=32), time_published=pretty_date(comment._created), rating_up=comment.properties.rating_positive, rating_down=comment.properties.rating_negative, author=comment.user.full_name, content=comment.properties.content, is_reply=is_reply, is_own=is_own, is_rated=is_rated, is_rated_positive=is_rated_positive, is_team=is_team, replies=replies)
def __init__(self, name): self.api = system_util.pillar_api() # Check if organization exists user = Organization.find_first({ 'where': '{"url" : "%s"}' % (name), }, api=self.api) if user: self.is_organization = True self.name = user.name self.url = user.url self.description = user.description self.gravatar = gravatar(user.email) else: # Check if user exists user = User.find_first({ 'where': '{"username" : "%s"}' % (name), }, api=self.api) if user: self.is_organization = False self.name = user.first_name self.url = user.username else: return abort(404) self._id = user._id