|
15 | 15 | # You should have received a copy of the GNU Lesser General Public License |
16 | 16 | # along with this program; if not, write to the Free Software Foundation, |
17 | 17 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | | -from sqlalchemy import and_ |
19 | 18 |
|
20 | 19 | from app import db |
21 | | -from app.datamgmt.manage.manage_access_control_db import get_case_effective_access |
| 20 | +from app.datamgmt.manage.manage_access_control_db import get_case_effective_access, \ |
| 21 | + remove_duplicate_user_case_effective_accesses, set_user_case_effective_access |
22 | 22 | from app.datamgmt.manage.manage_access_control_db import check_ua_case_client |
23 | 23 | from app.iris_engine.access_control.iris_user import iris_current_user |
24 | 24 | from app.logger import logger |
25 | 25 | from app.models.authorization import UserCaseAccess |
26 | | -from app.models.authorization import UserCaseEffectiveAccess |
27 | 26 | from app.models.authorization import CaseAccessLevel |
28 | 27 | from app.models.authorization import ac_flag_match_mask |
29 | 28 |
|
@@ -64,28 +63,10 @@ def set_case_effective_access_for_user(user_id, case_id, access_level: int): |
64 | 63 | Set a case access from a user |
65 | 64 | """ |
66 | 65 |
|
67 | | - uac = UserCaseEffectiveAccess.query.where(and_( |
68 | | - UserCaseEffectiveAccess.user_id == user_id, |
69 | | - UserCaseEffectiveAccess.case_id == case_id |
70 | | - )).all() |
71 | | - |
72 | | - if len(uac) > 1: |
| 66 | + if remove_duplicate_user_case_effective_accesses(user_id, case_id): |
73 | 67 | logger.error(f'Multiple access found for user {user_id} and case {case_id}') |
74 | | - for u in uac: |
75 | | - db.session.delete(u) |
76 | | - db.session.commit() |
77 | 68 |
|
78 | | - uac = UserCaseEffectiveAccess() |
79 | | - uac.user_id = user_id |
80 | | - uac.case_id = case_id |
81 | | - uac.access_level = access_level |
82 | | - db.session.add(uac) |
83 | | - |
84 | | - elif len(uac) == 1: |
85 | | - uac = uac[0] |
86 | | - uac.access_level = access_level |
87 | | - |
88 | | - db.session.commit() |
| 69 | + set_user_case_effective_access(access_level, case_id, user_id) |
89 | 70 |
|
90 | 71 |
|
91 | 72 | def ac_fast_check_user_has_case_access(user_id, cid, expected_access_levels: list[CaseAccessLevel]): |
|
0 commit comments