def _get_user_rows(self, request, app_id, start_key=None, query=[]): adapter = DjangoAdapter(app_id, request) with adapter.open_api_auth() as api: query = list(map(lambda x: json.loads(x), query)) result = api.get_users(start_key, limit=20, query=query) users = result['items'] end_key = result.get('end_key') user_groups = api.get_user_groups()['groups'] visible_user_fields = ['id', 'creation_date', 'email', 'groups'] none_extra_fields = [ 'id', 'creation_date', 'email', 'groups', 'password_hash', 'salt', 'partition', 'login_method' ] template = loader.get_template( 'dashboard/app/component/auth_user_table_row.html') context = { 'users': users, 'user_groups': user_groups, 'visible_user_fields': visible_user_fields, 'none_extra_fields': none_extra_fields, } return { 'user_rows': template.render(context, request), 'end_key': end_key }
def get(self, request, app_id): context = Util.get_context(request) context['app_id'] = app_id adapter = DjangoAdapter(app_id, request) with adapter.open_api_auth() as auth_api, adapter.open_api_logic( ) as logic_api: context['user_groups'] = auth_api.get_user_groups()['groups'] context['functions'] = logic_api.get_functions()['items'] return render(request, 'dashboard/app/schedule.html', context=context)
def get(self, request, app_id): context = Util.get_context(request) context['app_id'] = app_id adapter = DjangoAdapter(app_id, request) # allocate_resource_in_background(adapter) with adapter.open_api_auth() as auth_api, adapter.open_api_storage( ) as storage_api: cmd = request.GET.get('cmd', None) if cmd == 'download_file': file_path = request.GET['file_path'] file_name = file_path.split('/').pop() file_bin_b64 = storage_api.download_b64(file_path) file_bin = base64.b64decode(file_bin_b64) response = HttpResponse(file_bin, content_type='application/x-binary') file_name = file_name.encode('utf8').decode('ISO-8859-1') response[ 'Content-Disposition'] = 'attachment; filename=%s' % os.path.basename( file_name) return response elif cmd == 'download_b64': file_id = request.GET['file_id'] string_file_b64 = None file_name = 'file' while file_id: result = storage_api.download_b64(file_id) file_id = result.get('parent_file_id', None) string_b64_chuck = result.get('file_b64') if string_file_b64: string_file_b64 = string_b64_chuck + string_file_b64 else: string_file_b64 = string_b64_chuck file_name = result.get('file_name', file_name) string_b64 = string_file_b64.encode('utf-8') file_bin = base64.b64decode(string_b64) response = HttpResponse(file_bin, content_type='application/x-binary') file_name = file_name.encode('utf8').decode('ISO-8859-1') response[ 'Content-Disposition'] = 'attachment; filename=%s' % os.path.basename( file_name) return response else: result = storage_api.get_b64_info_items(start_key=None, reverse=True) context['app_id'] = app_id context['b64_info'] = result context['user_groups'] = auth_api.get_user_groups()['groups'] return render(request, 'dashboard/app/storage.html', context=context)
def _get_session_rows(self, request, app_id, start_key=None): adapter = DjangoAdapter(app_id, request) with adapter.open_api_auth() as api: result = api.get_sessions(start_key, limit=30) sessions = result['items'] end_key = result.get('end_key') template = loader.get_template('dashboard/app/component/auth_session_table_row.html') context = { 'sessions': sessions, } return { 'session_rows': template.render(context, request), 'end_key': end_key }
def get(self, request, app_id): context = Util.get_context(request) context['app_id'] = app_id adapter = DjangoAdapter(app_id, request) with adapter.open_api_auth() as auth_api, adapter.open_api_logic( ) as logic_api: context['user_groups'] = auth_api.get_user_groups()['groups'] context['functions'] = logic_api.get_functions()['items'] context['function_tests'] = logic_api.get_function_tests()['items'] webhooks = logic_api.get_webhooks()['items'] for webhook in webhooks: webhook['url'] = logic_api.get_webhook_url( webhook['name'])['url'] context['webhooks'] = webhooks return render(request, 'dashboard/app/logic.html', context=context)
def get(self, request, app_id): start = time.time() context = Util.get_context(request) context['app_id'] = app_id adapter = DjangoAdapter(app_id, request) # allocate_resource_in_background(adapter) with adapter.open_api_auth() as api: user_groups = api.get_user_groups()['groups'] for user_group in user_groups: user_group.setdefault('permissions', []) context['user_groups'] = user_groups context['user_count'] = api.get_user_count(count_system_user=True) context['session_count'] = api.get_session_count() context['users'] = api.get_users() context['visible_user_fields'] = [ 'id', 'creation_date', 'email', 'groups' ] context['none_extra_fields'] = [ 'id', 'creation_date', 'email', 'groups', 'password_hash', 'salt', 'partition', 'login_method' ] context['sessions'] = api.get_sessions() context['email_login'] = api.get_login_method( 'email_login')['item'] context['guest_login'] = api.get_login_method( 'guest_login')['item'] context['facebook_login'] = api.get_login_method( 'facebook_login')['item'] context['google_login'] = api.get_login_method( 'google_login')['item'] context['naver_login'] = api.get_login_method( 'naver_login')['item'] context['kakao_login'] = api.get_login_method( 'kakao_login')['item'] context['all_permissions'] = api.get_all_permissions( )['permissions'] return render(request, 'dashboard/app/auth.html', context=context)
def get(self, request, app_id): context = Util.get_context(request) context['app_id'] = app_id adapter = DjangoAdapter(app_id, request) allocate_resource_in_background(adapter) with adapter.open_api_auth() as auth_api, adapter.open_api_database( ) as database_api: partitions = database_api.get_partitions().get('items', []) partition_dict = {} for partition in partitions: name = partition['name'] result = database_api.get_item_count(name) partition_dict[name] = { 'name': name, 'item_count': result['item']['count'] } partitions = partition_dict.values() context['user_groups'] = auth_api.get_user_groups()['groups'] context['partitions'] = partitions return render(request, 'dashboard/app/database.html', context=context)
def get(self, request, app_id): context = Util.get_context(request) context['app_id'] = app_id adapter = DjangoAdapter(app_id, request) allocate_resource_in_background(adapter) with adapter.open_api_auth() as api: context['user_groups'] = api.get_user_groups()['groups'] context['user_count'] = api.get_user_count() context['session_count'] = api.get_session_count() context['users'] = api.get_users() context['visible_user_fields'] = ['id', 'creation_date', 'email', 'groups'] context['none_extra_fields'] = ['id', 'creation_date', 'email', 'groups', 'password_hash', 'salt', 'partition', 'login_method'] context['sessions'] = api.get_sessions() context['email_login'] = api.get_login_method('email_login')['item'] context['guest_login'] = api.get_login_method('guest_login')['item'] context['facebook_login'] = api.get_login_method('facebook_login')['item'] context['all_permissions'] = api.get_all_permissions()['permissions'] return render(request, 'dashboard/app/auth.html', context=context)
def post(self, request, app_id): context = Util.get_context(request) context['app_id'] = app_id adapter = DjangoAdapter(app_id, request) with adapter.open_api_auth() as api: cmd = request.POST['cmd'] if cmd == 'delete_group': name = request.POST['group_name'] error = api.delete_user_group(name).get('error', None) if error: Util.add_alert( request, '{}: {}'.format(error['code'], error['message'])) elif cmd == 'put_group': name = request.POST['group_name'] description = request.POST['group_description'] api.put_user_group(name, description) elif cmd == 'set_login_method': login_method = request.POST['login_method'] default_group = request.POST['default_group_name'] enabled = request.POST['enabled'] register_policy_code = request.POST.get( 'register_policy_code', None) if enabled == 'true': enabled = True else: enabled = False api.set_login_method(login_method, enabled, default_group, register_policy_code) elif cmd == 'put_user': email = request.POST['user_email'] password = request.POST['user_password'] api.create_user(email, password, {}) elif cmd == 'delete_user': user_id = request.POST['user_id'] api.delete_user(user_id) elif cmd == 'delete_sessions': session_ids = request.POST.getlist('session_ids[]') api.delete_sessions(session_ids) elif cmd == 'delete_users': user_ids = request.POST.getlist('user_ids[]') api.delete_users(user_ids) elif cmd == 'detach_group_permission': group_name = request.POST.get('group_name') permission = request.POST.get('permission') api.detach_group_permission(group_name, permission) elif cmd == 'attach_group_permission': group_name = request.POST.get('group_name') permission = request.POST.get('permission') api.attach_group_permission(group_name, permission) elif cmd == 'set_users': user_ids = request.POST.getlist('user_ids[]') field_name = request.POST.get('field_name') field_type = request.POST.get('field_type') field_value = request.POST.get('field_value', None) if field_type == 'S': field_value = str(field_value) elif field_type == 'N': field_value = Decimal(field_value) with ThreadPoolExecutor(max_workers=32) as exc: for user_id in user_ids: exc.submit(api.set_user, user_id, field_name, field_value) elif cmd == 'attach_user_group': user_id = request.POST.get('user_id') group_name = request.POST.get('group_name') api.attach_user_group(user_id, group_name) elif cmd == 'detach_user_group': user_id = request.POST.get('user_id') group_name = request.POST.get('group_name') api.detach_user_group(user_id, group_name) elif cmd == 'get_sessions': start_key = request.POST.get('start_key', None) result = api.get_sessions(start_key=start_key, limit=20) return JsonResponse(result) elif cmd == 'get_users': start_key = request.POST.get('start_key', None) result = api.get_users(start_key=start_key, limit=20) return JsonResponse(result) elif cmd == 'get_user_rows': start_key = request.POST.get('start_key', None) query = request.POST.getlist('query[]', []) if start_key: start_key = json.loads(start_key) result = self._get_user_rows(request, app_id, start_key=start_key, query=query) return JsonResponse(result) elif cmd == 'get_session_rows': start_key = request.POST.get('start_key', None) result = self._get_session_rows(request, app_id, start_key) return JsonResponse(result) elif cmd == 'set_group_session_security_enhancement': group_name = request.POST.get('group_name') enabled = request.POST.get('enabled') if enabled == 'false': enabled = False elif enabled == 'true': enabled = True result = api.set_group_session_security_enhancement( group_name, enabled) return JsonResponse(result) elif cmd == 'get_policy_code': mode = request.POST.get('mode') result = api.get_policy_code('user', mode) print(result) return JsonResponse(result) elif cmd == 'put_policy': mode = request.POST.get('mode') code = request.POST.get('code') result = api.put_policy('user', mode, code) return JsonResponse(result) return redirect(request.path_info) # Redirect back