@frontend.route('/objects/<int:object_id>/permissions')
@object_permissions_required(Permissions.READ, on_unauthorized=on_unauthorized)
def object_permissions(object_id):
    check_current_user_is_not_readonly()
    object = get_object(object_id)
    action = get_action(object.action_id)
    instrument = action.instrument
    user_permissions = get_object_permissions_for_users(object_id=object_id, include_instrument_responsible_users=False, include_groups=False, include_projects=False, include_readonly=False, include_admin_permissions=False)
    group_permissions = get_object_permissions_for_groups(object_id=object_id, include_projects=False)
    project_permissions = get_object_permissions_for_projects(object_id=object_id)
    public_permissions = (Permissions.READ if object_is_public(object_id) else Permissions.NONE)
    suggested_user_id = flask.request.args.get('add_user_id', '')
    try:
        suggested_user_id = int(suggested_user_id)
    except ValueError:
        suggested_user_id = None
    if (Permissions.GRANT in get_user_object_permissions(object_id=object_id, user_id=flask_login.current_user.id)):
        user_permission_form_data = []
        for (user_id, permissions) in user_permissions.items():
            if (user_id is None):
                continue
            user_permission_form_data.append({'user_id': user_id, 'permissions': permissions.name.lower()})
        group_permission_form_data = []
        for (group_id, permissions) in group_permissions.items():
            if (group_id is None):
                continue
            group_permission_form_data.append({'group_id': group_id, 'permissions': permissions.name.lower()})
        project_permission_form_data = []
        for (project_id, permissions) in project_permissions.items():
            if (project_id is None):
                continue
            project_permission_form_data.append({'project_id': project_id, 'permissions': permissions.name.lower()})
        edit_user_permissions_form = ObjectPermissionsForm(public_permissions=public_permissions.name.lower(), user_permissions=user_permission_form_data, group_permissions=group_permission_form_data, project_permissions=project_permission_form_data)
        users = get_users(exclude_hidden=True)
        users = [user for user in users if (user.id not in user_permissions)]
        add_user_permissions_form = ObjectUserPermissionsForm()
        groups = get_user_groups(flask_login.current_user.id)
        groups = [group for group in groups if (group.id not in group_permissions)]
        add_group_permissions_form = ObjectGroupPermissionsForm()
        projects = get_user_projects(flask_login.current_user.id, include_groups=True)
        projects = [project for project in projects if (project.id not in project_permissions)]
        add_project_permissions_form = ObjectProjectPermissionsForm()
        copy_permissions_form = CopyPermissionsForm()
        if (not flask.current_app.config['LOAD_OBJECTS_IN_BACKGROUND']):
            existing_objects = get_objects_with_permissions(user_id=flask_login.current_user.id, permissions=Permissions.GRANT)
            copy_permissions_form.object_id.choices = [(str(existing_object.id), existing_object.data['name']['text']) for existing_object in existing_objects if (existing_object.id != object_id)]
            if (len(copy_permissions_form.object_id.choices) == 0):
                copy_permissions_form = None
        else:
            copy_permissions_form.object_id.choices = []
    else:
        edit_user_permissions_form = None
        add_user_permissions_form = None
        add_group_permissions_form = None
        add_project_permissions_form = None
        copy_permissions_form = None
        users = []
        groups = []
        projects = []
    acceptable_project_ids = {project.id for project in projects}
    all_projects = logic.projects.get_projects()
    all_projects_by_id = {project.id: project for project in all_projects}
    if (not flask.current_app.config['DISABLE_SUBPROJECTS']):
        project_id_hierarchy_list = logic.projects.get_project_id_hierarchy_list(list(all_projects_by_id))
        project_id_hierarchy_list = [(level, project_id, (project_id in acceptable_project_ids)) for (level, project_id) in project_id_hierarchy_list]
    else:
        project_id_hierarchy_list = [(0, project.id, (project.id in acceptable_project_ids)) for project in sorted(all_projects, key=(lambda project: project.id))]
    return flask.render_template('objects/object_permissions.html', instrument=instrument, action=action, object=object, user_permissions=user_permissions, group_permissions=group_permissions, project_permissions=project_permissions, public_permissions=public_permissions, get_user=get_user, Permissions=Permissions, form=edit_user_permissions_form, users=users, groups=groups, projects_by_id=all_projects_by_id, project_id_hierarchy_list=project_id_hierarchy_list, show_projects_form=(len(acceptable_project_ids) > 0), add_user_permissions_form=add_user_permissions_form, add_group_permissions_form=add_group_permissions_form, get_group=get_group, add_project_permissions_form=add_project_permissions_form, copy_permissions_form=copy_permissions_form, get_project=get_project, suggested_user_id=suggested_user_id)
@frontend.route('/objects/<int:object_id>/permissions')
@object_permissions_required(Permissions.READ, on_unauthorized=on_unauthorized)
def object_permissions(object_id):
    check_current_user_is_not_readonly()
    object = get_object(object_id)
    action = get_action(object.action_id)
    instrument = action.instrument
    user_permissions = get_object_permissions_for_users(object_id=object_id, include_instrument_responsible_users=False, include_groups=False, include_projects=False, include_readonly=False, include_admin_permissions=False)
    group_permissions = get_object_permissions_for_groups(object_id=object_id, include_projects=False)
    project_permissions = get_object_permissions_for_projects(object_id=object_id)
    public_permissions = (Permissions.READ if object_is_public(object_id) else Permissions.NONE)
    suggested_user_id = flask.request.args.get('add_user_id', )
    try:
        suggested_user_id = int(suggested_user_id)
    except ValueError:
        suggested_user_id = None
    if (Permissions.GRANT in get_user_object_permissions(object_id=object_id, user_id=flask_login.current_user.id)):
        user_permission_form_data = []
        for (user_id, permissions) in user_permissions.items():
            if (user_id is None):
                continue
            user_permission_form_data.append({'user_id': user_id, 'permissions': permissions.name.lower()})
        group_permission_form_data = []
        for (group_id, permissions) in group_permissions.items():
            if (group_id is None):
                continue
            group_permission_form_data.append({'group_id': group_id, 'permissions': permissions.name.lower()})
        project_permission_form_data = []
        for (project_id, permissions) in project_permissions.items():
            if (project_id is None):
                continue
            project_permission_form_data.append({'project_id': project_id, 'permissions': permissions.name.lower()})
        edit_user_permissions_form = ObjectPermissionsForm(public_permissions=public_permissions.name.lower(), user_permissions=user_permission_form_data, group_permissions=group_permission_form_data, project_permissions=project_permission_form_data)
        users = get_users(exclude_hidden=True)
        users = [user for user in users if (user.id not in user_permissions)]
        add_user_permissions_form = ObjectUserPermissionsForm()
        groups = get_user_groups(flask_login.current_user.id)
        groups = [group for group in groups if (group.id not in group_permissions)]
        add_group_permissions_form = ObjectGroupPermissionsForm()
        projects = get_user_projects(flask_login.current_user.id, include_groups=True)
        projects = [project for project in projects if (project.id not in project_permissions)]
        add_project_permissions_form = ObjectProjectPermissionsForm()
        copy_permissions_form = CopyPermissionsForm()
        if (not flask.current_app.config['LOAD_OBJECTS_IN_BACKGROUND']):
            existing_objects = get_objects_with_permissions(user_id=flask_login.current_user.id, permissions=Permissions.GRANT)
            copy_permissions_form.object_id.choices = [(str(existing_object.id), existing_object.data['name']['text']) for existing_object in existing_objects if (existing_object.id != object_id)]
            if (len(copy_permissions_form.object_id.choices) == 0):
                copy_permissions_form = None
        else:
            copy_permissions_form.object_id.choices = []
    else:
        edit_user_permissions_form = None
        add_user_permissions_form = None
        add_group_permissions_form = None
        add_project_permissions_form = None
        copy_permissions_form = None
        users = []
        groups = []
        projects = []
    acceptable_project_ids = {project.id for project in projects}
    all_projects = logic.projects.get_projects()
    all_projects_by_id = {project.id: project for project in all_projects}
    if (not flask.current_app.config['DISABLE_SUBPROJECTS']):
        project_id_hierarchy_list = logic.projects.get_project_id_hierarchy_list(list(all_projects_by_id))
        project_id_hierarchy_list = [(level, project_id, (project_id in acceptable_project_ids)) for (level, project_id) in project_id_hierarchy_list]
    else:
        project_id_hierarchy_list = [(0, project.id, (project.id in acceptable_project_ids)) for project in sorted(all_projects, key=(lambda project: project.id))]
    return flask.render_template('objects/object_permissions.html', instrument=instrument, action=action, object=object, user_permissions=user_permissions, group_permissions=group_permissions, project_permissions=project_permissions, public_permissions=public_permissions, get_user=get_user, Permissions=Permissions, form=edit_user_permissions_form, users=users, groups=groups, projects_by_id=all_projects_by_id, project_id_hierarchy_list=project_id_hierarchy_list, show_projects_form=(len(acceptable_project_ids) > 0), add_user_permissions_form=add_user_permissions_form, add_group_permissions_form=add_group_permissions_form, get_group=get_group, add_project_permissions_form=add_project_permissions_form, copy_permissions_form=copy_permissions_form, get_project=get_project, suggested_user_id=suggested_user_id)