From 182f7acbe434447ff1bc3bd2d8292d09ed3cc079 Mon Sep 17 00:00:00 2001 From: Fawwaz Anugrah Wiradhika Dharmasatya <anugrahdwfawwaz@gmail.com> Date: Thu, 6 Jun 2024 17:10:46 +0700 Subject: [PATCH] feat: handle route annotation with nocheck --- src/lib/FileReader.py | 26 ++++++++++++++++++++++++-- tests/tc1/acl.txt | 1 + tests/tc1/auth.py | 3 ++- tests/tc1/class_views.py | 6 +++--- tests/tc1/views.py | 1 + todo.txt | 29 +++++++++++++++++++++++++++-- 6 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/lib/FileReader.py b/src/lib/FileReader.py index 1db79a0..ac81b2f 100644 --- a/src/lib/FileReader.py +++ b/src/lib/FileReader.py @@ -25,6 +25,7 @@ class FileReader: lines = source_code.readlines() i = 0 while i < len(lines): + is_skipped = False annotation_list = self.have_annotation(lines[i]) annotation = None if len(annotation_list)==0 else annotation_list[0] if(annotation): @@ -33,8 +34,19 @@ class FileReader: # skip fungsi ini # Cari tahu jenis yang di-excempt i+=1 - while re.search("\S*@.+",lines[i]): + while not is_skipped and re.search("\S*@.+",lines[i]): + next_annotations = self.have_annotation(lines[i]) + # print(next_annotations) + for annon in next_annotations: + if "@Routes" in annon: + # Skip fungsi ini + is_skipped = True + break + #TODO handle sisanya i+=1 + if is_skipped: + # print("skip") + continue # Kalau next line nya class, ya class, kalau def yg fungsi, selain itu type nya module curr_node = None if re.search("\S*class +",lines[i]): @@ -69,6 +81,7 @@ class FileReader: # Cari tahu jenis acl nya i+=1 while re.search("\S*@.+",lines[i]): + #TODO handle kalau ketemu yang lain i+=1 if re.search("\S*class +",lines[i]): # ACL nya kelas @@ -100,8 +113,17 @@ class FileReader: additional_context = re.sub(r"[\(\) ]","",match.group(0)).split(",") # Cari tahu jenis rute nya i+=1 - while re.search("\S*@.+",lines[i]): + while not is_skipped and re.search("\S*@.+",lines[i]): + next_annotations = self.have_annotation(lines[i]) + for annon in next_annotations: + if "@NoCheck" in annon: + # Skip fungsi ini + is_skipped = True + break + #TODO handle sisanya i+=1 + if is_skipped: + continue # Kalau next line nya class, ya class, kalau def yg fungsi, selain itu type nya module if re.search("\S*class +",lines[i]): project_info.route_class.append(ElementContext(lines[i].strip().split(" ")[1],'class',file,additional_context)) diff --git a/tests/tc1/acl.txt b/tests/tc1/acl.txt index 13f3317..93943d2 100644 --- a/tests/tc1/acl.txt +++ b/tests/tc1/acl.txt @@ -11,6 +11,7 @@ Views.class_update_note:admin,user Views.class_delete_note:admin,user Views.class_get_note:admin,user Views.class_get_logs: admin +logout: admin,user =====DETAIL===== var:user::var:role; [admin:admin,user:user,none:guest] lib:flask_login::login_required; admin,user \ No newline at end of file diff --git a/tests/tc1/auth.py b/tests/tc1/auth.py index cf67657..2f81ba6 100644 --- a/tests/tc1/auth.py +++ b/tests/tc1/auth.py @@ -2,6 +2,7 @@ from flask import Blueprint, render_template, request, flash, redirect, url_for from .models import User from werkzeug.security import generate_password_hash, check_password_hash from . import db +#@ACL(login_required) from flask_login import login_user, login_required, logout_user, current_user @@ -26,7 +27,7 @@ def login(): return render_template("login.html") - +#@Routes @auth.route('/logout') @login_required def logout(): diff --git a/tests/tc1/class_views.py b/tests/tc1/class_views.py index 8db2977..5af9e22 100644 --- a/tests/tc1/class_views.py +++ b/tests/tc1/class_views.py @@ -5,9 +5,8 @@ from .models import Note,Log from .db import db import json from lib.RoleCheck import RoleCheck -# @Routes -views = Blueprint('views', __name__) +views = Blueprint('views', __name__) class Views(): def __init__(self,a) -> None: self.a = a @@ -26,7 +25,8 @@ class Views(): flash('Note added!', category='success') return render_template("home.html") - +# @NoCheck +# @Routes @views.route('/update', methods=['POST']) @login_required def class_update_note(self): diff --git a/tests/tc1/views.py b/tests/tc1/views.py index ac11e48..fbb3a7d 100644 --- a/tests/tc1/views.py +++ b/tests/tc1/views.py @@ -1,3 +1,4 @@ +# @NoCheck # @Routes from flask import Blueprint, render_template, request, flash, jsonify,abort # @ACL(login_required) diff --git a/todo.txt b/todo.txt index 23c8984..c443f20 100644 --- a/todo.txt +++ b/todo.txt @@ -8,6 +8,31 @@ module: - class > function (V) TODO -- check kalau kelasnya disimpan di variabel (V) -> cuma kalau langsung manggil kelas +- check kalau kelasnya disimpan di variabel (V) -> cuma kalau langsung manggil kelas ( 1 kali assignment, belum transitif) - routes kena nocheck? -- default gak cek __init__ (V) \ No newline at end of file +routes -> nocheck +function (V) +class: (V) + - function (V) +module: (V) + - function (V) + - class (V) + - class > function (V) +nocheck -> routes +function (V) +class:(V) + - function (V) +module: (V) + - function (V) + - class (V) + - class > function (V) +- acl sekaligus routes? +routes -> acl +acl -> routes +nocheck -> acl +acl -> nocheck +routes -> routes +nocheck -> nocheck +acl -> acl +- default gak cek __init__ (V) +- routes dalam routes (module -> function) \ No newline at end of file -- GitLab