def get_all_tasks(group_id): """ Show all tasks ever made. Can specify specific group. No internal permission system made yet. Do not make routes to this module yet. """ if not ModuleAPI.can_read('pimpy'): return abort(403) if current_user.is_anonymous: flash('Huidige gebruiker niet gevonden.', 'danger') return redirect(url_for('pimpy.view_tasks')) status_meanings = Task.get_status_meanings() list_items = {} if group_id == 'all': for group in UserAPI.get_groups_for_current_user(): list_users = {} list_users['Iedereen'] = group.tasks list_items[group.name] = list_users else: list_users = {} tasks = Task.query.filter(Task.group_id == group_id).all() group = Group.query.filter(Group.id == group_id).first() if not group: return abort(404) if group not in UserAPI.get_groups_for_current_user(): return abort(403) list_users['Iedereen'] = tasks list_items[group.name] = list_users return Markup(render_template('pimpy/api/tasks.htm', list_items=list_items, type='tasks', group_id=group_id, personal=False, status_meanings=status_meanings, title='PimPy'))
def view_single(user_id): """ View user for admins and edit for admins and users. User is passed based on routes below. """ user = user_service.get_user_by_id(user_id) user.avatar = UserAPI.avatar(user) user.groups = UserAPI.get_groups_for_user_id(user) user.groups_amount = len(user.groups) if "gravatar" in user.avatar: user.avatar = user.avatar + "&s=341" # Get all activity entrees from these forms, order by start_time of # activity. activities = Activity.query.join(CustomForm).join(CustomFormResult). \ filter(CustomFormResult.owner_id == user_id and CustomForm.id == CustomFormResult.form_id and Activity.form_id == CustomForm.id) user.activities_amount = activities.count() new_activities = activities \ .filter(Activity.end_time > datetime.today()).distinct() \ .order_by(Activity.start_time) old_activities = activities \ .filter(Activity.end_time < datetime.today()).distinct() \ .order_by(Activity.start_time.desc()) can_write = role_service.user_has_role(current_user, Roles.USER_WRITE) return render_template('user/view_single.htm', user=user, new_activities=new_activities, old_activities=old_activities, can_write=can_write)
def get_member_details(_id=None): if not id: return jsonify(errors='No user id given'), 400 user = User.by_id(_id) if not user: return jsonify(errors='User not found with that id'), 404 data = { "id": user.id, "name": user.name, "email": user.email, "avatar": UserAPI.avatar(user), "gender": user.gender, "locale": user.locale, "student_id": user.student_id, "education": user.education.name } return jsonify(data=data), 200
def get_highest_permission_for_module(module_name): """ Return the highest permission for the current user for module name. Should crash if all has been deleted and the user is not logged in. """ groups = UserAPI.get_groups_for_current_user() highest = 0 for group in groups: query = GroupPermission.query\ .filter(GroupPermission.group_id == group.id) query = query.filter(GroupPermission.module_name == module_name) matching_permissions = query.all() for matching_permission in matching_permissions: highest = matching_permission.permission if\ matching_permission.permission > highest else highest return highest
def get_tasks_in_date_range(group_id, personal, start_date, end_date): """Load all tasks for a given group in a daterange.""" if not ModuleAPI.can_read('pimpy'): return abort(403) if current_user.is_anonymous: flash('Huidige gebruiker niet gevonden', 'danger') return redirect(url_for('pimpy.view_tasks')) status_meanings = Task.get_status_meanings() tasks_rel = TaskUserRel.query.join(Task).join(User) groups = UserAPI.get_groups_for_current_user() groups = map(lambda x: x.id, groups) if group_id == 'all': tasks_rel = tasks_rel.filter(Task.group_id.in_(groups)) else: group_id = int(group_id) if group_id not in groups: return abort(403) tasks_rel = tasks_rel.filter(Task.group_id == group_id) if personal: tasks_rel = tasks_rel.filter(User.id == current_user.id) tasks_rel = tasks_rel.filter(~Task.status.in_((4, 5))).join(Group).\ filter(start_date <= Task.timestamp, Task.timestamp <= end_date) tasks_rel = tasks_rel.order_by(Group.name.asc(), User.first_name.asc(), User.last_name.asc(), Task.id.asc()) return Markup(render_template('pimpy/api/tasks.htm', personal=personal, group_id=group_id, tasks_rel=tasks_rel, type='tasks', status_meanings=status_meanings, title='PimPy'))