Reformat files and run lint
Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar> Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
parent
afa3dd8ed8
commit
2c0c5b49bf
|
@ -80,7 +80,7 @@ sh run.sh -a
|
||||||
Por último, debe levantar el frontend (usará el puerto 3000) mediante:
|
Por último, debe levantar el frontend (usará el puerto 3000) mediante:
|
||||||
|
|
||||||
```
|
```
|
||||||
h run.sh -f
|
sh run.sh -f
|
||||||
```
|
```
|
||||||
|
|
||||||
## Documentación de la API
|
## Documentación de la API
|
||||||
|
|
|
@ -3,7 +3,7 @@ import json
|
||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends
|
||||||
from fastapi.responses import JSONResponse
|
from fastapi.responses import JSONResponse
|
||||||
|
|
||||||
from bsition.api.models.document import Document, DocumentUpdate, Access
|
from bsition.api.models.document import Access, Document, DocumentUpdate
|
||||||
from bsition.api.utils.security import get_current_user
|
from bsition.api.utils.security import get_current_user
|
||||||
from bsition.backend.elastic import search as elastic
|
from bsition.backend.elastic import search as elastic
|
||||||
from bsition.backend.mongo import documents as mongo
|
from bsition.backend.mongo import documents as mongo
|
||||||
|
@ -14,13 +14,17 @@ router = APIRouter()
|
||||||
|
|
||||||
@router.post("")
|
@router.post("")
|
||||||
def create(aux: Document, user: tuple = Depends(get_current_user)):
|
def create(aux: Document, user: tuple = Depends(get_current_user)):
|
||||||
doc_id = mongo.create_document({
|
doc_id = mongo.create_document(
|
||||||
|
{
|
||||||
"name": aux.name,
|
"name": aux.name,
|
||||||
"owner": user[0],
|
"owner": user[0],
|
||||||
"data": aux.data if aux.data is not None else ""
|
"data": aux.data if aux.data is not None else "",
|
||||||
})
|
}
|
||||||
|
)
|
||||||
postgres.give_access_doc(user[0], doc_id, 1)
|
postgres.give_access_doc(user[0], doc_id, 1)
|
||||||
return JSONResponse(content={"detail": "Document created", "id": doc_id}, status_code=201)
|
return JSONResponse(
|
||||||
|
content={"detail": "Document created", "id": doc_id}, status_code=201
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@router.get("")
|
@router.get("")
|
||||||
|
@ -63,7 +67,9 @@ def give_access(id: str, access_type: Access, user: tuple = Depends(get_current_
|
||||||
|
|
||||||
|
|
||||||
@router.put("/{id}/access")
|
@router.put("/{id}/access")
|
||||||
def update_access(id: str, access_type: Access, user: tuple = Depends(get_current_user)):
|
def update_access(
|
||||||
|
id: str, access_type: Access, user: tuple = Depends(get_current_user)
|
||||||
|
):
|
||||||
postgres.give_access_doc(user[0], id, access_type.access_type)
|
postgres.give_access_doc(user[0], id, access_type.access_type)
|
||||||
return JSONResponse(content={"detail": "Access updated"}, status_code=202)
|
return JSONResponse(content={"detail": "Access updated"}, status_code=202)
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@ from bsition.api.models.document import Access
|
||||||
from bsition.api.models.table import Filter, Sort, Table
|
from bsition.api.models.table import Filter, Sort, Table
|
||||||
from bsition.api.utils.security import get_current_user
|
from bsition.api.utils.security import get_current_user
|
||||||
from bsition.backend.mongo import tables as mongo
|
from bsition.backend.mongo import tables as mongo
|
||||||
from bsition.backend.postgres import tables as postgres_t
|
|
||||||
from bsition.backend.postgres import relations as postgres_r
|
from bsition.backend.postgres import relations as postgres_r
|
||||||
|
from bsition.backend.postgres import tables as postgres_t
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
@ -74,7 +74,9 @@ def give_access(id: str, access_type: Access, user: tuple = Depends(get_current_
|
||||||
|
|
||||||
|
|
||||||
@router.put("/{id}/access")
|
@router.put("/{id}/access")
|
||||||
def update_access(id: str, access_type: Access, user: tuple = Depends(get_current_user)):
|
def update_access(
|
||||||
|
id: str, access_type: Access, user: tuple = Depends(get_current_user)
|
||||||
|
):
|
||||||
postgres_r.give_access_table(user[0], id, access_type.access_type)
|
postgres_r.give_access_table(user[0], id, access_type.access_type)
|
||||||
return JSONResponse(content={"detail": "Access updated"}, status_code=202)
|
return JSONResponse(content={"detail": "Access updated"}, status_code=202)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ from bsition.api.utils.jwt import write_token
|
||||||
from bsition.api.utils.password import verify_password
|
from bsition.api.utils.password import verify_password
|
||||||
from bsition.api.utils.security import get_current_user, oauth2_scheme
|
from bsition.api.utils.security import get_current_user, oauth2_scheme
|
||||||
from bsition.backend.postgres.users import get_user_by_username
|
from bsition.backend.postgres.users import get_user_by_username
|
||||||
from bsition.backend.redis.tokens import add_token, remove_token, clean_tokens
|
from bsition.backend.redis.tokens import add_token, clean_tokens, remove_token
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
@ -34,6 +34,8 @@ def login(form: OAuth2PasswordRequestForm = Depends()):
|
||||||
|
|
||||||
|
|
||||||
@router.delete("/token")
|
@router.delete("/token")
|
||||||
def logout(token: str = Depends(oauth2_scheme), user: tuple = Depends(get_current_user)):
|
def logout(
|
||||||
|
token: str = Depends(oauth2_scheme), user: tuple = Depends(get_current_user)
|
||||||
|
):
|
||||||
remove_token(user[1], token)
|
remove_token(user[1], token)
|
||||||
return JSONResponse(content={"detail": "Token deleted."}, status_code=202)
|
return JSONResponse(content={"detail": "Token deleted."}, status_code=202)
|
||||||
|
|
|
@ -15,9 +15,7 @@ def search(index, query, user_id):
|
||||||
"must": [
|
"must": [
|
||||||
{"query_string": {"query": query, "default_field": "data"}},
|
{"query_string": {"query": query, "default_field": "data"}},
|
||||||
],
|
],
|
||||||
"filter": [
|
"filter": [{"terms": {"_id": acc_doc}}],
|
||||||
{"terms": {"_id": acc_doc}}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
highlight={"fields": {"data": {}}},
|
highlight={"fields": {"data": {}}},
|
||||||
|
@ -29,11 +27,11 @@ def search(index, query, user_id):
|
||||||
# str(hit["highlight"]) + " ---- " + "%(name)s: %(data)s" % hit["_source"]
|
# str(hit["highlight"]) + " ---- " + "%(name)s: %(data)s" % hit["_source"]
|
||||||
# str(hit["highlight"]) + " ---- " + "%(name)s: %(data)s" % hit["_source"]
|
# str(hit["highlight"]) + " ---- " + "%(name)s: %(data)s" % hit["_source"]
|
||||||
{
|
{
|
||||||
"id": hit['_id'],
|
"id": hit["_id"],
|
||||||
"name": hit['_source']["name"],
|
"name": hit["_source"]["name"],
|
||||||
"highlight": str(hit["highlight"]["data"])
|
"highlight": str(hit["highlight"]["data"]),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
print(hit['_id'], hit['_source'])
|
print(hit["_id"], hit["_source"])
|
||||||
|
|
||||||
return hits
|
return hits
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
|
|
||||||
from bsition.backend.elastic import utils as elastic
|
from bsition.backend.elastic import utils as elastic
|
||||||
from bsition.backend.postgres import relations as postgres
|
|
||||||
from bsition.backend.mongo.utils import get_database
|
from bsition.backend.mongo.utils import get_database
|
||||||
|
from bsition.backend.postgres import relations as postgres
|
||||||
|
|
||||||
|
|
||||||
def get_documents(user_id):
|
def get_documents(user_id):
|
||||||
|
@ -22,7 +22,7 @@ def get_documents(user_id):
|
||||||
"access": 1,
|
"access": 1,
|
||||||
"owner": 1,
|
"owner": 1,
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
return list(docs_coll.aggregate(pipeline))
|
return list(docs_coll.aggregate(pipeline))
|
||||||
|
|
||||||
|
|
|
@ -118,9 +118,7 @@ def is_public(doc_id):
|
||||||
conn = get_connection()
|
conn = get_connection()
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute(
|
cur.execute(
|
||||||
sql.SQL(
|
sql.SQL("SELECT doc_id FROM public_docs WHERE doc_id = {doc_id}").format(
|
||||||
"SELECT doc_id FROM public_docs WHERE doc_id = {doc_id}"
|
|
||||||
).format(
|
|
||||||
doc_id=sql.Literal(doc_id),
|
doc_id=sql.Literal(doc_id),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -21,8 +21,6 @@ def remove_token(username, token):
|
||||||
client.zrem(username, token)
|
client.zrem(username, token)
|
||||||
|
|
||||||
|
|
||||||
# Puede correr en un cron o, por ejemplo, cada vez que el usuario hace login (o logout)
|
|
||||||
|
|
||||||
def clean_tokens(username):
|
def clean_tokens(username):
|
||||||
client = get_client()
|
client = get_client()
|
||||||
client.zremrangebyscore(username, -inf, int(time.time()))
|
client.zremrangebyscore(username, -inf, int(time.time()))
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"extends": "next/core-web-vitals"
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -3,6 +3,7 @@
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"lint": "next lint",
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start"
|
"start": "next start"
|
||||||
|
@ -19,6 +20,8 @@
|
||||||
"@types/node": "^17.0.21",
|
"@types/node": "^17.0.21",
|
||||||
"@types/react": "^17.0.39",
|
"@types/react": "^17.0.39",
|
||||||
"autoprefixer": "^10.4.2",
|
"autoprefixer": "^10.4.2",
|
||||||
|
"eslint": "8.30.0",
|
||||||
|
"eslint-config-next": "13.0.7",
|
||||||
"postcss": "^8.4.7",
|
"postcss": "^8.4.7",
|
||||||
"postcss-import": "^14.0.2",
|
"postcss-import": "^14.0.2",
|
||||||
"tailwindcss": "^3.0.23",
|
"tailwindcss": "^3.0.23",
|
||||||
|
|
|
@ -90,8 +90,7 @@ const Sidebar = () => {
|
||||||
if (!activeMenu || !menu || menu === "undefined") {
|
if (!activeMenu || !menu || menu === "undefined") {
|
||||||
if (!router.query || !router.query.id) {
|
if (!router.query || !router.query.id) {
|
||||||
return classNames("flex items-center cursor-pointer hover:bg-light-lighter rounded w-full overflow-hidden whitespace-nowrap");
|
return classNames("flex items-center cursor-pointer hover:bg-light-lighter rounded w-full overflow-hidden whitespace-nowrap");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return classNames(
|
return classNames(
|
||||||
"flex items-center cursor-pointer hover:bg-light-lighter rounded w-full overflow-hidden whitespace-nowrap",
|
"flex items-center cursor-pointer hover:bg-light-lighter rounded w-full overflow-hidden whitespace-nowrap",
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,13 +39,17 @@ export default function CreateDocument() {
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<div className="flex items-center justify-center w-full h-full">
|
<div className="flex items-center justify-center w-full h-full">
|
||||||
<form onSubmit={handleSubmit} className="flex items-center justify-center align-center w-full h-full login-form" style={{flexDirection: "column"}}>
|
<form onSubmit={handleSubmit}
|
||||||
|
className="flex items-center justify-center align-center w-full h-full login-form"
|
||||||
|
style={{flexDirection: "column"}}>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" id="name" name="name" required placeholder="name"
|
<input type="text" id="name" name="name" required placeholder="name"
|
||||||
style={{border: "1px solid grey", color: "black", padding: "2px 4px"}}/>
|
style={{border: "1px solid grey", color: "black", padding: "2px 4px"}}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" className="rounded bg-pink-600 rounded" style={{border: "1px solid grey", padding: "4px"}}>Create</button>
|
<button type="submit" className="rounded bg-pink-600 rounded"
|
||||||
|
style={{border: "1px solid grey", padding: "4px"}}>Create
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
|
@ -111,14 +111,26 @@ export default function Document() {
|
||||||
openDropdown.classList.remove('show');
|
openDropdown.classList.remove('show');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}}} className="dropbtn"></OptionsIcon>
|
}
|
||||||
|
}
|
||||||
|
}} className="dropbtn"></OptionsIcon>
|
||||||
<div id="myDropdown" className="dropdown-content">
|
<div id="myDropdown" className="dropdown-content">
|
||||||
<Link href={access}>
|
<Link href={access}>
|
||||||
<div className="flex flex-row items-center justify-start align-center menu-opt"><ManageIcon/><span>Manage access</span></div>
|
<div className="flex flex-row items-center justify-start align-center menu-opt">
|
||||||
|
<ManageIcon/><span>Manage access</span></div>
|
||||||
</Link>
|
</Link>
|
||||||
<a href="#"><div className="flex flex-row items-center justify-start align-center menu-opt"><ShareIcon/><span>Share</span></div></a>
|
<a href="#">
|
||||||
<a href="#"><div className="flex flex-row items-center justify-start align-center menu-opt"><LockIcon/><span>Public/private</span></div></a>
|
<div className="flex flex-row items-center justify-start align-center menu-opt"><ShareIcon/><span>Share</span>
|
||||||
<a href="#"><div className="flex flex-row items-center justify-start align-center menu-opt"><DeleteIcon/><span>Delete document</span></div></a>
|
</div>
|
||||||
|
</a>
|
||||||
|
<a href="#">
|
||||||
|
<div className="flex flex-row items-center justify-start align-center menu-opt">
|
||||||
|
<LockIcon/><span>Public/private</span></div>
|
||||||
|
</a>
|
||||||
|
<a href="#">
|
||||||
|
<div className="flex flex-row items-center justify-start align-center menu-opt">
|
||||||
|
<DeleteIcon/><span>Delete document</span></div>
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -100,7 +100,9 @@ export default function Document() {
|
||||||
style={{border: "1px solid grey", color: "black", padding: "2px 4px"}}/>
|
style={{border: "1px solid grey", color: "black", padding: "2px 4px"}}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" className="rounded bg-pink-600 rounded" style={{border: "1px solid grey", padding: "4px"}}>Create</button>
|
<button type="submit" className="rounded bg-pink-600 rounded"
|
||||||
|
style={{border: "1px solid grey", padding: "4px"}}>Create
|
||||||
|
</button>
|
||||||
{/*</form>*/}
|
{/*</form>*/}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
|
|
@ -38,7 +38,9 @@ export default function Login() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-center w-full h-full" style={{marginTop: "30%"}}>
|
<div className="flex items-center justify-center w-full h-full" style={{marginTop: "30%"}}>
|
||||||
<form onSubmit={handleSubmit} className="flex items-center justify-center align-center w-full h-full login-form" style={{flexDirection: "column"}}>
|
<form onSubmit={handleSubmit}
|
||||||
|
className="flex items-center justify-center align-center w-full h-full login-form"
|
||||||
|
style={{flexDirection: "column"}}>
|
||||||
<div>
|
<div>
|
||||||
<input type="text" id="username" name="username" required placeholder="username"
|
<input type="text" id="username" name="username" required placeholder="username"
|
||||||
style={{border: "1px solid grey", color: "black", padding: "2px 4px"}}/>
|
style={{border: "1px solid grey", color: "black", padding: "2px 4px"}}/>
|
||||||
|
@ -48,7 +50,9 @@ export default function Login() {
|
||||||
style={{border: "1px solid grey", color: "black", padding: "2px 4px"}}/>
|
style={{border: "1px solid grey", color: "black", padding: "2px 4px"}}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="submit" className="rounded bg-pink-600 rounded" style={{border: "1px solid grey", padding: "4px"}}>Log in</button>
|
<button type="submit" className="rounded bg-pink-600 rounded"
|
||||||
|
style={{border: "1px solid grey", padding: "4px"}}>Log in
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -61,9 +61,13 @@
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dropdown a:hover {background-color: #ddd;}
|
.dropdown a:hover {
|
||||||
|
background-color: #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
.show {display: block;}
|
.show {
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue