From 9486870405a3c60d9fdd1d1f85b4e4b47b84594f Mon Sep 17 00:00:00 2001 From: e Date: Wed, 21 Jul 2021 11:42:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=88=A4=E6=96=AD=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=9A=84=E7=94=A8=E6=88=B7=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=9C=89=E7=9B=B8=E5=85=B3=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javcra/application/serialize/validate.py | 36 ++++++++++++++----- release-assistant/javcra/common/constant.py | 35 ++++++++++++++++++ 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/release-assistant/javcra/application/serialize/validate.py b/release-assistant/javcra/application/serialize/validate.py index c3c63bf..875a45e 100644 --- a/release-assistant/javcra/application/serialize/validate.py +++ b/release-assistant/javcra/application/serialize/validate.py @@ -13,18 +13,38 @@ """ Verification method """ +from javcra.common.constant import PERMISSION_INFO +from javcra.common.constant import COMMAND_DICT -def validate_giteeid(issue_id, gitee_id, person): + +def validate_giteeid(user, comment, personnel_authority: dict, permission_info=PERMISSION_INFO, + command_dict=COMMAND_DICT): """ Description: get the ID with comment permission from the corresponding Gitee Issue Args: - issue_id: the openEuler update version issue ID - gitee_id: the gitee id who comment this issue + user: user id + comment: Related permissions + personnel_authority: personnel authority e.g:{'developer': 'xxx', 'version_manager':'xxx'} + permission_info: permission info + command_dict: command info + Returns: + True or False """ - - permission = True - print("the permission is given to : " + person) - if not permission: - print("Sorry! You do not have the permisson to commit this operation.") + try: + user_id = '' + user_list = command_dict[comment] + for key, value in personnel_authority.items(): + if user in value and key in user_list: + user_id = key + if comment not in permission_info[user_id]: + print("{} has no operation authority:{}, please contact the administrator".format(user, comment)) + return False + except KeyError as error: + print("Error:{}\n Gitee id:{}\n Comment:{}\n Related permissions: {} \n" + "please check and try again".format(error, user, comment, permission_info)) + return False + except AttributeError as error: + print("Personnel Authority:{} \n User id:{} \n Comment:{} \n {}".format(personnel_authority, user, comment, + error)) return False return True diff --git a/release-assistant/javcra/common/constant.py b/release-assistant/javcra/common/constant.py index 2d39ba5..f2d52bb 100644 --- a/release-assistant/javcra/common/constant.py +++ b/release-assistant/javcra/common/constant.py @@ -26,3 +26,38 @@ PERMISSION_DICT = { 'cvrfok': 'security', 'start': 'manager' } +PERMISSION_INFO = { + "version_manager": ["/start-update", "/no-release"], + "security_committee": [ + "/add-cve", + "/delete-cve", + "/cve-ok", + "/check-ok", + "/cvrf-ok", + ], + "developer": [ + "/add-bugfix", + "/delete-bugfix", + "/bugfix-ok", + "/check-status", + "/get-requires", + ], + "tester": ["/test-ok"], + "tc": ["/check-ok"], + "release": ["/check-ok"], + "qa": ["/check-ok"] +} + +COMMAND_DICT = { + "/start-update": ["version_manager"], + "/no-release": ["version_manager"], + "/get-requires": ["developer"], + "/check-status": ["developer"], + "/test-ok": ["tester"], + "/check-ok": ["tc", "qa", "release", "security_committee"], + "/cvrf-ok": ["security_committee"], + "/add-cve": ["security_committee"], + "/add-bugfix": ["developer"], + "/delete-cve": ["security_committee"], + "/delete-bugfix": ["developer"], +} -- Gitee From 12a9912892597f67a6ea56ea22f30bb26794048a Mon Sep 17 00:00:00 2001 From: e Date: Fri, 23 Jul 2021 15:43:24 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=88=A4=E6=96=AD=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=9A=84=E7=94=A8=E6=88=B7=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=9C=89=E7=9B=B8=E5=85=B3=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../javcra/application/serialize/validate.py | 47 ++++++++----------- release-assistant/javcra/common/constant.py | 14 ------ 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/release-assistant/javcra/application/serialize/validate.py b/release-assistant/javcra/application/serialize/validate.py index 875a45e..4813dbd 100644 --- a/release-assistant/javcra/application/serialize/validate.py +++ b/release-assistant/javcra/application/serialize/validate.py @@ -14,37 +14,28 @@ Verification method """ from javcra.common.constant import PERMISSION_INFO -from javcra.common.constant import COMMAND_DICT -def validate_giteeid(user, comment, personnel_authority: dict, permission_info=PERMISSION_INFO, - command_dict=COMMAND_DICT): +def validate_giteeid(giteeid, comment, personnel_authority): """ - Description: get the ID with comment permission from the corresponding Gitee Issue + Personnel permission verification Args: - user: user id - comment: Related permissions - personnel_authority: personnel authority e.g:{'developer': 'xxx', 'version_manager':'xxx'} - permission_info: permission info - command_dict: command info + giteeid: personnel + comment: comment + personnel_authority: personnel authority + Returns: - True or False + True: Authentication is successful + False: Validation fails """ - try: - user_id = '' - user_list = command_dict[comment] - for key, value in personnel_authority.items(): - if user in value and key in user_list: - user_id = key - if comment not in permission_info[user_id]: - print("{} has no operation authority:{}, please contact the administrator".format(user, comment)) - return False - except KeyError as error: - print("Error:{}\n Gitee id:{}\n Comment:{}\n Related permissions: {} \n" - "please check and try again".format(error, user, comment, permission_info)) - return False - except AttributeError as error: - print("Personnel Authority:{} \n User id:{} \n Comment:{} \n {}".format(personnel_authority, user, comment, - error)) - return False - return True + roles = [] + for role, person in personnel_authority.items(): + if giteeid in person: + roles.append(role) + comments = [] + for role in roles: + if comment in PERMISSION_INFO[role]: + comments.append(comment) + if comments: + return True + return False diff --git a/release-assistant/javcra/common/constant.py b/release-assistant/javcra/common/constant.py index f2d52bb..e60f206 100644 --- a/release-assistant/javcra/common/constant.py +++ b/release-assistant/javcra/common/constant.py @@ -47,17 +47,3 @@ PERMISSION_INFO = { "release": ["/check-ok"], "qa": ["/check-ok"] } - -COMMAND_DICT = { - "/start-update": ["version_manager"], - "/no-release": ["version_manager"], - "/get-requires": ["developer"], - "/check-status": ["developer"], - "/test-ok": ["tester"], - "/check-ok": ["tc", "qa", "release", "security_committee"], - "/cvrf-ok": ["security_committee"], - "/add-cve": ["security_committee"], - "/add-bugfix": ["developer"], - "/delete-cve": ["security_committee"], - "/delete-bugfix": ["developer"], -} -- Gitee From 9df1e2f0d68a90b934f8f7c898e9136339eecc05 Mon Sep 17 00:00:00 2001 From: e Date: Tue, 27 Jul 2021 18:39:21 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=88=A4=E6=96=AD=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=9A=84=E7=94=A8=E6=88=B7=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=9C=89=E7=9B=B8=E5=85=B3=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release-assistant/javcra/application/serialize/validate.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/release-assistant/javcra/application/serialize/validate.py b/release-assistant/javcra/application/serialize/validate.py index 4813dbd..219af99 100644 --- a/release-assistant/javcra/application/serialize/validate.py +++ b/release-assistant/javcra/application/serialize/validate.py @@ -32,10 +32,9 @@ def validate_giteeid(giteeid, comment, personnel_authority): for role, person in personnel_authority.items(): if giteeid in person: roles.append(role) - comments = [] for role in roles: if comment in PERMISSION_INFO[role]: - comments.append(comment) - if comments: - return True + return True return False + + -- Gitee From 10a3713176edc5e10dcb25d084e5df897639e21d Mon Sep 17 00:00:00 2001 From: e Date: Wed, 28 Jul 2021 09:33:13 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=88=A4=E6=96=AD=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=9A=84=E7=94=A8=E6=88=B7=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=9C=89=E7=9B=B8=E5=85=B3=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release-assistant/javcra/application/serialize/validate.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/release-assistant/javcra/application/serialize/validate.py b/release-assistant/javcra/application/serialize/validate.py index 219af99..20856af 100644 --- a/release-assistant/javcra/application/serialize/validate.py +++ b/release-assistant/javcra/application/serialize/validate.py @@ -28,12 +28,8 @@ def validate_giteeid(giteeid, comment, personnel_authority): True: Authentication is successful False: Validation fails """ - roles = [] for role, person in personnel_authority.items(): - if giteeid in person: - roles.append(role) - for role in roles: - if comment in PERMISSION_INFO[role]: + if giteeid in person and comment in PERMISSION_INFO[role]: return True return False -- Gitee From 0e4a8ca5381fe63cfddd4b90ebac6610e43b27f9 Mon Sep 17 00:00:00 2001 From: e Date: Wed, 28 Jul 2021 09:38:21 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=88=A4=E6=96=AD=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E7=9A=84=E7=94=A8=E6=88=B7=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E6=9C=89=E7=9B=B8=E5=85=B3=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release-assistant/javcra/application/serialize/validate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/release-assistant/javcra/application/serialize/validate.py b/release-assistant/javcra/application/serialize/validate.py index 20856af..c05bb4e 100644 --- a/release-assistant/javcra/application/serialize/validate.py +++ b/release-assistant/javcra/application/serialize/validate.py @@ -29,7 +29,7 @@ def validate_giteeid(giteeid, comment, personnel_authority): False: Validation fails """ for role, person in personnel_authority.items(): - if giteeid in person and comment in PERMISSION_INFO[role]: + if giteeid in person and comment in PERMISSION_INFO.get(role): return True return False -- Gitee