codeant-ai-for-open-source[bot] commented on code in PR #39469:
URL: https://github.com/apache/superset/pull/39469#discussion_r3453903904


##########
superset/views/users/schemas.py:
##########
@@ -51,8 +51,30 @@ class CurrentUserPutSchema(Schema):
         metadata={"description": last_name_description},
         validate=[Length(1, 64)],
     )
-    password = fields.String(
-        required=False,
-        validate=[PasswordComplexityValidator()],
-        metadata={"description": password_description},
+
+
+class CurrentUserPasswordPutSchema(Schema):
+    """Payload for ``PUT /api/v1/me/password`` (AUTH_DB only)."""
+
+    current_password = fields.String(
+        required=True,
+        metadata={"description": current_password_description},
+        validate=[Length(min=1, max=256)],
     )
+    new_password = fields.String(
+        required=True,
+        metadata={"description": new_password_description},
+        validate=[Length(min=1, max=256)],
+    )
+    confirm_password = fields.String(
+        required=True,
+        metadata={"description": confirm_password_description},
+        validate=[Length(min=1, max=256)],
+    )
+
+    @validates_schema
+    def validate_new_password_confirmation(self, data: dict[str, str], 
**kwargs: object) -> None:
+        if data.get("new_password") != data.get("confirm_password"):
+            raise ValidationError(
+                {"confirm_password": [_("Confirmation must match 
new_password.")]}
+            )

Review Comment:
   **Suggestion:** Add a short docstring to the new schema validation method to 
document its purpose and validation behavior. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This is a newly added Python method, and it has no docstring in the final 
file state.
   The custom rule explicitly requires new functions and classes to be 
documented inline, so the suggestion identifies a real violation.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=22b199f7e3ee40689db56e6bbf84771e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=22b199f7e3ee40689db56e6bbf84771e&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/views/users/schemas.py
   **Line:** 75:80
   **Comment:**
        *Custom Rule: Add a short docstring to the new schema validation method 
to document its purpose and validation behavior.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39469&comment_hash=8ed365a5a7b05640a624de8aa08fa8ee60de2a347333de6ca9f9603c41ceaf2d&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39469&comment_hash=8ed365a5a7b05640a624de8aa08fa8ee60de2a347333de6ca9f9603c41ceaf2d&reaction=dislike'>👎</a>



##########
superset/views/users/api.py:
##########
@@ -14,47 +14,107 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+from __future__ import annotations
+
+import functools
+import logging
 from datetime import datetime
-from typing import Any, Dict
+from typing import Any, Callable, Dict
 
-from flask import current_app as app, g, redirect, request, Response
+from flask import current_app as app, g, redirect, request, Response, session
 from flask_appbuilder.api import expose, permission_name, safe
+from flask_appbuilder.const import AUTH_DB
 from flask_appbuilder.security.decorators import protect
 from flask_appbuilder.security.sqla.models import User
+from flask_login import login_user
 from marshmallow import ValidationError
+from sqlalchemy.exc import SQLAlchemyError
 from sqlalchemy.orm.exc import NoResultFound
-from werkzeug.security import generate_password_hash
 
 from superset import is_feature_enabled
 from superset.daos.user import UserDAO
-from superset.extensions import db, event_logger
+from superset.extensions import db, event_logger, security_manager
+from superset.utils.auth_db_password import (
+    get_auth_db_login_rate_limit_string,
+    get_public_auth_db_password_policy,
+    validate_auth_db_password,
+)
+from superset.utils.auth_db_password_hash import (
+    hash_auth_db_password,
+    verify_auth_db_password,
+)
+from superset.utils.auth_session_stamp import (
+    bump_user_session_auth_stamp,
+    clear_flask_login_remember_cookie,
+)
 from superset.utils.slack import get_user_avatar, SlackClientError
 from superset.views.base_api import BaseSupersetApi, requires_json, 
statsd_metrics
-from superset.views.users.schemas import CurrentUserPutSchema, 
UserResponseSchema
+from superset.views.users.schemas import (
+    CurrentUserPasswordPutSchema,
+    CurrentUserPutSchema,
+    UserResponseSchema,
+)
 from superset.views.utils import bootstrap_user_data
 
+logger = logging.getLogger(__name__)
+
 user_response_schema = UserResponseSchema()
 
 
+def _get_client_ip() -> str | None:
+    """Return best-effort client IP from request context."""
+    if request.access_route:
+        return request.access_route[0]
+    return request.remote_addr
+
+
+def _me_password_rate_limit_key() -> str:
+    uid = getattr(getattr(g, "user", None), "id", None)
+    if uid is not None:
+        return f"me_password_uid:{uid}"
+    return _get_client_ip() or "unknown"
+
+
+def _rate_limit_me_password_change(
+    f: Callable[..., Response],
+) -> Callable[..., Response]:
+    """Apply AUTH_DB ``login_rate_limit`` when Flask-Limiter is enabled."""
+
+    @functools.wraps(f)
+    def wrapped(self: CurrentUserRestApi, *args: Any, **kwargs: Any) -> 
Response:
+        if not app.config.get("RATELIMIT_ENABLED", False):
+            return f(self, *args, **kwargs)
+        limiter = getattr(security_manager, "limiter", None)
+        if limiter is None:
+            return f(self, *args, **kwargs)
+        limited_view = limiter.limit(
+            get_auth_db_login_rate_limit_string(),
+            key_func=_me_password_rate_limit_key,
+            methods=["PUT"],
+        )(f)
+        return limited_view(self, *args, **kwargs)

Review Comment:
   **Suggestion:** Add a docstring to this new nested function so its behavior 
and purpose inside the decorator are explicitly documented. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This is a real violation of the docstring rule: the newly added nested 
function
   `wrapped` has no docstring. New Python functions should be documented inline.
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=294c75922b8d48438f7328b3114da34a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=294c75922b8d48438f7328b3114da34a&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/views/users/api.py
   **Line:** 84:95
   **Comment:**
        *Custom Rule: Add a docstring to this new nested function so its 
behavior and purpose inside the decorator are explicitly documented.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39469&comment_hash=ae3d87b0cd51f98b671b4a91e066d8c4e07d59f66ac3bda6565856649fe4dbe4&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39469&comment_hash=ae3d87b0cd51f98b671b4a91e066d8c4e07d59f66ac3bda6565856649fe4dbe4&reaction=dislike'>👎</a>



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to