|
20 | 20 | from st2common import log as logging |
21 | 21 | from st2common.exceptions.actionalias import ActionAliasAmbiguityException |
22 | 22 | from st2common.exceptions.apivalidation import ValueValidationException |
23 | | -from st2common.exceptions.rbac import ResourceTypeAccessDeniedError |
24 | 23 | from st2common.models.api.action import ActionAliasAPI |
25 | 24 | from st2common.persistence.actionalias import ActionAlias |
26 | 25 | from st2common.rbac.types import PermissionType |
@@ -75,13 +74,22 @@ def get_one(self, ref_or_id, requester_user): |
75 | 74 | ref_or_id, requester_user=requester_user, permission_type=permission_type |
76 | 75 | ) |
77 | 76 |
|
78 | | - def match(self, action_alias_match_api): |
| 77 | + def match(self, action_alias_match_api, requester_user=None): |
79 | 78 | """ |
80 | 79 | Find a matching action alias. |
81 | 80 |
|
82 | 81 | Handles requests: |
83 | 82 | POST /actionalias/match |
84 | 83 | """ |
| 84 | + |
| 85 | + permission_type = PermissionType.ACTION_ALIAS_MATCH |
| 86 | + rbac_utils = get_rbac_backend().get_utils_class() |
| 87 | + |
| 88 | + rbac_utils.assert_user_has_permission( |
| 89 | + user_db=requester_user, |
| 90 | + permission_type=permission_type, |
| 91 | + ) |
| 92 | + |
85 | 93 | command = action_alias_match_api.command |
86 | 94 |
|
87 | 95 | try: |
@@ -111,32 +119,23 @@ def help(self, filter, pack, limit, offset, **kwargs): |
111 | 119 |
|
112 | 120 | permission_type = PermissionType.ACTION_ALIAS_HELP |
113 | 121 | rbac_utils = get_rbac_backend().get_utils_class() |
114 | | - |
| 122 | + rbac_utils.assert_user_has_permission( |
| 123 | + user_db=requester_user, |
| 124 | + permission_type=permission_type, |
| 125 | + ) |
115 | 126 | try: |
116 | 127 | aliases_resp = super(ActionAliasController, self)._get_all(**kwargs) |
117 | | - aliases = [] |
118 | | - for alias in aliases_resp.json: |
119 | | - try: |
120 | | - rbac_utils.assert_user_has_permission( |
121 | | - user_db=requester_user, |
122 | | - permission_type=permission_type, |
123 | | - ) |
124 | | - aliases.append(ActionAliasAPI(**alias)) |
125 | | - except ResourceTypeAccessDeniedError as exception: |
126 | | - # Permission denied, don't include in output. |
127 | | - pass |
128 | | - except Exception as exception: |
129 | | - LOG.exception(f"Error processing action-alias.") |
| 128 | + aliases = [ActionAliasAPI(**alias) for alias in aliases_resp.json] |
130 | 129 |
|
131 | 130 | return generate_helpstring_result( |
132 | 131 | aliases, filter, pack, int(limit), int(offset) |
133 | 132 | ) |
134 | | - except (TypeError) as e: |
| 133 | + except TypeError as exception_type: |
135 | 134 | LOG.exception( |
136 | 135 | "Helpstring request contains an invalid data type: %s.", |
137 | | - six.text_type(e), |
| 136 | + six.text_type(exception_type), |
138 | 137 | ) |
139 | | - return abort(http_client.BAD_REQUEST, six.text_type(e)) |
| 138 | + return abort(http_client.BAD_REQUEST, six.text_type(exception_type)) |
140 | 139 |
|
141 | 140 | def post(self, action_alias, requester_user): |
142 | 141 | """ |
|
0 commit comments