Add disconnect GitHub button

This commit is contained in:
rubenwardy 2024-04-30 23:13:22 +01:00
parent a2125acddd
commit 3d9fe80177
2 changed files with 52 additions and 20 deletions

@ -129,8 +129,7 @@ def profile_edit(username):
abort(404)
if not user.can_see_edit_profile(current_user):
flash(gettext("Permission denied"), "danger")
return redirect(url_for("users.profile", username=username))
abort(403)
form = UserProfileForm(obj=user)
if form.validate_on_submit():
@ -243,9 +242,31 @@ def account(username):
if not user:
abort(404)
if not user.can_see_edit_profile(current_user):
abort(403)
return render_template("users/account.html", user=user, tabs=get_setting_tabs(user), current_tab="account")
@bp.route("/users/<username>/settings/account/disconnect-github/", methods=["POST"])
def disconnect_github(username: str):
user: User = User.query.filter_by(username=username).one_or_404()
if not user.can_see_edit_profile(current_user):
abort(403)
if user.password and user.email:
user.github_user_id = None
user.github_username = None
db.session.commit()
flash(gettext("Removed GitHub account"), "success")
else:
flash(gettext("You need to add an email address and password before you can remove your GitHub account"), "danger")
return redirect(url_for("users.account", username=username))
@bp.route("/users/<username>/delete/", methods=["GET", "POST"])
@rank_required(UserRank.ADMIN)
def delete(username):

@ -30,14 +30,14 @@
{% endif %}
{% endif %}
<h3>{{ _("Linked Accounts") }}</h3>
<h3 class="mt-5">{{ _("Linked Accounts") }}</h3>
<table class="table">
<tr>
<td>Forums</td>
<td>
{% if user.forums_username %}
<a class="btn btn-secondary" href="https://forum.minetest.net/memberlist.php?mode=viewprofile&un={{ user.forums_username }}">
{{ _("Connected") }} [{{ user.forums_username }}]
<a href="https://forum.minetest.net/memberlist.php?mode=viewprofile&un={{ user.forums_username }}">
{{ user.forums_username }}
</a>
{% else %}
{{ _("Please PM %(rubenwardy)s on the forums to link your account.", rubenwardy=self.ruben_link()) }}
@ -48,15 +48,23 @@
<td>GitHub</td>
<td>
{% if user.github_username %}
<a class="btn btn-secondary" href="https://github.com/{{ user.github_username }}">
{{ _("Connected") }} [{{ user.github_username }}]
</a>
<p>
<a href="https://github.com/{{ user.github_username }}">
{{ user.github_username }}
</a>
</p>
{% if user == current_user %}
<a class="btn btn-secondary ms-2" href="{{ url_for('github.view_permissions') }}">
<a class="btn btn-secondary" href="{{ url_for('github.view_permissions') }}">
{{ _("View ContentDB's GitHub Permissions") }}
</a>
{% endif %}
{% if user.forums_username %}
<form method="post" action="{{ url_for('users.disconnect_github', username=user.username) }}" class="d-inline-block">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="submit" class="btn btn-secondary" value="{{ _('Disconnect') }}" />
</form>
{% endif %}
{% elif user == current_user %}
<a class="btn btn-secondary" href="{{ url_for('github.start') }}">
{{ _("Link Github") }}
@ -68,18 +76,8 @@
</tr>
</table>
{% if current_user.rank.at_least(current_user.rank.MODERATOR) %}
<a class="btn btn-secondary float-end" href="{{ url_for('admin.audit', username=user.username) }}">
{{ _("View All") }}
</a>
{% endif %}
<h3>{{ _("Recent Account Actions") }}</h3>
{% from "macros/audit_log.html" import render_audit_log %}
{{ render_audit_log(user.audit_log_entries.limit(10).all(), current_user) }}
<h3>{{ _("Account Deletion and Deactivation") }}</h3>
<h3 class="mt-5">{{ _("Account Deletion and Deactivation") }}</h3>
{% if current_user.rank.at_least(current_user.rank.ADMIN) %}
<a class="btn btn-danger" href="{{ url_for('users.delete', username=user.username) }}">
@ -91,4 +89,17 @@
</p>
{% endif %}
<h3 class="mt-5">{{ _("Recent Account Actions") }}</h3>
{% from "macros/audit_log.html" import render_audit_log %}
{{ render_audit_log(user.audit_log_entries.limit(10).all(), current_user) }}
{% if current_user.rank.at_least(current_user.rank.MODERATOR) %}
<p class="mt-4">
<a class="btn btn-secondary" href="{{ url_for('admin.audit', username=user.username) }}">
{{ _("View All") }}
</a>
</p>
{% endif %}
{% endblock %}