ashb closed pull request #4276: [AIRFLOW-1552] Airflow Filter_by_owner not 
working with password_auth
URL: https://github.com/apache/incubator-airflow/pull/4276
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/UPDATING.md b/UPDATING.md
index 88dc78c810..814e2e107d 100644
--- a/UPDATING.md
+++ b/UPDATING.md
@@ -76,6 +76,24 @@ To delete a user:
 airflow users --delete --username jondoe
 ```
 
+### User model changes
+This patch changes the `User.superuser` field from a hardcoded boolean to a 
`Boolean()` database column. `User.superuser` will default to `False`, which 
means that this privilege will have to be granted manually to any users that 
may require it.
+
+For example, open a Python shell and
+```python
+from airflow import models, settings
+
+session = settings.Session()
+users = session.query(models.User).all()  # [admin, regular_user]
+
+users[1].superuser  # False
+
+admin = users[0]
+admin.superuser = True
+session.add(admin)
+session.commit()
+```
+
 ## Airflow 1.10.1
 
 ### StatsD Metrics
diff --git a/airflow/contrib/auth/backends/password_auth.py 
b/airflow/contrib/auth/backends/password_auth.py
index 55f5daf8fd..dcdb1d1225 100644
--- a/airflow/contrib/auth/backends/password_auth.py
+++ b/airflow/contrib/auth/backends/password_auth.py
@@ -95,8 +95,7 @@ def data_profiling(self):
         return True
 
     def is_superuser(self):
-        """Access all the things"""
-        return True
+        return hasattr(self, 'user') and self.user.is_superuser()
 
 
 @login_manager.user_loader
diff --git a/airflow/migrations/versions/41f5f12752f8_add_superuser_field.py 
b/airflow/migrations/versions/41f5f12752f8_add_superuser_field.py
new file mode 100644
index 0000000000..6e02582b7e
--- /dev/null
+++ b/airflow/migrations/versions/41f5f12752f8_add_superuser_field.py
@@ -0,0 +1,42 @@
+# 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.
+
+"""add superuser field
+
+Revision ID: 41f5f12752f8
+Revises: 03bc53e68815
+Create Date: 2018-12-04 15:50:04.456875
+
+"""
+
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = '41f5f12752f8'
+down_revision = '03bc53e68815'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+    op.add_column('users', sa.Column('superuser', sa.Boolean(), default=False))
+
+
+def downgrade():
+    op.drop_column('users', 'superuser')
diff --git a/airflow/models.py b/airflow/models.py
index 1bca27cbc8..a6d0ebbd73 100755
--- a/airflow/models.py
+++ b/airflow/models.py
@@ -601,7 +601,7 @@ class User(Base):
     id = Column(Integer, primary_key=True)
     username = Column(String(ID_LEN), unique=True)
     email = Column(String(500))
-    superuser = False
+    superuser = Column(Boolean(), default=False)
 
     def __repr__(self):
         return self.username


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to