|
37 | 37 | "admin": "Administer System", |
38 | 38 | "gateadmin": "Administer Quality Gates", |
39 | 39 | "profileadmin": "Administer Quality Profiles", |
40 | | - "provisioning": "Create Projects", |
41 | 40 | "scan": "Execute Analysis", |
| 41 | + "provisioning": "Create Projects", |
42 | 42 | } |
43 | | -DEVELOPER_GLOBAL_PERMISSIONS = {**COMMUNITY_GLOBAL_PERMISSIONS, **{"applicationcreator": "Create Applications"}} |
44 | | -ENTERPRISE_GLOBAL_PERMISSIONS = {**DEVELOPER_GLOBAL_PERMISSIONS, **{"portfoliocreator": "Create Portfolios"}} |
| 43 | + |
| 44 | +DEVELOPER_GLOBAL_PERMISSIONS = {**COMMUNITY_GLOBAL_PERMISSIONS, "applicationcreator": "Create Applications"} |
| 45 | +ENTERPRISE_GLOBAL_PERMISSIONS = {**DEVELOPER_GLOBAL_PERMISSIONS, "portfoliocreator": "Create Portfolios"} |
45 | 46 |
|
46 | 47 | PROJECT_PERMISSIONS = { |
47 | | - "admin": "Administer Project", |
48 | 48 | "user": "Browse", |
49 | 49 | "codeviewer": "See source code", |
50 | 50 | "issueadmin": "Administer Issues", |
51 | 51 | "securityhotspotadmin": "Create Projects", |
| 52 | + "admin": "Administer Project", |
52 | 53 | "scan": "Execute Analysis", |
53 | 54 | } |
54 | 55 |
|
@@ -81,24 +82,23 @@ def __init__(self, concerned_object: object) -> None: |
81 | 82 | def __str__(self) -> str: |
82 | 83 | return f"permissions of {str(self.concerned_object)}" |
83 | 84 |
|
84 | | - def to_json(self, perm_type: Optional[str] = None, csv: bool = False) -> types.JsonPermissions: |
| 85 | + def to_json(self, perm_type: Optional[str] = None) -> types.JsonPermissions: |
85 | 86 | """Converts a permission object to JSON""" |
86 | | - if not csv: |
87 | | - return self.permissions.get(perm_type, {}) if is_valid(perm_type) else self.permissions |
88 | 87 | perms = [] |
| 88 | + order = PROJECT_PERMISSIONS if self.concerned_object else ENTERPRISE_GLOBAL_PERMISSIONS |
89 | 89 | for p in normalize(perm_type): |
90 | 90 | if p not in self.permissions or len(self.permissions[p]) == 0: |
91 | 91 | continue |
92 | 92 | for k, v in self.permissions.get(p, {}).items(): |
93 | 93 | if not v or len(v) == 0: |
94 | 94 | continue |
95 | | - perms += [{p[:-1]: k, "permissions": encode(v)}] |
| 95 | + perms += [{p[:-1]: k, "permissions": encode(v, order)}] |
96 | 96 | return perms if len(perms) > 0 else None |
97 | 97 |
|
98 | 98 | def export(self) -> types.ObjectJsonRepr: |
99 | 99 | """Exports permissions as JSON""" |
100 | | - perms = {k: v for k, v in self.to_json().items() if len(v) > 0} |
101 | | - return None if len(perms) == 0 else perms |
| 100 | + perms = self.to_json() |
| 101 | + return None if not perms or len(perms) == 0 else perms |
102 | 102 |
|
103 | 103 | @abstractmethod |
104 | 104 | def read(self) -> Permissions: |
@@ -324,11 +324,12 @@ def simplify(perms_dict: dict[str, list[str]]) -> Optional[dict[str, str]]: |
324 | 324 | return {k: encode(v) for k, v in perms_dict.items() if len(v) > 0} |
325 | 325 |
|
326 | 326 |
|
327 | | -def encode(perms_array: dict[str, list[str]]) -> dict[str, str]: |
| 327 | +def encode(perms_array: dict[str, list[str]], order: list[str]) -> dict[str, str]: |
328 | 328 | """ |
329 | 329 | :meta private: |
330 | 330 | """ |
331 | | - return utilities.list_to_csv(perms_array, ", ", check_for_separator=True) |
| 331 | + ordered = utilities.order_list(perms_array, *order) |
| 332 | + return utilities.list_to_csv(ordered, ", ", check_for_separator=True) |
332 | 333 |
|
333 | 334 |
|
334 | 335 | def decode(encoded_perms: dict[str, str]) -> dict[str, list[str]]: |
|
0 commit comments