Skip to content
Snippets Groups Projects
Commit c169dca5 authored by kaiyou's avatar kaiyou
Browse files

Improve upon the action framework and add assignment

parent 21f3873e
No related branches found
No related tags found
No related merge requests found
......@@ -53,7 +53,7 @@
</a>
</li>
{% endif %}
{% for action in common.get_actions(profile) %}
{% for action in profile.actions %}
<li class="nav-item">
<a class="nav-link" href="{{ action.url(profile=profile) }}">
<i class="{{ action.icon }}"></i>&nbsp;
......
......@@ -86,3 +86,23 @@ class CancelTransition(Action):
def authorized(self, profile):
return profile.transition_step
class Assign(Action):
""" Assign a claimable profile
"""
action = "profile.assign"
label = _("assign")
description = _("assign the profile to a user")
icon=""
def url(self, profile):
return super(Assign, self).url(profile_uuid=profile.uuid)
def authorized(self, profile):
return (
flask_login.current_user.is_admin and
profile.status == profile.UNCLAIMED
)
......@@ -255,7 +255,8 @@ class Profile(db.Model):
label=_("purge"), description=_("delete and purge this profile"),
icon="fas fa-trash", from_=(ACTIVE, BLOCKED, DELETED), to=PURGED,
delay=120
)
),
"assign": actions.Assign()
}
user_uuid = db.Column(db.String(36), db.ForeignKey(User.uuid))
......@@ -277,6 +278,16 @@ class Profile(db.Model):
def email(self):
return "{}@{}".format(self.uuid, app.config.get("MAIL_DOMAIN"))
@property
def actions(self):
print(">>> Actions are...",)
result = [
action for action in Profile.TRANSITIONS.values()
if action.authorized(self)
]
print(repr(result))
return result
@classmethod
def filter(cls, service, user):
return cls.query.filter_by(
......
......@@ -37,21 +37,4 @@ def apply_transition(profile):
}[profile.transition_step]
if profile.transition_step == models.Profile.DONE:
profile.status = transition.to
def get_actions(profile):
""" Get available actions on the given profile for the current user
Actions are represented as tuples: (url, name, description, color, icon)
"""
result = []
# First add transitions
result.extend([
transition for transition in profile.TRANSITIONS.values()
if transition.authorized(profile)
])
if profile.transition_step:
result.append(actions.CancelTransition())
return result
......@@ -12,8 +12,10 @@
<dt class="col-lg-3">{% trans %}Username{% endtrans %}</dt>
<dd class="col-lg-9">{{ profile.username }}</dd>
{% if profile.user %}
<dt class="col-lg-3">{% trans %}Owner{% endtrans %}</dt>
<dd class="col-lg-9"><a href="{{ url_for("user.details", user_uuid=profile.user_uuid) }}">{{ profile.user.username }}</a></dd>
{% endif %}
<dt class="col-lg-3">{% trans %}UUID{% endtrans %}</dt>
<dd class="col-lg-9"><pre>{{ profile.uuid }}</pre></dd>
......@@ -34,7 +36,7 @@
</div>
<div class="card-body">
<dl class="row">
{% for action in actions %}
{% for action in profile.actions %}
<dt class="col-3"><a href="{{ action.url(profile) }}">{{ action.label | capitalize }}</a></dt>
<dd class="col-9">{{ action.description | capitalize }}</dd>
{% endfor %}
......@@ -51,7 +53,7 @@
{% endblock %}
{% block actions %}
{% for action in actions %}
{% for action in profile.actions %}
<a href="{{ action.url(profile) }}" class="btn btn-info">{{ action.label | capitalize }}</a>
{% endfor %}
{% endblock %}
......@@ -36,18 +36,17 @@
{% if not service %}
<td>{{ profile.service.name }}</td>
{% endif %}
{% if profile.user_uuid %}
<td><a href="{{ url_for("profile.details", profile_uuid=profile.uuid) }}">{{ profile.username }}</a></td>
{% if profile.user_uuid %}
<td><a href="{{ url_for("user.details", user_uuid=profile.user_uuid) }}">{{ profile.user.username }}</a></td>
{% else %}
<td>{{ profile.username }}</td>
<td>-</td>
{% endif %}
<td>{{ profile.uuid }}</td>
<td>{{ macros.profile_status(profile) }}</td>
<td>{{ profile.created_at.date() }}</td>
<td>
{% for action in common.get_actions(profile) %}
{% for action in profile.actions %}
<a href="{{ action.url(profile) }}">{{ action.label | capitalize }}</a>
{% endfor %}
</td>
......
......@@ -139,7 +139,7 @@ def claim(service_uuid):
def list_for_status(status):
profiles = models.Profile.query.filter_by(status=status).all()
return flask.render_template("profile_list.html", profiles=profiles,
status=models.Profile.STATUSES[status], common=common)
status=models.Profile.STATUSES[status])
@blueprint.route("/list/service/<service_uuid>")
......@@ -147,7 +147,7 @@ def list_for_status(status):
def list_for_service(service_uuid):
service = models.Service.query.get(service_uuid) or flask.abort(404)
return flask.render_template("profile_list.html", profiles=service.profiles,
service=service, common=common)
service=service)
@blueprint.route("/unclaimedexport/service/<service_uuid>.csv")
......@@ -162,7 +162,7 @@ def unclaimed_export_for_service(service_uuid):
@security.admin_required()
def details(profile_uuid):
profile = models.Profile.query.get(profile_uuid) or flask.abort(404)
return flask.render_template("profile_details.html", profile=profile, actions=common.get_actions(profile))
return flask.render_template("profile_details.html", profile=profile)
@blueprint.route("/action/<profile_uuid>/<action>", methods=["GET", "POST"])
......
......@@ -6,6 +6,8 @@ import flask_limiter
import flask_redis
import babel
from werkzeug import routing
# Login configuration
login = flask_login.LoginManager()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment