You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2022/09/01 16:21:35 UTC

[superset] 01/01: merge perms

This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch change-sql-perm-name
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 04e0ae7fd1987c7911bdc6476e0386d1d6207080
Author: hughhhh <hu...@gmail.com>
AuthorDate: Thu Sep 1 09:21:10 2022 -0700

    merge perms
---
 ...dcbe046eaf44_update_sqllab_permissions_views.py | 70 ++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/superset/migrations/versions/2022-08-29_13-28_dcbe046eaf44_update_sqllab_permissions_views.py b/superset/migrations/versions/2022-08-29_13-28_dcbe046eaf44_update_sqllab_permissions_views.py
new file mode 100644
index 0000000000..f124847b41
--- /dev/null
+++ b/superset/migrations/versions/2022-08-29_13-28_dcbe046eaf44_update_sqllab_permissions_views.py
@@ -0,0 +1,70 @@
+# 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.
+"""update_sqllab_permissions_views
+
+Revision ID: dcbe046eaf44
+Revises: 6d3c6f9d665d
+Create Date: 2022-08-29 13:28:29.477253
+
+"""
+from alembic import op
+from sqlalchemy.exc import SQLAlchemyError
+from sqlalchemy.orm import Session
+
+from superset.migrations.shared.security_converge import (
+    add_pvms,
+    get_reversed_new_pvms,
+    get_reversed_pvm_map,
+    migrate_roles,
+    Pvm,
+)
+
+revision = "dcbe046eaf44"
+down_revision = "6d3c6f9d665d"
+
+
+PVM_MAP = {
+    Pvm("menu_access", "SQL Lab"): (Pvm("menu_access", "SQL"),),
+    Pvm("menu_access", "SQL Editor"): (Pvm("menu_access", "SQL Lab"),),
+}
+
+
+def upgrade():
+    bind = op.get_bind()
+    session = Session(bind=bind)
+
+    # Add the new permissions on the migration itself
+    migrate_roles(session, PVM_MAP)
+    try:
+        session.commit()
+    except SQLAlchemyError as ex:
+        print(f"An error occurred while upgrading permissions: {ex}")
+        session.rollback()
+
+
+def downgrade():
+    bind = op.get_bind()
+    session = Session(bind=bind)
+
+    # Add the old permissions on the migration itself
+    add_pvms(session, get_reversed_new_pvms(PVM_MAP))
+    migrate_roles(session, get_reversed_pvm_map(PVM_MAP))
+    try:
+        session.commit()
+    except SQLAlchemyError as ex:
+        print(f"An error occurred while downgrading permissions: {ex}")
+        session.rollback()