fixed the bug

pull/141/head
hyh123a 2022-04-21 12:37:56 +08:00
parent 413ce2e012
commit e04b6d2634
3 changed files with 142 additions and 164 deletions

View File

@ -7,17 +7,24 @@ import re
from core.useractivity import user_logger, access_control
import requests
# BASE_API = 'http://172.16.203.116/'
BASE_API = 'http://192.168.1.4/'
BASE_API = 'http://172.16.203.116/'
# BASE_API = 'http://192.168.1.4/'
default_password = '123456'
def login():
def login(acount):
"""
:param acount:
{
"user_name": "admin",
}
:return:
"""
url = BASE_API + "/api/v1.0/login"
payload = json.dumps({
"username": "admin",
"password": "123456",
"type": "account"
"username": acount["user_name"],
"password": default_password,
"type": 'account',
})
headers = {
'Content-Type': 'application/json',
@ -78,36 +85,8 @@ class TicketApplicationListCollection:
resp.status = falcon.HTTP_200
@staticmethod
def on_post(req, resp):
try:
raw_json = req.stream.read().decode('utf-8')
except Exception as ex:
raise falcon.HTTPError(falcon.HTTP_400, title='API.ERROR', description=ex)
"""
{
"user_name": "admin",
}"""
new_values = json.loads(raw_json)
checked_fields = [
{
"name": "user_name",
"type": str
},
]
for field in checked_fields:
_name = field['name']
_type = field['type']
if _name not in new_values.keys() or \
not isinstance(new_values[_name], _type) or \
len(str(new_values[_name])) == 0:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_FIELD' + _name)
payload = new_values
user_name = payload['user_name']
def on_get(req, resp):
user_name = req.get_param('username')
cnx = mysql.connector.connect(**config.loonflow)
cursor = cnx.cursor()
@ -274,6 +253,7 @@ class TicketApplicationItem:
@staticmethod
def on_post(req, resp, id_):
"""Handles POST requests"""
try:
raw_json = req.stream.read().decode('utf-8')
except Exception as ex:
@ -283,7 +263,7 @@ class TicketApplicationItem:
"title": "测试维修",
"long_field": "测试维修",
"transition_id": 29,
"workflow_id": 4
"workflow_id": 4,
}"""
print("id_", id_)
new_values = json.loads(raw_json)
@ -296,8 +276,7 @@ class TicketApplicationItem:
{
"name": "workflow_id",
"type": int
},
}
]
for field in checked_fields:
@ -311,7 +290,9 @@ class TicketApplicationItem:
payload = new_values
session = login()
session = login({
'user_name': req.get_param('username')
})
url = BASE_API + "/api/v1.0/tickets"
headers = {
'Content-Type': 'application/json',
@ -339,36 +320,9 @@ class TicketAgentListCollection:
resp.status = falcon.HTTP_200
@staticmethod
def on_post(req, resp):
def on_get(req, resp):
try:
raw_json = req.stream.read().decode('utf-8')
except Exception as ex:
raise falcon.HTTPError(falcon.HTTP_400, title='API.ERROR', description=ex)
"""
{
"user_name": "admin",
}"""
new_values = json.loads(raw_json)
checked_fields = [
{
"name": "user_name",
"type": str
},
]
for field in checked_fields:
_name = field['name']
_type = field['type']
if _name not in new_values.keys() or \
not isinstance(new_values[_name], _type) or \
len(str(new_values[_name])) == 0:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_FIELD' + _name)
payload = new_values
user_name = payload['user_name']
user_name = req.get_param('username')
cnx = mysql.connector.connect(**config.loonflow)
cursor = cnx.cursor()
@ -676,9 +630,13 @@ class TicketStatusItem:
def on_get(req, resp, id_):
if not id_.isdigit() or int(id_) <= 0:
raise falcon.HTTPError(falcon.HTTP_400, '400 Bad Request')
print(req.get_param('username'))
ticket_id = int(id_)
session = login()
session = login(
{
'user_name': req.get_param('username')
}
)
url = BASE_API + "/api/v1.0/tickets/"+id_+"/flowsteps"
headers = {
'Content-Type': 'application/json',
@ -688,61 +646,61 @@ class TicketStatusItem:
print("content", content)
resp.text = json.dumps(content)
@staticmethod
def on_post(req, resp, id_):
"""Handles POST requests"""
try:
raw_json = req.stream.read().decode('utf-8')
except Exception as ex:
raise falcon.HTTPError(falcon.HTTP_400, title='API.ERROR', description=ex)
"""
{
"title": "测试维修",
"long_field": "测试维修",
"transition_id": 29,
"workflow_id": 4
}"""
print("id_", id_)
new_values = json.loads(raw_json)
checked_fields = [
{
"name": "transition_id",
"type": int
},
{
"name": "workflow_id",
"type": int
},
]
for field in checked_fields:
_name = field['name']
_type = field['type']
if _name not in new_values.keys() or \
not isinstance(new_values[_name], _type) or \
len(str(new_values[_name])) == 0:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_FIELD' + _name)
payload = new_values
session = login()
url = BASE_API + "/api/v1.0/tickets"
headers = {
'Content-Type': 'application/json',
}
resp = session.post(url, headers=headers, data=json.dumps(payload))
content = json.loads(resp.text)
print("content", content)
new_ticket_id = content.get('ticket_id')
print(resp.status_code)
if resp.status_code != 200:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_COOKIE',
description='API.INVALID_STATUS_CODE:' + str(resp.status_code))
resp.status = falcon.HTTP_201
resp.location = '/tickets/' + str(new_ticket_id)
# @staticmethod
# def on_post(req, resp, id_):
# """Handles POST requests"""
# try:
# raw_json = req.stream.read().decode('utf-8')
# except Exception as ex:
# raise falcon.HTTPError(falcon.HTTP_400, title='API.ERROR', description=ex)
# """
# {
# "title": "测试维修",
# "long_field": "测试维修",
# "transition_id": 29,
# "workflow_id": 4
# }"""
# print("id_", id_)
# new_values = json.loads(raw_json)
#
# checked_fields = [
# {
# "name": "transition_id",
# "type": int
# },
# {
# "name": "workflow_id",
# "type": int
# },
#
# ]
#
# for field in checked_fields:
# _name = field['name']
# _type = field['type']
# if _name not in new_values.keys() or \
# not isinstance(new_values[_name], _type) or \
# len(str(new_values[_name])) == 0:
# raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
# description='API.INVALID_FIELD' + _name)
#
# payload = new_values
#
# session = login()
# url = BASE_API + "/api/v1.0/tickets"
# headers = {
# 'Content-Type': 'application/json',
# }
# resp = session.post(url, headers=headers, data=json.dumps(payload))
# content = json.loads(resp.text)
# print("content", content)
# new_ticket_id = content.get('ticket_id')
# print(resp.status_code)
# if resp.status_code != 200:
# raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_COOKIE',
# description='API.INVALID_STATUS_CODE:' + str(resp.status_code))
# resp.status = falcon.HTTP_201
# resp.location = '/tickets/' + str(new_ticket_id)
class TicketFieldItem:
@ -761,7 +719,7 @@ class TicketFieldItem:
raise falcon.HTTPError(falcon.HTTP_400, '400 Bad Request')
ticket_id = int(id_)
session = login()
session = login({'user_name': req.get_param('username')})
url = BASE_API + "api/v1.0/tickets/" + id_
headers = {
'Content-Type': 'application/json',
@ -788,7 +746,11 @@ class TicketTransitionItem:
raise falcon.HTTPError(falcon.HTTP_400, '400 Bad Request')
ticket_id = int(id_)
session = login()
session = login(
{
'user_name': req.get_param('username')
}
)
url = BASE_API + "api/v1.0/tickets/" + id_ + "/transitions"
headers = {
'Content-Type': 'application/json',
@ -828,7 +790,7 @@ class TicketAgentItem:
payload = new_values
ticket_id = int(id_)
session = login()
session = login({'user_name': req.get_param('username')})
url = BASE_API + "api/v1.0/tickets/" + id_
headers = {
'Content-Type': 'application/json',
@ -839,6 +801,36 @@ class TicketAgentItem:
resp.text = json.dumps(content)
class TicketListCollection:
@staticmethod
def __init__():
""""Initializes ContactCollection"""
pass
@staticmethod
def on_options(req, resp):
resp.status = falcon.HTTP_200
@staticmethod
def on_get(req, resp):
session = login(
{
'user_name': req.get_param('username')
}
)
url = BASE_API + "api/v1.0/tickets?category=owner"
headers = {
'Content-Type': 'application/json',
}
get_resp = session.get(url, headers=headers)
print(get_resp)
print(get_resp.text)
content = json.loads(get_resp.text)
print("TicketListCollection content", content)
resp.text = json.dumps(content)
class ContactItem:
@staticmethod
def __init__():

View File

@ -83,7 +83,7 @@ const TicketAggent = ({ setRedirect, setRedirectUrl, t }) => {
useEffect(() => {
let isResponseOK = false;
// Get Ticket Type
fetch(APIBaseURL + '/ticket/types', {
fetch(APIBaseURL + '/ticket/types' + '?username=admin', {
method: 'GET',
headers: {
'Content-type': 'application/json'
@ -115,14 +115,12 @@ const TicketAggent = ({ setRedirect, setRedirectUrl, t }) => {
useEffect(() => {
let isResponseOK = false;
// Get Ticket List
fetch(APIBaseURL + '/ticket/list/agent', {
method: 'POST',
fetch(APIBaseURL + '/ticket/list/agent' + '?username=admin', {
method: 'GET',
headers: {
'Content-type': 'application/json'
},
body: JSON.stringify({
user_name: 'admin'
})
body: null
})
.then(response => {
console.log(response);
@ -168,7 +166,7 @@ const TicketAggent = ({ setRedirect, setRedirectUrl, t }) => {
setTicketId(id);
// Get Ticket Status
let isResponseOK = false;
fetch(APIBaseURL + '/ticket/status/' + id, {
fetch(APIBaseURL + '/ticket/status/' + id + '?username=admin', {
method: 'GET',
headers: {
'Content-type': 'application/json'
@ -211,7 +209,7 @@ const TicketAggent = ({ setRedirect, setRedirectUrl, t }) => {
// Get Ticket Field
isResponseOK = false;
fetch(APIBaseURL + '/ticket/fields/' + id, {
fetch(APIBaseURL + '/ticket/fields/' + id + '?username=admin', {
method: 'GET',
headers: {
'Content-type': 'application/json'
@ -242,7 +240,7 @@ const TicketAggent = ({ setRedirect, setRedirectUrl, t }) => {
// Get Ticket Transition Field
isResponseOK = false;
fetch(APIBaseURL + '/ticket/transition/' + id, {
fetch(APIBaseURL + '/ticket/transition/' + id + '?username=admin', {
method: 'GET',
headers: {
'Content-type': 'application/json'
@ -377,13 +375,13 @@ const TicketAggent = ({ setRedirect, setRedirectUrl, t }) => {
ticketFields.value.field_list.map(item => {
let item_key = item.field_key;
let value = item.field_value;
let temp = {}
let temp = {};
temp[item_key] = value;
setTicketBody({ ...ticketBody, ...temp });
});
let isResponseOK = false;
fetch(APIBaseURL + '/ticket/agent/' + ticketId, {
fetch(APIBaseURL + '/ticket/agent/' + ticketId + '?username=admin', {
method: 'PATCH',
headers: {
'Content-type': 'application/json'

View File

@ -111,14 +111,12 @@ const TicketApplication = ({ setRedirect, setRedirectUrl, t }) => {
useEffect(() => {
let isResponseOK = false;
// Get Ticket List
fetch(APIBaseURL + '/ticket/list/apply', {
method: 'POST',
fetch(APIBaseURL + '/ticket/list/apply' + '?username=admin', {
method: 'GET',
headers: {
'Content-type': 'application/json'
},
body: JSON.stringify({
user_name: 'admin'
})
body: null
})
.then(response => {
console.log(response);
@ -142,16 +140,6 @@ const TicketApplication = ({ setRedirect, setRedirectUrl, t }) => {
const DetailedDataTable = loadable(() => import('../common/DetailedDataTable'));
const nameFormatter = (dataField, { name }) => (
<Link to="#">
<Media tag={Flex} align="center">
<Media body className="ml-2">
<h5 className="mb-0 fs--1">{name}</h5>
</Media>
</Media>
</Link>
);
const actionFormatter = (dataField, { id }) => (
// Control your row with this id
<UncontrolledDropdown>
@ -253,7 +241,7 @@ const TicketApplication = ({ setRedirect, setRedirectUrl, t }) => {
console.log('You apply the ticket!!', selectedTicketType);
let isResponseOK = false;
fetch(APIBaseURL + '/ticket/apply/' + selectedTicketType, {
fetch(APIBaseURL + '/ticket/apply/' + selectedTicketType + '?username=admin', {
method: 'GET',
headers: {
'Content-type': 'application/json'
@ -294,19 +282,19 @@ const TicketApplication = ({ setRedirect, setRedirectUrl, t }) => {
console.log('submit----', ticketApplicationPayload);
let isResponseOK = false;
fetch(APIBaseURL + '/ticket/apply/' + selectedTicketType, {
fetch(APIBaseURL + '/ticket/apply/' + selectedTicketType + '?username=admin', {
method: 'POST',
headers: {
'Content-type': 'application/json'
},
body: JSON.stringify(ticketApplicationPayload)
body: JSON.stringify({ ...ticketApplicationPayload })
})
.then(response => {
console.log(response);
if (response.ok) {
isResponseOK = true;
}
return response.json();
return response.status;
})
.then(json => {
if (isResponseOK) {
@ -328,7 +316,7 @@ const TicketApplication = ({ setRedirect, setRedirectUrl, t }) => {
console.log('View Ticket Status', id);
// Get Ticket Status
let isResponseOK = false;
fetch(APIBaseURL + '/ticket/status/' + id, {
fetch(APIBaseURL + '/ticket/status/' + id + '?username=admin', {
method: 'GET',
headers: {
'Content-type': 'application/json'
@ -377,7 +365,7 @@ const TicketApplication = ({ setRedirect, setRedirectUrl, t }) => {
console.log('View Ticket Record', id);
// Get Ticket Status
let isResponseOK = false;
fetch(APIBaseURL + '/ticket/status/' + id, {
fetch(APIBaseURL + '/ticket/status/' + id + '?username=admin', {
method: 'GET',
headers: {
'Content-type': 'application/json'
@ -504,7 +492,7 @@ const TicketApplication = ({ setRedirect, setRedirectUrl, t }) => {
<ModalBody>
{ticketStatus && (
<Timeline mode="left">
<Timeline.Item key={100} label={""}></Timeline.Item>
<Timeline.Item key={100} label={''} />
{ticketStatus.value
.filter(item => item.state_flow_log_list.length > 0)
.map((item, index) => {
@ -518,7 +506,7 @@ const TicketApplication = ({ setRedirect, setRedirectUrl, t }) => {
</Timeline.Item>
);
})}
<Timeline.Item key={999} label={""}></Timeline.Item>
<Timeline.Item key={999} label={''} />
</Timeline>
)}
</ModalBody>