mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 11:26:56 -08:00
admin update user roles
This commit is contained in:
parent
33abd5458a
commit
259d7c619c
4 changed files with 23 additions and 1 deletions
|
@ -117,6 +117,11 @@ class AddUserForm(FlaskForm):
|
|||
ignore_bots = BooleanField(_l('Hide posts by bots'))
|
||||
nsfw = BooleanField(_l('Show NSFW posts'))
|
||||
nsfl = BooleanField(_l('Show NSFL posts'))
|
||||
role_options = [(2, _l('User')),
|
||||
(3, _l('Staff')),
|
||||
(4, _l('Admin')),
|
||||
]
|
||||
role = SelectField(_l('Role'), choices=role_options, default=2, coerce=int)
|
||||
submit = SubmitField(_l('Save'))
|
||||
|
||||
def validate_email(self, email):
|
||||
|
@ -174,6 +179,11 @@ class EditUserForm(FlaskForm):
|
|||
searchable = BooleanField(_l('Show profile in user list'))
|
||||
indexable = BooleanField(_l('Allow search engines to index this profile'))
|
||||
manually_approves_followers = BooleanField(_l('Manually approve followers'))
|
||||
role_options = [(2, _l('User')),
|
||||
(3, _l('Staff')),
|
||||
(4, _l('Admin')),
|
||||
]
|
||||
role = SelectField(_l('Role'), choices=role_options, default=2, coerce=int)
|
||||
submit = SubmitField(_l('Save'))
|
||||
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ from app.admin.forms import FederationForm, SiteMiscForm, SiteProfileForm, EditC
|
|||
from app.admin.util import unsubscribe_from_everything_then_delete, unsubscribe_from_community, send_newsletter
|
||||
from app.community.util import save_icon_file, save_banner_file
|
||||
from app.models import AllowedInstances, BannedInstances, ActivityPubLog, utcnow, Site, Community, CommunityMember, \
|
||||
User, Instance, File, Report, Topic, UserRegistration
|
||||
User, Instance, File, Report, Topic, UserRegistration, Role
|
||||
from app.utils import render_template, permission_required, set_setting, get_setting, gibberish, markdown_to_html, \
|
||||
moderating_communities, joined_communities, finalize_user_setup, theme_list
|
||||
from app.admin import bp
|
||||
|
@ -553,6 +553,13 @@ def admin_user_edit(user_id):
|
|||
user.searchable = form.searchable.data
|
||||
user.indexable = form.indexable.data
|
||||
user.ap_manually_approves_followers = form.manually_approves_followers.data
|
||||
|
||||
# Update user roles. The UI only lets the user choose 1 role but the DB structure allows for multiple roles per user.
|
||||
for role in user.roles:
|
||||
if role.id != form.role.data:
|
||||
user.roles.remove(role)
|
||||
user.roles.append(Role.query.get(form.role.data))
|
||||
|
||||
db.session.commit()
|
||||
user.flush_cache()
|
||||
flash(_('Saved'))
|
||||
|
@ -573,6 +580,8 @@ def admin_user_edit(user_id):
|
|||
form.searchable.data = user.searchable
|
||||
form.indexable.data = user.indexable
|
||||
form.manually_approves_followers.data = user.ap_manually_approves_followers
|
||||
if user.roles:
|
||||
form.role.data = user.roles[0].id
|
||||
|
||||
return render_template('admin/edit_user.html', title=_('Edit user'), form=form, user=user,
|
||||
moderating_communities=moderating_communities(current_user.get_id()),
|
||||
|
@ -635,6 +644,7 @@ def admin_users_add():
|
|||
user.ap_profile_id = f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}"
|
||||
user.ap_public_url = f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}"
|
||||
user.ap_inbox_url = f"https://{current_app.config['SERVER_NAME']}/u/{user.user_name}/inbox"
|
||||
user.roles.append(Role.query.get(form.role.data))
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
{{ render_field(form.newsletter) }}
|
||||
{{ render_field(form.nsfw) }}
|
||||
{{ render_field(form.nsfl) }}
|
||||
{{ render_field(form.role) }}
|
||||
{{ render_field(form.submit) }}
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
{{ render_field(form.searchable) }}
|
||||
{{ render_field(form.indexable) }}
|
||||
{{ render_field(form.manually_approves_followers) }}
|
||||
{{ render_field(form.role) }}
|
||||
{{ render_field(form.submit) }}
|
||||
</form>
|
||||
<p class="mt-4">
|
||||
|
|
Loading…
Reference in a new issue