示例#1
0
文件: api.py 项目: dodopizza/superset
 def get_my_roles(self) -> Response:
     """Get the user roles corresponding to the agent making the request
     ---
     get:
       description: >-
         Returns the user roles corresponding to the agent making the request,
         or returns a 401 error if the user is unauthenticated.
       responses:
         200:
           description: The current user
           content:
             application/json:
               schema:
                 type: object
                 properties:
                   result:
                     $ref: '#/components/schemas/UserResponseSchema'
         401:
           $ref: '#/components/responses/401'
     """
     try:
         if g.user is None or g.user.is_anonymous:
             return self.response_401()
     except NoAuthorizationError:
         return self.response_401()
     user = bootstrap_user_data(g.user, include_perms=True)
     return self.response(200, result=user)
示例#2
0
文件: views.py 项目: ws1993/superset
 def add(self) -> FlaskResponse:
     payload = {
         "common": common_bootstrap_payload(),
         "user": bootstrap_user_data(g.user),
     }
     return self.render_template("superset/add_slice.html",
                                 bootstrap_data=json.dumps(payload))
示例#3
0
 def add(self) -> FlaskResponse:
     datasources = [{
         "value": str(d.id) + "__" + d.type,
         "label": repr(d)
     } for d in ConnectorRegistry.get_all_datasources(db.session)]
     payload = {
         "datasources": sorted(datasources, key=lambda d: d["label"]),
         "common": common_bootstrap_payload(),
         "user": bootstrap_user_data(g.user),
     }
     return self.render_template("superset/add_slice.html",
                                 bootstrap_data=json.dumps(payload))
示例#4
0
 def add(self) -> FlaskResponse:
     datasources = [{
         "value": str(d.id) + "__" + d.type,
         "label": repr(d)
     } for d in security_manager.get_user_datasources()]
     payload = {
         "datasources":
         sorted(
             datasources,
             key=lambda d: d["label"].lower()
             if isinstance(d["label"], str) else "",
         ),
         "common":
         common_bootstrap_payload(),
         "user":
         bootstrap_user_data(g.user),
     }
     return self.render_template("superset/add_slice.html",
                                 bootstrap_data=json.dumps(payload))
示例#5
0
文件: views.py 项目: Sareni/superset
    def add(self) -> FlaskResponse:
        allowed_datasources = []
        datasources = []

        # only if gamma
        is_gamma = False
        logging.debug('-------------------------')
        for role in g.user.roles:
            if str(role) == 'Gamma':
                is_gamma = True
            logging.debug(role.permissions)
            for perm in role.permissions:
                if str(perm).startswith('datasource access on ['):
                    #'datasource access on [DB].[DATASOURCE](id:ID)')
                    data_search = re.search(
                        'datasource access on \[([^\]]+)\]\.\[([^\]]+)\]\(id:([^\)]+)\)',
                        str(perm))
                    if data_search:
                        allowed_datasources.append({
                            "connection":
                            data_search.group(1),
                            "name":
                            data_search.group(2),
                            "id":
                            data_search.group(3)
                        })
        for d in ConnectorRegistry.get_all_datasources(db.session):
            if (is_gamma):
                for a in allowed_datasources:
                    table_name = d.short_data.get("name").split('.')[-1]
                    if table_name == a.get("name") and d.short_data.get(
                            "connection") == a.get("connection") and str(
                                d.short_data.get("id")) == str(a.get("id")):
                        if hasattr(d, 'custom_label'):
                            datasources.append({
                                "value": str(d.id) + "__" + d.type,
                                "label": d.custom_label
                            })
                        else:
                            datasources.append({
                                "value": str(d.id) + "__" + d.type,
                                "label": repr(d)
                            })
            else:
                if hasattr(d, 'custom_label'):
                    datasources.append({
                        "value": str(d.id) + "__" + d.type,
                        "label": d.custom_label
                    })
                else:
                    datasources.append({
                        "value": str(d.id) + "__" + d.type,
                        "label": repr(d)
                    })
        payload = {
            "datasources": sorted(datasources, key=lambda d: d["label"]),
            "common": common_bootstrap_payload(),
            "user": bootstrap_user_data(g.user),
        }
        return self.render_template("superset/add_slice.html",
                                    bootstrap_data=json.dumps(payload))