sunyuhan1998 commented on code in PR #11210:
URL: https://github.com/apache/gravitino/pull/11210#discussion_r3298039549


##########
clients/client-python/gravitino/dto/authorization/privilege_dto.py:
##########
@@ -0,0 +1,110 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+from dataclasses import dataclass, field
+
+from dataclasses_json import config, dataclass_json
+
+from gravitino.api.authorization.privileges import Privilege
+from gravitino.api.metadata_object import MetadataObject
+
+
+def _encode_privilege_name(name: Privilege.Name) -> str:
+    return name.name.lower()
+
+
+def _decode_privilege_name(val: str) -> Privilege.Name:
+    return Privilege.Name[val.upper()]
+
+
+def _encode_condition(condition: Privilege.Condition) -> str:
+    return condition.value.lower()
+
+
+def _decode_condition(val: str) -> Privilege.Condition:
+    return Privilege.Condition(val.upper())
+
+
+@dataclass_json
+@dataclass
+class PrivilegeDTO(Privilege):
+    """Data transfer object representing a privilege."""
+
+    _name: Privilege.Name = field(
+        metadata=config(
+            field_name="name",
+            encoder=_encode_privilege_name,
+            decoder=_decode_privilege_name,
+        )
+    )
+    _condition: Privilege.Condition = field(
+        metadata=config(
+            field_name="condition",
+            encoder=_encode_condition,
+            decoder=_decode_condition,
+        )
+    )
+
+    def name(self) -> Privilege.Name:
+        return self._name
+
+    def simple_string(self) -> str:
+        return f"{self._condition.value} {self._name.name.lower().replace('_', 
' ')}"
+
+    def condition(self) -> Privilege.Condition:
+        return self._condition
+
+    def can_bind_to(self, obj_type: MetadataObject.Type) -> bool:
+        return True
+

Review Comment:
   Done.`can_bind_to` now delegates to the concrete `Privilege` subclass via 
`Privileges.allow/deny(name).can_bind_to(type)`, matching the Java 
`PrivilegeDTO` behavior.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to