Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ yarn-error.log*
.idea

# payload
/src/payload/payload-types.ts
/src/payload/payload-types.ts

.yarn
2 changes: 2 additions & 0 deletions scripts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PAYLOAD_API_KEY=xxx
PAYLOAD_SLUG_THIRD_PARTY_ACCESS=third-party-access
4 changes: 4 additions & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
python-dotenv==1.2.1
requests==2.32.5
requests-html==0.10.0
lxml_html_clean==0.4.3
67 changes: 67 additions & 0 deletions scripts/verify_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import requests
from dotenv import load_dotenv
from requests_html import HTMLSession
import os

session = HTMLSession()

load_dotenv()

def verify_url_href(url: str, href: str) -> bool:
try:
r = session.get(url)
r.html.render(sleep=1)
return href in r.html.absolute_links
except requests.RequestException as e:
print(f"Error fetching URL {url}: {e}")
return False

if __name__ == "__main__":
params = {
"depth": 0,
"where[verified][equals]": False,
}

authorization_header = f"{os.getenv('PAYLOAD_SLUG_THIRD_PARTY_ACCESS')} API-Key {os.getenv('PAYLOAD_API_KEY')}"

response = requests.get(
"http://localhost:3000/api/declarations",
headers={
"Authorization": authorization_header,
"Content-Type": "application/json",
},
params=params,
)

if response.status_code != 200:
print("Failed to fetch data from the API.")

data = response.json().get('docs', [])

for declaration in data:
url = f"{declaration.get('url')}"
href = f"{declaration.get('url')}/mentions"

print(f"Verifying declaration {declaration.get('id')} with URL: {url} and href: {href}")

if not url or not href:
print(f"Declaration {declaration.get('id')} is missing URL or href.")
continue

is_verified = verify_url_href(url, href)

print(f"Declaration {declaration.get('id')} verification result: {is_verified}")

update_response = requests.patch(
f"http://localhost:3000/api/declarations/{declaration.get('id')}",
headers={
"Authorization": authorization_header,
"Content-Type": "application/json",
},
json={"verified": is_verified},
)

if update_response.status_code == 200:
print(f"Successfully updated declaration {declaration.get('id')} verification status to {is_verified}.")
else:
print(f"Failed to update declaration {declaration.get('id')} verification status.")
1 change: 0 additions & 1 deletion src/payload/collections/Declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ export const Declarations: CollectionConfig = {
name: "access_right",
type: "relationship",
relationTo: "access-rights",
required: true,
},
],
};
28 changes: 28 additions & 0 deletions src/payload/collections/ThirdPartyAccess.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { CollectionConfig } from "payload";

export const ThirdPartyAccess: CollectionConfig = {
slug: "third-party-access",
admin: {
group: "Paramètres",
},
labels: {
singular: {
fr: "Accès tiers",
},
plural: {
fr: "Accès tiers",
},
},
auth: {
useAPIKey: true,
disableLocalStrategy: true,
},
fields: [
{
name: "service_name",
label: { fr: "Nom du service" },
type: "text",
required: true,
},
],
};
2 changes: 2 additions & 0 deletions src/payload/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { Domains } from "./collections/Domain";
import { Entities } from "./collections/Entity";
import { Declarations } from "./collections/Declaration";
import { AccessRights } from "./collections/AccessRight";
import { ThirdPartyAccess } from "./collections/ThirdPartyAccess";

const filename = fileURLToPath(import.meta.url);
const dirname = path.dirname(filename);
Expand All @@ -32,6 +33,7 @@ export default buildConfig({
Entities,
Declarations,
AccessRights,
ThirdPartyAccess,
],
secret: process.env.PAYLOAD_SECRET || "",
db: postgresAdapter({
Expand Down