def static_page(): """ Render the administrative static page """ user_db = UserDB() role_db = RoleDB() event_log = EventLog() icebox = Icebox() if current_user.is_authenticated() and current_user.is_active(): is_admin = user_db.in_group(current_user, mainApp.config['ADMIN_GROUP']) all_activities = set() for m in role_db.get_roles(current_user): acts = role_db.get_activities(m.role_id) for act in acts: if acts[act]: all_activities.add(act) can_admin_static = 'make_static' in all_activities can_admin_static_now = 'make_static_now' in all_activities if is_admin or can_admin_static: if request.method == 'POST': if 'sched_rebuild' in request.form: event_log.add('rebuild_static', current_user.id) flash(_('Full site rebuild scheduled.')) elif 'incr_build' in request.form: icebox.generate_pages() flash(_('New/updated pages generated.')) elif 'rebuild_now' in request.form: if can_admin_static_now: icebox.generate_pages(True) flash(_('Full site rebuilt')) else: flash(_('Not authorized for full site rebuild', 'error')) return render_template('admin_static.html', state=get_state(), can_admin_static=can_admin_static, can_admin_static_now=can_admin_static_now, title=_('Administrate Static Site'), sched_rebuild_text=_('Schedule a full site rebuild'), sched_rebuild_button=_('Schedule'), incr_build_text=_('Perform an incremental build'), incr_build_button=_('Incremental'), rebuild_now_text=_('Perform a full rebuild now'), rebuild_now_button=_('Rebuild')) else: return _not_auth() else: return _not_auth()
def admin_new_role(): """ Renders the new role page """ role_db = RoleDB() if current_user.is_authenticated() and current_user.is_active(): all_activities = set() for m in role_db.get_roles(current_user): acts = role_db.get_activities(m.role_id) for act in acts: if acts[act]: all_activities.add(act) if 'new_role' in all_activities: role = role_db.create_temp_empty_role() if 'cancel' in request.form: return redirect(url_for('admin_role.admin_role_page')) elif 'submit' in request.form: rname = request.form.get('role_name', None) role.name = rname role.description = request.form.get('description', None) updated_acts = request.form.getlist('activities') ract = get_activity_dict(False) for a in updated_acts: ract[a] = True role = role_db.update_temp_role_activities(role, ract) if rname is not None and rname != '': r = role_db.get_role(rname) if r is None: try: role = role_db.add_role(role.name, role.description, ract) flash(_('Role "{0}" added.'.format(rname))) return redirect(url_for( 'admin_role.admin_role_page')) except DuplicateRole: flash(_('Role name "{0}" is already in use!'.format( rname)), 'error') return render_template('admin_role.html', role=role, state=get_state(), title=_('Edit Role'), cancel_button=_('Cancel'), submit_button=_('Submit'), can_edit_roles=True, activities=activities) else: return _not_auth() else: return _not_auth()
def admin_new_group(): """ Renders the new group page """ user_db = UserDB() role_db = RoleDB() if current_user.is_authenticated() and current_user.is_active(): all_activities = set() for m in role_db.get_roles(current_user): acts = role_db.get_activities(m.role_id) for act in acts: if acts[act]: all_activities.add(act) if 'new_group' in all_activities: group = user_db.create_temp_empty_group() if 'cancel' in request.form: return redirect(url_for('admin_group.admin_group_page')) elif 'submit' in request.form: gname = request.form.get('group_name', None) group.name = gname group.description = request.form.get('description', None) if gname is not None and gname != '': g = user_db.get_group(gname) if g is None: try: group = user_db.add_group(group.name, group.description) flash(_('Group "{0}" added.'.format(gname))) return redirect(url_for( 'admin_group.admin_group_page')) except DuplicateGroup: flash(_( 'Group name "{0}" is already in use!'.format( gname)), 'error') else: flash(_("Group name cannot be empty!"), 'error') return render_template('admin_group.html', group=group, state=get_state(), title=_('Edit Group'), cancel_button=_('Cancel'), submit_button=_('Submit'), can_edit_groups=True) else: return _not_auth() else: return _not_auth()
def event_viewer(): """ Render the event viewer. """ page_num = int(request.args.get('page', 0)) per_page = int(request.args.get('per_page', 20)) user_db = UserDB() role_db = RoleDB() event_log = EventLog() if current_user.is_authenticated() and current_user.is_active(): is_admin = user_db.in_group(current_user, mainApp.config['ADMIN_GROUP']) all_activities = set() for m in role_db.get_roles(current_user): acts = role_db.get_activities(m.role_id) for act in acts: if acts[act]: all_activities.add(act) can_view_logs = 'view_logs' in all_activities if is_admin or can_view_logs: events = event_log.find_recent_by_num(per_page, page_num * per_page) count = event_log.count() total_pages = 0 if count > per_page: total_pages = int(ceil(float(count) / float(per_page))) return render_template('admin_events.html', events=events, state=get_state(), page_num=page_num, per_page=per_page, title=_('Event log'), total_pages=total_pages) else: return _not_auth() else: return _not_auth()
def admin_role_page(rid): """ Renders the role admin page """ user_db = UserDB() role_db = RoleDB() if current_user.is_authenticated() and current_user.is_active(): is_admin = user_db.in_group(current_user, mainApp.config['ADMIN_GROUP']) all_activities = set() for m in role_db.get_roles(current_user): acts = role_db.get_activities(m.role_id) for act in acts: if acts[act]: all_activities.add(act) can_view_roles = 'view_roles' in all_activities can_edit_roles = 'edit_roles' in all_activities if is_admin or can_view_roles: if rid is None: if request.method == 'POST': if 'delete' in request.form: rids = request.form.getlist('select') for rid in rids: try: role_db.delete_role(int(rid)) flash(_('Role with ID "{0}" deleted'.format( rid))) except RoleNotFound: flash(_('"{0}" role id not found!'.format( rid)), 'error') elif 'new' in request.form: return redirect(url_for('admin_role.admin_new_role')) roles = role_db.get_all_roles() return render_template('list_roles.html', roles=roles, state=get_state(), can_view_roles=can_view_roles, can_edit_roles=can_edit_roles, title=_('All Roles'), delete_button=_('Delete'), new_button=_('New'), cancel_button=_('Cancel'), activities=activities, del_title=_('Delete Roles(s)'), del_warn=_('Deleting roles is a permanent action. '\ 'Are you sure?')) else: if request.method == "POST": if 'cancel' in request.form: return redirect(url_for('admin_role.admin_role_page')) elif 'submit' in request.form: role = role_db.get_role(rid) if role is not None: role.name = request.form.get('role_name', role.name) role.description = request.form.get('description', role.description) updated_acts = request.form.getlist('activities') ract = get_activity_dict(False) for a in updated_acts: ract[a] = True role = role_db.update_temp_role_activities( role, ract) role_db.update_role(role) return redirect(url_for( 'admin_role.admin_role_page')) role = role_db.get_role(rid) if role is not None: return render_template('admin_role.html', role=role, state=get_state(), title=_('Edit Role'), cancel_button=_('Cancel'), submit_button=_('Submit'), can_edit_roles=True, activities=activities) else: return _not_auth() else: return _not_auth()
def admin_group_page(gid): """ Renders the group page """ user_db = UserDB() role_db = RoleDB() if current_user.is_authenticated() and current_user.is_active(): is_admin = user_db.in_group(current_user, mainApp.config['ADMIN_GROUP']) all_activities = set() for m in role_db.get_roles(current_user): acts = role_db.get_activities(m.role_id) for act in acts: if acts[act]: all_activities.add(act) can_view_groups = 'view_groups' in all_activities can_edit_groups = 'edit_group' in all_activities if is_admin or can_view_groups: if gid is None: if request.method == "POST": if 'delete' in request.form: gids = request.form.getlist('select') for gid in gids: try: user_db.delete_group(int(gid)) flash(_('Group with ID "{0}" deleted.'.format( gid))) except GroupNotFound: flash(_('"{0}" group id not found!'.format( gid)), 'error') elif 'new' in request.form: return redirect(url_for('admin_group.admin_new_group')) groups = user_db.get_all_groups() return render_template('list_groups.html', groups=groups, state=get_state(), can_view_groups=can_view_groups, can_edit_groups=can_edit_groups, title=_('All Groups'), delete_button=_('Delete'), new_button=_('New'), cancel_button=_('Cancel'), del_title=_('Delete Group(s)'), del_warn=_('Deleting groups is a permanent action. '\ 'Are you sure?')) else: if request.method == "POST": if 'cancel' in request.form: return redirect(url_for('admin_group.admin_group_page')) elif 'submit' in request.form: group = user_db.get_group(gid) if group is not None: group.name = request.form.get('group_name', group.name) group.description = request.form.get('description', group.description) user_db.update_group(group) group = user_db.get_group(gid) if group is not None: return render_template('admin_group.html', group=group, state=get_state(), title=_('Edit Group'), cancel_button=_('Cancel'), submit_button=_('Submit'), can_edit_groups=can_edit_groups) else: flash(_('Group "{0}" not found!'.format(gid)), 'error') return redirect(url_for("admin_group.admin_group_page")) else: return _not_auth() else: return _not_auth()