Skip to content

Commit

Permalink
Fixes #146 & #147
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kraft committed Mar 22, 2024
1 parent 5320802 commit ec5ec5e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
2 changes: 1 addition & 1 deletion odmf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '2024.3.20'
__version__ = '2024.3.21'
prefix = '.'
2 changes: 1 addition & 1 deletion odmf/db/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Person(Base):
mobile = sql.Column(sql.String)
car_available = sql.Column(sql.Integer, default=0)
password = sql.Column(sql.VARCHAR)
access_level = sql.Column(sql.INTEGER)
access_level = sql.Column(sql.INTEGER, nullable=False, default=0)
active = sql.Column(sql.Boolean, default=True, nullable=False)

def __str__(self):
Expand Down
1 change: 1 addition & 0 deletions odmf/db/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def members(self, access_level=0, with_responsible=True):
if not self.session(): # For a new project no session and no member exists!
return None
from ..webpage.auth import Level
access_level = Level(access_level)
for pm in (
self.members_query.filter(ProjectMember.access_level>=access_level)
.order_by(ProjectMember.access_level.desc(), ProjectMember._member)
Expand Down
21 changes: 20 additions & 1 deletion odmf/static/templates/person.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ <h1 py:content="active_person"/>
class="form-control"
rows="4"
py:content="U.comment"
py:attrs="prop(disabled=not (is_member('supervisor') or is_self(U.username)))"
py:attrs="prop(disabled=not (is_member(Level.supervisor) or is_self(U.username)))"
/>
</div>

Expand All @@ -163,6 +163,25 @@ <h2 class="mt-4">Projects:</h2>
<span class="badge badge-warning float-right" py:content="level.name"/>
</a>
</div>
<a href="#add-member" py:if="potential_projects"
class="btn-sm btn-primary dropdown-toggle" data-toggle="collapse"
aria-controls="add-member" aria-role="button">
<i class="fas fa-plus"/> add project ...
</a>
<div id="add-member" class="collapse" py:if="potential_projects">
<form method="post" action="addproject" class="form-row">
<input type="hidden" value="${active_person.username}" name="username"/>
<select id="add_project" class="form-control col-sm-8 " name="project">
<option py:for="p in potential_projects" value="${p.id}">${p}</option>
</select>
<select id="add_level" class="form-control col-sm-3" name="level">
<option py:for="l in Level" value="${l.value}" py:content="l.name"/>
</select>
<button class="btn btn-success btn-sm col-sm-1" type="submit" title="add record"><i class="fas fa-check"/></button>
</form>

</div>


</div>

Expand Down
4 changes: 1 addition & 3 deletions odmf/static/templates/project.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,8 @@ <h2 class="border-bottom">Members</h2>
<a href="#add-member" py:if="is_member(Level.admin, actproject.id)" class="btn-sm btn-primary dropdown-toggle" data-toggle="collapse" aria-controls="add-member" aria-role="button"><i class="fas fa-plus"/> add member...</a>
<div py:if="is_member(Level.admin, actproject.id)" class="collapse" id="add-member">
<form class="form-row border" method="post" action="add_member">
<input type="hidden" value="${actproject.id}" xname="project_id"/>

<select id="add_who" class="form-control col-sm-8 select2" name="member_name" >
<option value="${p.username}" py:for="p in persons" py:content="f'{p} ({Level(p.access_level).name})'"/>
<option value="${p.username}" py:for="p in persons" py:content="f'{p} ({Level(p.access_level or 0).name})'"/>
</select>
<select id="add_level" class="form-control col-sm-3" name="access_level">
<option py:for="l in Level" value="${l.value}" py:content="l.name"/>
Expand Down
34 changes: 29 additions & 5 deletions odmf/webpage/db_editor/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ def default(self, act_user=None, error='', msg=''):
with db.session_scope() as session:
persons = session.query(db.Person).order_by(
db.sql.desc(db.Person.can_supervise), db.Person.surname)

me: db.Person = session.query(db.Person).get(users.current.name)
# 'guest' user can't see himself in the user list
if users.current.name == 'guest':
persons = persons.filter(db.Person.access_level != 0)
# TODO: url "host/guest" shouldn't be accessible for the guest user

supervisors = persons.filter(db.Person.can_supervise == True)
jobs = []
act_user = act_user or users.current.name
Expand All @@ -37,6 +36,15 @@ def default(self, act_user=None, error='', msg=''):
except:
p_act = session.get(db.Person, users.current.name)
error = traceback()
user_projects = [p for p, level in p_act.projects()]
if me.access_level >= Level.admin:
potential_projects = [p for p in session.query(db.Project).order_by(db.Project.id) if p not in user_projects]
else:
potential_projects = [
p for p, level in me.projects()
if level >= Level.admin and p not in user_projects
]

return web.render(
'person.html',
persons=persons,
Expand All @@ -45,6 +53,7 @@ def default(self, act_user=None, error='', msg=''):
error=error, success=msg,
jobs=jobs,
act_user=act_user,
potential_projects=potential_projects,
is_self=is_self
).render()

Expand All @@ -59,7 +68,7 @@ def saveitem(self, **kwargs):
p_act = session.query(db.Person).filter_by(
username=username).first()
if not p_act:
p_act = db.Person(username=username, active=False)
p_act = db.Person(username=username, active=False, access_level=0)
session.add(p_act)
p_act.email = kwargs.get('email')
p_act.firstname = kwargs.get('firstname')
Expand All @@ -69,7 +78,7 @@ def saveitem(self, **kwargs):
db.Person).get(kwargs.get('supervisor'))
p_act.telephone = kwargs.get('telephone')
p_act.comment = kwargs.get('comment')
if kwargs.get('status') == 'on':
if kwargs.get('status') == 'on' or is_self(username):
p_act.active = True
else:
p_act.active = False
Expand All @@ -86,7 +95,6 @@ def saveitem(self, **kwargs):
else:
error = 'Passwords not equal'
# Simple Validation
# if users.current.level == ACCESS_LEVELS['Supervisor']:
acl = web.conv(int, kwargs.get('access_level'))
if acl and acl <= users.current.level:
p_act.access_level = acl
Expand All @@ -99,6 +107,22 @@ def saveitem(self, **kwargs):

raise web.redirect(username, error=error, msg=msg)

@expose_for(Level.editor)
@web.method.post
def addproject(self, username, project, level):
with db.session_scope() as session:
me: db.Person = session.query(db.Person).get(users.current.name)
user: db.Person = session.query(db.Person).get(username)
project: db.Project = session.query(db.Project).get(int(project))
level = Level(int(level))
if project.get_access_level(me) >= Level.admin:
project.add_member(user, level)
msg = f'Added {user} to {project} as {level.name}'
else:
raise web.HTTPError(403, f'You are not an admin of the project {project}, can\'t add members')
raise web.redirect(username, msg=msg)


@expose_for()
@web.mime.json
def json(self, supervisors=False):
Expand Down

0 comments on commit ec5ec5e

Please sign in to comment.