예제 #1
0
def view_embed(node_id):
    api = system_util.pillar_api()

    # Get node, we'll embed linked objects later.
    try:
        node = Node.find(node_id, api=api)
    except ResourceNotFound:
        return render_template('errors/404_embed.html')
    except ForbiddenAccess:
        return render_template('errors/403_embed.html')

    project_projection = {'project': {'url': 1, 'name': 1}}
    project = Project.find(node.project, project_projection, api=api)

    node.picture = get_file(node.picture, api=api)
    node.user = node.user and User.find(node.user, api=api)

    write_access = 'PUT' in (node.allowed_methods or set())

    extra_template_args = {'project': project}

    return render_template(
        'nodes/custom/dillo_post/view_embed.html',
        node_id=node._id,
        node=node,
        write_access=write_access,
        api=api,
        **extra_template_args)
예제 #2
0
def view_embed(organization_id: str):
    if not request.is_xhr:
        return index(organization_id)

    api = pillar_api()

    organization: Organization = Organization.find(organization_id, api=api)

    om = current_app.org_manager
    organization_oid = str2id(organization_id)

    members = om.org_members(organization.members)
    for member in members:
        member['avatar'] = gravatar(member.get('email'))
        member['_id'] = str(member['_id'])

    admin_user = User.find(organization.admin_uid, api=api)

    # Make sure it's never None
    organization.unknown_members = organization.unknown_members or []

    can_super_edit = current_user.has_cap('admin')
    can_edit = can_super_edit or om.user_is_admin(organization_oid)

    csrf = flask_wtf.csrf.generate_csrf()

    return render_template('organizations/view_embed.html',
                           organization=organization,
                           admin_user=admin_user,
                           members=members,
                           can_edit=can_edit,
                           can_super_edit=can_super_edit,
                           seats_used=len(members) +
                           len(organization.unknown_members),
                           csrf=csrf)
예제 #3
0
def emails():
    """Main email settings.
    """
    if current_user.has_role('protected'):
        return abort(404)  # TODO: make this 403, handle template properly
    api = system_util.pillar_api()
    user = User.find(current_user.objectid, api=api)

    # Force creation of settings for the user (safely remove this code once
    # implemented on account creation level, and after adding settings to all
    # existing users)
    if not user.settings:
        user.settings = dict(email_communications=1)
        user.update(api=api)

    if user.settings.email_communications is None:
        user.settings.email_communications = 1
        user.update(api=api)

    # Generate form
    form = forms.UserSettingsEmailsForm(
        email_communications=user.settings.email_communications)

    if form.validate_on_submit():
        try:
            user.settings.email_communications = form.email_communications.data
            user.update(api=api)
            flash("Profile updated", 'success')
        except sdk_exceptions.ResourceInvalid as e:
            message = json.loads(e.content)
            flash(message)

    return render_template('users/settings/emails.html',
                           form=form,
                           title='emails')
예제 #4
0
파일: routes.py 프로젝트: scaredyfish/dillo
def profile_dillo():
    """Override Pillar profile page."""
    api = system_util.pillar_api()
    user = User.find(current_user.objectid, api=api)

    form = UserProfileForm(username=user.username,
                           full_name=user.full_name,
                           email=user.email)

    if form.validate_on_submit():
        user.username = form.username.data
        user.full_name = form.full_name.data
        user.email = form.email.data
        try:
            user.update(api=api)
            # TODO(fsiddi) fix missing flash, maybe it's in the template
            flash("Profile updated", 'success')
        except sdk_exceptions.ResourceInvalid as e:
            # TODO(fsiddi) fix the missing flash and attach the error to the form
            r = json.loads(e.content)
            log.warning("Error while updating user profile for User %s" %
                        current_user.objectid)

    return render_template('users/settings/profile.html',
                           form=form,
                           title='profile')
예제 #5
0
def profile():
    """Profile view and edit page. This is a temporary implementation.
    """
    if current_user.has_role('protected'):
        return abort(404)  # TODO: make this 403, handle template properly
    api = system_util.pillar_api()
    user = User.find(current_user.objectid, api=api)

    form = forms.UserProfileForm(username=user.username)

    if form.validate_on_submit():
        try:
            response = user.set_username(form.username.data, api=api)
            log.info('updated username of %s: %s', current_user, response)
            flash("Profile updated", 'success')
        except sdk_exceptions.ResourceInvalid as ex:
            log.warning('unable to set username %s to %r: %s', current_user,
                        form.username.data, ex)
            message = json.loads(ex.content)
            flash(message)

    blender_id_endpoint = current_app.config['BLENDER_ID_ENDPOINT']
    blender_profile_url = urllib.parse.urljoin(blender_id_endpoint,
                                               'settings/profile')

    return render_template('users/settings/profile.html',
                           form=form,
                           title='profile',
                           blender_profile_url=blender_profile_url)
예제 #6
0
def assigned_users_to(node, node_type):
    api = SystemUtility.attract_api()

    if node_type['name'] != "task":
        return []
    users = node['properties']['owners']['users']
    owners = []
    for user in users:
        user_node = User.find(user, api=api)
        owners.append(user_node)
    return owners
예제 #7
0
def assigned_users_to(node, node_type):
    api = SystemUtility.attract_api()

    if node_type['name'] != "task":
        return []
    users = node['properties']['owners']['users']
    owners = []
    for user in users:
        user_node = User.find(user, api=api)
        owners.append(user_node)
    return owners
예제 #8
0
파일: routes.py 프로젝트: scaredyfish/dillo
def links():
    """Links settings.
    """
    api = system_util.pillar_api()
    user = User.find(current_user.objectid, api=api)

    form = LinksListForm()

    if form.validate_on_submit():
        user_links = []
        for f in form.links:
            user_links.append({'name': f.data['name'], 'url': f.data['url']})
        # Update user properties
        update_links(bson.ObjectId(current_user.objectid), user_links)

        flash('Profile updated!', 'success')
        # Clear the list entries before populating it with the new links
        form.links.entries = []

        for link in user_links:
            form.links.append_entry(link)

    # If the form fails to validate, do not update any field
    elif form.errors:
        # Handle the specific case of when we have the last link in the list.
        # In this case we will ignore the errors and assign an empty link.
        if 'links' in form.errors and len(form.links) == 1:
            errors = form.errors['links'][0]
            if 'name' in errors and 'url' in errors:
                update_links(bson.ObjectId(current_user.objectid), [{
                    'name': None,
                    'url': None
                }])
                return redirect(url_for('settings.links'))
        for e, v in form.errors.items():
            log.debug("Error validating field %s" % e)
    else:
        # Read user properties
        if 'links' in user['extension_props_public']['dillo'] and \
                len(user['extension_props_public']['dillo']['links']) > 0:
            links = user['extension_props_public']['dillo']['links']
        else:
            links = []
        for link in links:
            form.links.append_entry(link)

    return render_template('users/settings/links.html',
                           form=form,
                           title='emails')
예제 #9
0
파일: routes.py 프로젝트: babbysross/pillar
def profile():
    """Profile view and edit page. This is a temporary implementation.
    """
    if current_user.has_role('protected'):
        return abort(404)  # TODO: make this 403, handle template properly
    api = system_util.pillar_api()
    user = User.find(current_user.objectid, api=api)

    form = forms.UserProfileForm(username=user.username)

    if form.validate_on_submit():
        try:
            user.username = form.username.data
            user.update(api=api)
            flash("Profile updated", 'success')
        except sdk_exceptions.ResourceInvalid as e:
            message = json.loads(e.content)
            flash(message)

    return render_template('users/settings/profile.html',
                           form=form,
                           title='profile')
예제 #10
0
def is_community_followed(community) -> bool:
    """Check if the community is followed."""

    if current_user.is_anonymous:
        return False

    # Community is not followed by default
    community_is_followed = False

    # Define the communities followed by default
    followed_communities = [cid for cid in
                            current_app.config['DEFAULT_FOLLOWED_COMMUNITY_IDS']]

    user = User.find(current_user.objectid, api=system_util.pillar_api())
    # If 'followed_communities' for the user exists and is not an empty list
    if 'followed_communities' in user['extension_props_public']['dillo'] \
            and user['extension_props_public']['dillo']['followed_communities']:
        followed_communities = user['extension_props_public']['dillo']['followed_communities']

    if community['_id'] in followed_communities:
        community_is_followed = True

    return community_is_followed