-
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
app/permissions: Move permissions data out of LDAP
- Loading branch information
Showing
4 changed files
with
149 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from logging import getLogger | ||
|
||
from yunohost.tools import Migration | ||
from yunohost.permission import permission_sync_to_user | ||
from yunohost.app import app_setting | ||
|
||
logger = getLogger("yunohost.migration") | ||
|
||
################################################### | ||
# Tools used also for restoration | ||
################################################### | ||
|
||
|
||
class MyMigration(Migration): | ||
|
||
introduced_in_version = "12.1" | ||
dependencies = [] | ||
|
||
ldap_migration_started = False | ||
|
||
@Migration.ldap_migration | ||
def run(self, *args): | ||
|
||
self.ldap_migration_started = True | ||
|
||
permissions_per_app = self.read_legacy_permissions_per_app() | ||
for app, permissions in permissions_per_app.items(): | ||
print(app) | ||
print(permissions) | ||
app_setting(app, "_permissions", permissions) | ||
|
||
permission_sync_to_user() | ||
|
||
# FIXME : dummy excepton to trigger the rollback while debugging everything etc | ||
raise Exception | ||
|
||
def run_after_system_restore(self): | ||
self.run() | ||
|
||
def read_legacy_permissions_per_app(self): | ||
|
||
from yunohost.utils.ldap import _get_ldap_interface | ||
SYSTEM_PERMS = ["mail", "sftp", "ssh"] | ||
|
||
ldap = _get_ldap_interface() | ||
permissions_infos = ldap.search( | ||
"ou=permission", | ||
"(objectclass=permissionYnh)", | ||
[ | ||
"cn", | ||
"URL", | ||
"additionalUrls", | ||
"authHeader", | ||
"label", | ||
"showTile", | ||
"isProtected", | ||
], | ||
) | ||
|
||
permissions_per_app = {} | ||
for infos in permissions_infos: | ||
app, name = infos["cn"][0].split(".") | ||
|
||
if app in SYSTEM_PERMS: | ||
continue | ||
|
||
if app not in permissions_per_app: | ||
permissions_per_app[app] = {} | ||
|
||
permissions_per_app[app][name] = { | ||
"label": infos.get("label", [None])[0], | ||
"show_tile": infos.get("showTile", [False])[0] == "TRUE", | ||
"auth_header": infos.get("authHeader", [False])[0] == "TRUE", | ||
"protected": infos.get("isProtected", [False])[0] == "TRUE", | ||
"url": infos.get("URL", [None])[0], | ||
"additional_urls": infos.get("additionalUrls", []), | ||
} | ||
|
||
return permissions_per_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters