mirror of
https://github.com/YunoHost-Apps/wekan_ynh.git
synced 2024-09-03 20:36:09 +02:00
Create admin user.
This commit is contained in:
parent
f597a38525
commit
516f9fcb8a
4 changed files with 59 additions and 1 deletions
29
conf/add_admin_user.py
Normal file
29
conf/add_admin_user.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
import ldapsync
|
||||
|
||||
def ldap_sync():
|
||||
print("Fetching user __ADMIN__ from LDAP")
|
||||
ldap = LdapConnection()
|
||||
ldap_user = ldap.get_users()['__ADMIN__']
|
||||
ldap_user['is_superuser'] = True
|
||||
|
||||
print("Fetching users from Wekan")
|
||||
wekan_username_list = []
|
||||
for user in mongodb_database["users"].find():
|
||||
if not user['loginDisabled']:
|
||||
wekan_username_list.append(user['username'])
|
||||
|
||||
print("Sorting users")
|
||||
in_wekan = '__ADMIN__' in wekan_username_list
|
||||
|
||||
print("Processing users")
|
||||
if in_wekan:
|
||||
print(f"User in Wekan, updating {ldap_user}")
|
||||
update_wekan_user(ldap_user)
|
||||
else:
|
||||
print(f"User not in Wekan, adding {ldap_user}")
|
||||
create_wekan_user(ldap_user)
|
||||
|
||||
print("Done")
|
||||
|
||||
if __name__ == "__main__":
|
||||
ldap_sync()
|
|
@ -51,6 +51,12 @@ ram.runtime = "50M"
|
|||
autoupdate.strategy = "latest_github_release"
|
||||
autoupdate.asset.amd64 = ".*-amd64.zip"
|
||||
|
||||
[resources.sources.ldap]
|
||||
url = "https://raw.githubusercontent.com/wekan/wekan/main/docs/Login/ldap-sync/ldap-sync.py"
|
||||
sha256 = "c65fad3ad90072d45df5995074e2f9924fc6399c17867ab15305300b6c7eddf9"
|
||||
format = "whatever"
|
||||
rename = "ldapsync.py"
|
||||
|
||||
[resources.ports]
|
||||
|
||||
[resources.system_user]
|
||||
|
@ -60,4 +66,6 @@ ram.runtime = "50M"
|
|||
|
||||
[resources.permissions]
|
||||
main.url = "/"
|
||||
#admin.allowed = "admins"
|
||||
|
||||
[resources.apt]
|
||||
packages = ["python3", "python3-venv"]
|
||||
|
|
|
@ -11,6 +11,24 @@ mongo_version="7.0"
|
|||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
||||
ynh_sync_admin_user_to_wekan() {
|
||||
local tmp=$(mktemp -d)
|
||||
|
||||
ynh_setup_source --dest_dir="$tmp" --source_id="ldap"
|
||||
|
||||
python3 -m venv $tmp
|
||||
source $tmp/bin/activate
|
||||
pip install pymongo ldap3 environs
|
||||
|
||||
ynh_add_config --template="add_admin_user.py" --destination="$tmp/add_admin_user.py"
|
||||
source "$install_dir/.env"
|
||||
|
||||
python3 $tmp/add_admin_user.py
|
||||
|
||||
deactivate
|
||||
ynh_secure_remove --file="$tmp"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# EXPERIMENTAL HELPERS
|
||||
#=================================================
|
||||
|
|
|
@ -80,6 +80,9 @@ ynh_add_config --template=".env" --destination="$install_dir/.env"
|
|||
chmod 400 "$install_dir/.env"
|
||||
chown $app:$app "$install_dir/.env"
|
||||
|
||||
ynh_script_progression --message="Updating the admin user..."
|
||||
ynh_sync_admin_user_to_wekan
|
||||
|
||||
#=================================================
|
||||
# START SYSTEMD SERVICE
|
||||
#=================================================
|
||||
|
|
Loading…
Reference in a new issue