Check user's access to server. If allowed connect. Parameters ---------- access: dict user: dict server_name: str libraries: list Returns ------- server_connection: class
(access, user, server_name, libraries=None)
| 330 | |
| 331 | |
| 332 | def check_users_access(access, user, server_name, libraries=None): |
| 333 | """Check user's access to server. If allowed connect. |
| 334 | |
| 335 | Parameters |
| 336 | ---------- |
| 337 | access: dict |
| 338 | user: dict |
| 339 | server_name: str |
| 340 | libraries: list |
| 341 | |
| 342 | Returns |
| 343 | ------- |
| 344 | server_connection: class |
| 345 | |
| 346 | """ |
| 347 | try: |
| 348 | _user = access.get(user) |
| 349 | for access in _user['access']: |
| 350 | server = access.get("server") |
| 351 | # Check user access to server |
| 352 | if server.get(server_name): |
| 353 | server_obj = server.get(server_name) |
| 354 | # If syncing by libraries, check library access |
| 355 | if libraries: |
| 356 | library_check = any(lib.title in access.get("sections").keys() for lib in libraries) |
| 357 | # Check user access to library |
| 358 | if library_check: |
| 359 | server_connection = connect_to_server(server_obj, _user['account']) |
| 360 | return server_connection |
| 361 | |
| 362 | elif not library_check: |
| 363 | print("User does not have access to this library.") |
| 364 | # Not syncing by libraries |
| 365 | else: |
| 366 | server_connection = connect_to_server(server_obj, _user['account']) |
| 367 | return server_connection |
| 368 | # else: |
| 369 | # print("User does not have access to this server: {}.".format(server_name)) |
| 370 | except KeyError: |
| 371 | print('User name is incorrect.') |
| 372 | print(", ".join(plex_admin.all_users().keys())) |
| 373 | exit() |
| 374 | |
| 375 | |
| 376 | def sync_watch_status(watched, section, accountTo, userTo, same_server=False): |
no test coverage detected