'User profile page'

@has_access
@expose(u'/profile/<username>/')
def profile(self, username):

    if ((not username) and g.user):
        username = g.user.username
    user = db.session.query(ab_models.User).filter_by(username=username).one()
    roles = {}
    permissions = defaultdict(set)
    for role in user.roles:
        perms = set()
        for perm in role.permissions:
            perms.add((perm.permission.name, perm.view_menu.name))
            if (perm.permission.name in (u'datasource_access', u'database_access')):
                permissions[perm.permission.name].add(perm.view_menu.name)
        roles[role.name] = [[perm.permission.name, perm.view_menu.name] for perm in role.permissions]
    payload = {u'user': {u'username': user.username, u'firstName': user.first_name, u'lastName': user.last_name, u'userId': user.id, u'isActive': user.is_active(), u'createdOn': user.created_on.isoformat(), u'email': user.email, u'roles': roles, u'permissions': permissions}}
    return self.render_template(u'superset/basic.html', title=(user.username + u"'s    profile"), navbar_container=True, entry=u'profile', bootstrap_data=json.dumps(payload, default=utils.json_iso_dttm_ser))
