Skip to content
Snippets Groups Projects
Verified Commit 069b8364 authored by ornanovitch's avatar ornanovitch Committed by ornanovitch
Browse files

Merge branch '58-pouvoir-supprimer-un-profil-non-reclame' into 'dev'

Resolve "Pouvoir supprimer un profil non réclamé"

Closes #58 and #39

See merge request !80
parent 0049ff4b
No related branches found
No related tags found
No related merge requests found
......@@ -86,23 +86,3 @@ 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
)
......@@ -253,6 +253,10 @@ class Profile(db.Model):
}
TRANSITIONS = {
"assign": actions.Transition("assign",
label=(_("assign")), description=(_("assign this profile to a user")),
icon="fas fa-people-arrows", from_=(UNCLAIMED,), to=ACTIVE
),
"activate": actions.Transition("activate",
label=(_("activate")), description=(_("activate this profile")),
icon="fas fa-user-check", from_=(REQUEST,), to=ACTIVE
......@@ -276,10 +280,9 @@ class Profile(db.Model):
),
"purge": actions.Transition("purge",
label=(_("purge")), description=(_("delete and purge this profile")),
icon="fas fa-trash", from_=(ACTIVE, BLOCKED, DELETED), to=PURGED,
icon="fas fa-trash", from_=(UNCLAIMED, ACTIVE, BLOCKED, DELETED), to=PURGED,
delay=120
),
"assign": actions.Assign()
)
}
user_uuid = db.Column(db.String(36), db.ForeignKey(User.uuid))
......
......@@ -197,6 +197,9 @@ def start_transition(profile_uuid, transition_id):
actor=flask_login.current_user,
public=True
)
if transition_id == "assign":
user = hiboo_user.get_user(intent="profile.start_transition", profile_uuid=profile_uuid)
profile.user_uuid = user.uuid
models.db.session.commit()
flask.flash(_("Profile status change was requested"), "success")
if transition_id == "delete" and flask_login.current_user.is_admin == False or transition_id == "purge" and not flask_login.current_user.is_admin:
......@@ -228,25 +231,3 @@ def complete_transition(profile_uuid):
models.db.session.commit()
flask.flash(_("Profile status change was completed"), "success")
return flask.redirect(flask.url_for(".details", profile_uuid=profile_uuid))
@blueprint.route("/assign/<profile_uuid>", methods=["GET", "POST"])
@security.admin_required()
def assign(profile_uuid):
profile = models.Profile.query.get(profile_uuid) or flask.abort(404)
assert profile.status == models.Profile.UNCLAIMED
user = hiboo_user.get_user(intent="profile.assign", profile_uuid=profile_uuid)
profile.user_uuid = user.uuid
profile.status = models.Profile.ACTIVE
models.log(
category=models.History.STATUS,
value=models.Profile.ACTIVE,
user=user,
service=profile.service,
profile=profile,
actor=flask_login.current_user,
public=True
)
models.db.session.commit()
flask.flash(_("Successfully assigned the profile"), "success")
return flask.redirect(flask.url_for(".details", profile_uuid=profile_uuid))
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