uranusjr commented on a change in pull request #19121:
URL: https://github.com/apache/airflow/pull/19121#discussion_r737025668



##########
File path: airflow/www/fab_security/sqla/models.py
##########
@@ -0,0 +1,206 @@
+# 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.
+
+# This product contains a modified portion of 'Flask App Builder' developed by 
Daniel Vaz Gaspar.
+# (https://github.com/dpgaspar/Flask-AppBuilder).
+# Copyright 2013, Daniel Vaz Gaspar
+
+import datetime
+
+from flask import g
+from flask_appbuilder._compat import as_unicode
+from flask_appbuilder.models.sqla import Model
+from sqlalchemy import (
+    Boolean,
+    Column,
+    DateTime,
+    ForeignKey,
+    Integer,
+    Sequence,
+    String,
+    Table,
+    UniqueConstraint,
+)
+from sqlalchemy.ext.declarative import declared_attr
+from sqlalchemy.orm import backref, relationship
+
+_dont_audit = False

Review comment:
       Is this inherited from FAB? Doesn't seem to be used anywhere.

##########
File path: airflow/www/fab_security/sqla/models.py
##########
@@ -0,0 +1,206 @@
+# 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.
+
+# This product contains a modified portion of 'Flask App Builder' developed by 
Daniel Vaz Gaspar.
+# (https://github.com/dpgaspar/Flask-AppBuilder).
+# Copyright 2013, Daniel Vaz Gaspar
+
+import datetime
+
+from flask import g
+from flask_appbuilder._compat import as_unicode
+from flask_appbuilder.models.sqla import Model
+from sqlalchemy import (
+    Boolean,
+    Column,
+    DateTime,
+    ForeignKey,
+    Integer,
+    Sequence,
+    String,
+    Table,
+    UniqueConstraint,
+)
+from sqlalchemy.ext.declarative import declared_attr
+from sqlalchemy.orm import backref, relationship
+
+_dont_audit = False
+
+
+"""
+Compatibility note: The models in this file are duplicated from Flask 
AppBuilder.
+"""
+
+
+class Action(Model):
+    """Represents permission actions such as `can_read`."""
+
+    __tablename__ = "ab_permission"
+    id = Column(Integer, Sequence("ab_permission_id_seq"), primary_key=True)
+    name = Column(String(100), unique=True, nullable=False)
+
+    def __repr__(self):
+        return self.name
+
+
+class Resource(Model):
+    """Represents permission object such as `User` or `Dag`."""
+
+    __tablename__ = "ab_view_menu"
+    id = Column(Integer, Sequence("ab_view_menu_id_seq"), primary_key=True)
+    name = Column(String(250), unique=True, nullable=False)
+
+    def __eq__(self, other):
+        return (isinstance(other, self.__class__)) and (self.name == 
other.name)
+
+    def __neq__(self, other):
+        return self.name != other.name
+
+    def __repr__(self):
+        return self.name
+
+
+assoc_permission_role = Table(
+    "ab_permission_view_role",
+    Model.metadata,
+    Column("id", Integer, Sequence("ab_permission_view_role_id_seq"), 
primary_key=True),
+    Column("permission_view_id", Integer, ForeignKey("ab_permission_view.id")),
+    Column("role_id", Integer, ForeignKey("ab_role.id")),
+    UniqueConstraint("permission_view_id", "role_id"),
+)
+
+
+class Role(Model):
+    """Represents a user role to which permissions can be assigned."""
+
+    __tablename__ = "ab_role"
+
+    id = Column(Integer, Sequence("ab_role_id_seq"), primary_key=True)
+    name = Column(String(64), unique=True, nullable=False)
+    permissions = relationship("Permission", secondary=assoc_permission_role, 
backref="role")
+
+    def __repr__(self):
+        return self.name
+
+
+class Permission(Model):
+    """Permission pair comprised of an Action + Resource combo."""
+
+    __tablename__ = "ab_permission_view"
+    __table_args__ = (UniqueConstraint("permission_id", "view_menu_id"),)
+    id = Column(Integer, Sequence("ab_permission_view_id_seq"), 
primary_key=True)
+    action_id = Column("permission_id", Integer, 
ForeignKey("ab_permission.id"))
+    action = relationship("Action")
+    resource_id = Column("view_menu_id", Integer, 
ForeignKey("ab_view_menu.id"))
+    resource = relationship("Resource")
+
+    def __repr__(self):
+        return str(self.action).replace("_", " ") + " on " + str(self.resource)
+
+
+assoc_user_role = Table(
+    "ab_user_role",
+    Model.metadata,
+    Column("id", Integer, Sequence("ab_user_role_id_seq"), primary_key=True),
+    Column("user_id", Integer, ForeignKey("ab_user.id")),
+    Column("role_id", Integer, ForeignKey("ab_role.id")),
+    UniqueConstraint("user_id", "role_id"),
+)
+
+
+class User(Model):
+    """Represents an Airflow user which has roles assigned to it."""
+
+    __tablename__ = "ab_user"
+    id = Column(Integer, Sequence("ab_user_id_seq"), primary_key=True)
+    first_name = Column(String(64), nullable=False)
+    last_name = Column(String(64), nullable=False)
+    username = Column(String(64), unique=True, nullable=False)
+    password = Column(String(256))
+    active = Column(Boolean)
+    email = Column(String(64), unique=True, nullable=False)
+    last_login = Column(DateTime)
+    login_count = Column(Integer)
+    fail_login_count = Column(Integer)
+    roles = relationship("Role", secondary=assoc_user_role, backref="user")
+    created_on = Column(DateTime, default=datetime.datetime.now, nullable=True)
+    changed_on = Column(DateTime, default=datetime.datetime.now, nullable=True)
+
+    @declared_attr
+    def created_by_fk(self):
+        return Column(Integer, ForeignKey("ab_user.id"), 
default=self.get_user_id, nullable=True)
+
+    @declared_attr
+    def changed_by_fk(self):
+        return Column(Integer, ForeignKey("ab_user.id"), 
default=self.get_user_id, nullable=True)
+
+    created_by = relationship(
+        "User",
+        backref=backref("created", uselist=True),
+        remote_side=[id],
+        primaryjoin="User.created_by_fk == User.id",
+        uselist=False,
+    )
+    changed_by = relationship(
+        "User",
+        backref=backref("changed", uselist=True),
+        remote_side=[id],
+        primaryjoin="User.changed_by_fk == User.id",
+        uselist=False,
+    )
+
+    @classmethod
+    def get_user_id(cls):
+        try:
+            return g.user.id
+        except Exception:
+            return None
+
+    @property
+    def is_authenticated(self):
+        return True
+
+    @property
+    def is_active(self):
+        return self.active
+
+    @property
+    def is_anonymous(self):
+        return False
+
+    def get_id(self):
+        return as_unicode(self.id)

Review comment:
       Looks like a leftover from Python 2 compatibility. Probably OK to keep 
if we want to minimise deviation from FAB but should be removed otherwise.

##########
File path: airflow/api_connexion/schemas/task_instance_schema.py
##########
@@ -39,7 +39,7 @@ class Meta:
     task_id = auto_field()
     dag_id = auto_field()
     run_id = auto_field(data_key="dag_run_id")
-    execution_date = auto_field()
+    # execution_date = auto_field()

Review comment:
       Is this intended?




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