Пример #1
0
    def post(self, request, *args, **kwargs):
        self.logger.info('========== Start creating permission ==========')

        name = request.POST.get('name', '')
        description = request.POST.get('description', '')

        params = {
            'name': name,
            'description': description,
            'is_page_level': True
        }

        is_success, status_code, status_message, data = PermissionsClient.create_permission(
            headers=self._get_headers(), params=params, logger=self.logger)

        if is_success:
            messages.success(request, 'Added data successfully')
            self.logger.info('========== End creating permission ==========')
            return redirect('authentications:permissions_list')
        else:
            messages.error(request, status_message)
            self.logger.info(
                '========== End creating permission got error [{}] =========='.
                format(status_message))
            return render(request, self.template_name)
Пример #2
0
    def post(self, request, *args, **kwargs):
        self.logger.info(
            '========== Start update permission entity ==========')
        permission_id = kwargs['permission_id']

        name = request.POST.get('name', '')
        description = request.POST.get('description', '')

        params = {
            'name': name,
            'description': description,
            'is_page_level': True
        }

        is_success, status_code, status_message, data = PermissionsClient.update_permission(
            permission_id=permission_id,
            headers=self._get_headers(),
            params=params,
            logger=self.logger)

        if is_success:
            messages.success(self.request, 'Updated data successfully')
        else:
            messages.error(self.request, status_message)
        self.logger.info('========== End update permission entity ==========')
        return redirect('authentications:permissions_list')
Пример #3
0
    def get_context_data(self, **kwargs):
        context = super(PermissionList, self).get_context_data(**kwargs)

        is_success, status_code, status_message, permissions = PermissionsClient.get_permissions(
            headers=self._get_headers(), params={}, logger=self.logger)

        if is_success:
            page_permissions_list = self._check_permission_list_page()
            self.logger.info(
                "Permissions have [{}] permissions in database".format(
                    len(permissions)))
            context['permissions'] = permissions
            context['page_permissions_list'] = page_permissions_list
        else:
            messages.error(self.request, status_message)
        return context
Пример #4
0
    def get_context_data(self, **kwargs):
        self.logger.info('========== Start get permission entity ==========')
        context = super(PermissionEditView, self).get_context_data(**kwargs)
        permission_id = context['permission_id']

        params = {'id': int(permission_id)}
        self.logger.info(
            "Searching permission with [{}] id".format(permission_id))

        is_success, status_code, status_message, permission_detail = PermissionsClient.get_permission_detail(
            headers=self._get_headers(), params=params, logger=self.logger)

        if is_success:
            context['permission'] = permission_detail
        else:
            messages.error(self.request, status_message)
        self.logger.info('========== End get permission entity ==========')
        return context
Пример #5
0
    def post(self, request, *args, **kwargs):
        self.logger.info(
            '========== Start delete permission entity ==========')
        permission_id = kwargs['permission_id']

        is_success, status_code, status_message = PermissionsClient.delete_permission(
            id=permission_id, headers=self._get_headers(), logger=self.logger)

        if is_success:
            messages.success(request, 'Deleted data successfully')
            self.logger.info(
                '========== End delete permission entity ==========')
            return redirect('authentications:permissions_list')
        else:
            messages.error(request, status_message)
            self.logger.info(
                '========== End delete role entity got error [{}] =========='.
                format(status_message))
            return redirect('authentications:delete_permission',
                            permission_id=permission_id)