user_attributes.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. from flask_appbuilder import Model
  18. from sqlalchemy import Column, ForeignKey, Integer
  19. from sqlalchemy.orm import relationship
  20. from superset import security_manager
  21. from superset.models.helpers import AuditMixinNullable
  22. class UserAttribute(Model, AuditMixinNullable):
  23. """
  24. Custom attributes attached to the user.
  25. Extending the user attribute is tricky due to its dependency on the
  26. authentication typew an circular dependencies in Superset. Instead, we use
  27. a custom model for adding attributes.
  28. """
  29. __tablename__ = "user_attribute"
  30. id = Column(Integer, primary_key=True) # pylint: disable=invalid-name
  31. user_id = Column(Integer, ForeignKey("ab_user.id"))
  32. user = relationship(
  33. security_manager.user_model, backref="extra_attributes", foreign_keys=[user_id]
  34. )
  35. welcome_dashboard_id = Column(Integer, ForeignKey("dashboards.id"))
  36. welcome_dashboard = relationship("Dashboard")