def api_call(self, request, filters): if 'name__startswith' in filters: # NOTE(garcianavalon) we wan't to filter by username, not name filters['username__startswith'] = filters.pop('name__startswith') filters.update({'enabled': True}) users = fiware_api.keystone.user_list(request, filters=filters) attrs = [ 'id', 'username', 'default_project_id', 'img_medium', ] # add MEDIA_URL to avatar paths or the default avatar json_users = [] for user in users: # Never show users with out username if not getattr(user, 'username', None): continue json_user = idm_utils.obj_to_jsonable_dict(user, attrs) json_user['img_medium'] = idm_utils.get_avatar( user, 'img_medium', idm_utils.DEFAULT_USER_MEDIUM_AVATAR) # Consistency with other elements json_user['name'] = json_user.pop('username') json_users.append(json_user) return json_users
def dispatch(self, request, *args, **kwargs): # Load credentials from the request self.application_credentials = self.load_credentials(request) if not self.application_credentials['application_id']: # if no client_id was found, notify and progress no further messages.error( request, 'OUATH2 ERROR: client_id is missing in query_string') context = { 'next': (reverse('fiware_oauth2_authorize') + '?' + self.request.GET.urlencode()), 'redirect_field_name': auth.REDIRECT_FIELD_NAME, } return auth_views.login( request, extra_context=context, form_class=fiware_auth_forms.LoginWithEmailForm, **kwargs) # Get the application details try: self.application = fiware_api.keystone.application_get( request, self.application_credentials['application_id'], use_idm_account=True) except Exception: msg = ('Unable to retrieve application.') LOG.exception(msg) messages.error(request, (msg)) return redirect('horizon:user_home') if request.user.is_authenticated(): # continue return super(AuthorizeView, self).dispatch(request, *args, **kwargs) else: # redirect to the login page showing some info about the application self.application.avatar = idm_utils.get_avatar( self.application, 'img_medium', idm_utils.DEFAULT_APP_MEDIUM_AVATAR) context = { 'next': (reverse('fiware_oauth2_authorize') + '?' + self.request.GET.urlencode()), 'redirect_field_name': auth.REDIRECT_FIELD_NAME, 'show_application_details': True, 'application': self.application, } LOG.debug('OAUTH2: Login page with consumer details') return auth_views.login( request, extra_context=context, form_class=fiware_auth_forms.LoginWithEmailForm, **kwargs)
def api_call(self, request, filters): if 'name__startswith' in filters: # NOTE(garcianavalon) we wan't to filter by username, not name filters['username__startswith'] = filters.pop('name__startswith') filters.update({'enabled':True}) users = fiware_api.keystone.user_list(request, filters=filters) attrs = [ 'id', 'username', 'default_project_id', 'img_small', ] # add MEDIA_URL to avatar paths or the default avatar json_users = [] for user in users: # Never show users with out username if not getattr(user, 'username', None): continue json_user = idm_utils.obj_to_jsonable_dict(user, attrs) json_user['img_small'] = idm_utils.get_avatar( user, 'img_small', idm_utils.DEFAULT_USER_SMALL_AVATAR) # Consistency with other elements json_user['name'] = json_user.pop('username') json_users.append(json_user) return json_users
def _list_all_owners(self, request, superset_id): all_organizations = fiware_api.keystone.project_list(request) return [(org.id, idm_utils.get_avatar(org, 'img_small', idm_utils.DEFAULT_ORG_SMALL_AVATAR) + '$' + org.name) for org in idm_utils.filter_default(all_organizations)]
def _list_all_owners(self, request, superset_id): all_users = fiware_api.keystone.user_list(request, filters={'enabled':True}) return [ (user.id, idm_utils.get_avatar( user, 'img_small', idm_utils.DEFAULT_USER_SMALL_AVATAR) + '$' + user.username) for user in all_users if getattr(user, 'username', None) ]
def _list_all_owners(self, request, superset_id): all_users = fiware_api.keystone.user_list(request, filters={'enabled': True}) return [(user.id, idm_utils.get_avatar(user, 'img_medium', idm_utils.DEFAULT_USER_MEDIUM_AVATAR) + '$' + user.username) for user in all_users if getattr(user, 'username', None)]
def dispatch(self, request, *args, **kwargs): # Load credentials from the request self.application_credentials = self.load_credentials(request) if not self.application_credentials['application_id']: # if no client_id was found, notify and progress no further messages.error(request, 'OUATH2 ERROR: client_id is missing in query_string') context = { 'next':(reverse('fiware_oauth2_authorize') + '?' + self.request.GET.urlencode()), 'redirect_field_name': auth.REDIRECT_FIELD_NAME, } return auth_views.login( request, extra_context=context, form_class=fiware_auth_forms.LoginWithEmailForm, **kwargs) # Get the application details try: self.application = fiware_api.keystone.application_get( request, self.application_credentials['application_id'], use_idm_account=True) except Exception: msg = ('Unable to retrieve application.') LOG.exception(msg) messages.error(request, (msg)) return redirect('horizon:user_home') if request.user.is_authenticated(): # continue return super(AuthorizeView, self).dispatch(request, *args, **kwargs) else: # redirect to the login page showing some info about the application self.application.avatar = idm_utils.get_avatar( self.application, 'img_medium', idm_utils.DEFAULT_APP_MEDIUM_AVATAR) context = { 'next':(reverse('fiware_oauth2_authorize') + '?' + self.request.GET.urlencode()), 'redirect_field_name': auth.REDIRECT_FIELD_NAME, 'show_application_details':True, 'application':self.application, } LOG.debug('OAUTH2: Login page with consumer details') return auth_views.login( request, extra_context=context, form_class=fiware_auth_forms.LoginWithEmailForm, **kwargs)
class OtherOrganizationsTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_ORG_MEDIUM_AVATAR)) name = tables.Column('name', verbose_name=('Name')) description = tables.Column(lambda obj: getattr(obj, 'description', '')) hide_panel = True pagination_url = 'fiware_complex_server_filters_organizations' empty_message = 'There are no other organizations.' filter_data = { 'organization_role': 'OTHER', } class Meta: name = "other_organizations" verbose_name = ("") row_class = idm_tables.OrganizationClickableRow
class MemberOrganizationsTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_ORG_MEDIUM_AVATAR)) name = tables.Column('name', verbose_name=('Name')) description = tables.Column(lambda obj: getattr(obj, 'description', None)) hide_panel = True pagination_url = 'fiware_complex_server_filters_organizations' empty_message = 'You are not member of any organization.' filter_data = { 'organization_role': getattr(local_settings, "OPENSTACK_KEYSTONE_DEFAULT_ROLE"), } class Meta: name = "member_organizations" verbose_name = ("") row_class = idm_tables.OrganizationClickableRow
def _list_all_owners(self, request, superset_id): # NOTE(garcianavalon) Filtering by project in user_list # filters by default_project_id. # We need to get the role_assignments for the user's # id's and then filter the user list ourselves all_users = fiware_api.keystone.user_list(request, filters={'enabled':True}) project_users_roles = api.keystone.get_project_users_roles( request, project=superset_id) members = [user for user in all_users if user.id in project_users_roles and hasattr(user, 'username')] return [ (user.id, idm_utils.get_avatar(user, 'img_small', idm_utils.DEFAULT_USER_SMALL_AVATAR) + '$' + user.username) for user in members]
class AuthorizedApplicationsTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_APP_MEDIUM_AVATAR)) name = tables.Column('name', verbose_name=('Name')) url = tables.Column(lambda obj: getattr(obj, 'url', '')) hide_panel = True pagination_url = 'fiware_complex_server_filters_applications' empty_message = 'You are not authorized in any application.' filter_data = { 'application_role': 'OTHER', } class Meta: name = "authorized_table" verbose_name = ("") multi_select = False row_class = idm_tables.ApplicationClickableRow
class ProvidingApplicationsTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_APP_MEDIUM_AVATAR)) name = tables.Column('name', verbose_name=('Name')) url = tables.Column(lambda obj: getattr(obj, 'url', '')) hide_panel = True pagination_url = 'fiware_complex_server_filters_applications' empty_message = 'You are not provider of any application.' filter_data = { 'application_role': getattr(local_settings, "FIWARE_PROVIDER_ROLE_ID"), } class Meta: name = "providing_table" verbose_name = ("") multi_select = False row_class = idm_tables.ApplicationClickableRow
def _list_all_owners(self, request, superset_id): # NOTE(garcianavalon) Filtering by project in user_list # filters by default_project_id. # We need to get the role_assignments for the user's # id's and then filter the user list ourselves all_users = fiware_api.keystone.user_list(request, filters={'enabled': True}) project_users_roles = api.keystone.get_project_users_roles( request, project=superset_id) members = [ user for user in all_users if user.id in project_users_roles and hasattr(user, 'username') ] return [(user.id, idm_utils.get_avatar(user, 'img_small', idm_utils.DEFAULT_USER_SMALL_AVATAR) + '$' + user.username) for user in members]
class ApplicationsTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_APP_MEDIUM_AVATAR)) name = tables.Column('name', verbose_name=('Applications')) url = tables.Column(lambda obj: getattr(obj, 'url', '')) empty_message = 'You are not authorized in any application.' pagination_url = 'fiware_complex_server_filters_applications' filter_data = {} def __init__(self, *args, **kwargs): super(ApplicationsTable, self).__init__(*args, **kwargs) self.filter_data.update({'user_id': self.kwargs['user_id']}) class Meta: name = "applications" verbose_name = ("Applications") row_class = idm_tables.ApplicationClickableRow table_actions = (tables.FilterAction, )
class OwnedOrganizationsTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_ORG_MEDIUM_AVATAR)) name = tables.Column('name', verbose_name=('Name')) description = tables.Column(lambda obj: getattr(obj, 'description', '')) switch = tables.Column( lambda obj: idm_utils.get_switch_url(obj, check_switchable=False)) hide_panel = True pagination_url = 'fiware_complex_server_filters_organizations' empty_message = 'You are not owner of any organization.' filter_data = { 'organization_role': getattr(local_settings, "KEYSTONE_OWNER_ROLE"), } class Meta: name = "owned_organizations" verbose_name = ("") row_class = idm_tables.OrganizationClickableRow
class MembersTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_USER_MEDIUM_AVATAR)) name = tables.Column(lambda obj: getattr(obj, 'username', obj.name)) pagination_url = 'fiware_complex_server_filters_users' filter_data = { } def __init__(self, *args, **kwargs): super(MembersTable, self).__init__(*args, **kwargs) self.filter_data.update({'application_id': fiware_api.keystone.get_idm_admin_app(self.request).id}) class Meta: name = "members" verbose_name = ("Authorized Administrators") multi_select = False row_class = idm_tables.UserClickableRow table_actions = (tables.FilterAction, ManageAuthorizedMembersLink,)
class MembersTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_USER_MEDIUM_AVATAR)) username = tables.Column('username', verbose_name=('Members')) pagination_url = 'fiware_complex_server_filters_users' filter_data = {} def __init__(self, *args, **kwargs): super(MembersTable, self).__init__(*args, **kwargs) self.filter_data.update( {'organization_id': self.request.organization.id}) class Meta: name = "members" verbose_name = ("Members") table_actions = (tables.FilterAction, ManageMembersLink, ManageAuthorizedMembersLink) multi_select = False row_class = idm_tables.UserClickableRow
class OrganizationsTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_ORG_MEDIUM_AVATAR)) name = tables.Column('name', verbose_name=('Name')) description = tables.Column(lambda obj: getattr(obj, 'description', ''), verbose_name=('Description')) empty_message = 'You don\'t have any organizations.' pagination_url = 'fiware_complex_server_filters_organizations' filter_data = {} def __init__(self, *args, **kwargs): super(OrganizationsTable, self).__init__(*args, **kwargs) self.filter_data.update({'user_id': self.kwargs['user_id']}) class Meta: name = "organizations" verbose_name = ("Organizations") row_class = idm_tables.OrganizationClickableRow table_actions = (tables.FilterAction, )
def api_call(self, request, filters): applications = idm_utils.filter_default(fiware_api.keystone.application_list(request)) # request, filters=filters)) TODO(garcianavalon) filter support! attrs = [ 'id', 'name', 'img_small', 'url', ] # add MEDIA_URL to avatar paths or the default avatar json_apps = [] for app in applications: json_app = idm_utils.obj_to_jsonable_dict(app, attrs) json_app['img_small'] = idm_utils.get_avatar( json_app, 'img_small', idm_utils.DEFAULT_APP_SMALL_AVATAR) json_apps.append(json_app) return json_apps
class MembersTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_USER_MEDIUM_AVATAR)) username = tables.Column('username', verbose_name=('Members')) view_all_url = 'horizon:idm:organizations:index' pagination_url = 'fiware_complex_server_filters_users' empty_message = 'No members.' filter_data = {} def __init__(self, *args, **kwargs): super(MembersTable, self).__init__(*args, **kwargs) self.filter_data.update( {'organization_id': self.request.organization.id}) class Meta: name = "members" verbose_name = ("Members") table_actions = (ManageMembersLink, ) multi_select = False row_class = idm_tables.UserClickableRow template = 'idm/home/_data_table.html'
class ApplicationsTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_APP_MEDIUM_AVATAR)) name = tables.Column('name', verbose_name=('Name')) url = tables.Column(lambda obj: getattr(obj, 'url', '')) view_all_url = 'horizon:idm:myApplications:index' pagination_url = 'fiware_complex_server_filters_applications' empty_message = 'You are not authorized in any application.' filter_data = {} def __init__(self, *args, **kwargs): super(ApplicationsTable, self).__init__(*args, **kwargs) self.filter_data.update({'user_id': self.request.user.id}) class Meta: name = "applications" verbose_name = ("Applications") table_actions = (RegisterApplication, ) multi_select = False row_class = idm_tables.ApplicationClickableRow template = 'idm/home/_data_table.html'
def api_call(self, request, filters): user_id = filters.pop('user_id', None) organizations = idm_utils.filter_default( fiware_api.keystone.project_list(request, filters=filters, user=user_id)) attrs = [ 'id', 'name', 'img_small', 'description', ] # add MEDIA_URL to avatar paths or the default avatar json_orgs = [] for org in organizations: json_org = idm_utils.obj_to_jsonable_dict(org, attrs) json_org['img_small'] = idm_utils.get_avatar(json_org, 'img_small', idm_utils.DEFAULT_ORG_SMALL_AVATAR) json_orgs.append(json_org) return json_orgs
def api_call(self, request, filters): applications = idm_utils.filter_default( fiware_api.keystone.application_list(request)) # request, filters=filters)) TODO(garcianavalon) filter support! attrs = [ 'id', 'name', 'img_medium', 'url', ] # add MEDIA_URL to avatar paths or the default avatar json_apps = [] for app in applications: json_app = idm_utils.obj_to_jsonable_dict(app, attrs) json_app['img_medium'] = idm_utils.get_avatar( json_app, 'img_medium', idm_utils.DEFAULT_APP_MEDIUM_AVATAR) json_apps.append(json_app) return json_apps
class AuthUsersTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_USER_MEDIUM_AVATAR)) username = tables.Column('username') empty_message = 'This application does not have any authorized users.' pagination_url = 'fiware_complex_server_filters_users' filter_data = {} def __init__(self, *args, **kwargs): super(AuthUsersTable, self).__init__(*args, **kwargs) self.filter_data.update( {'application_id': self.kwargs['application_id']}) class Meta: name = "auth_users" verbose_name = ("Authorized Users") table_actions = ( tables.FilterAction, ManageAuthorizedUsersLink, ) multi_select = False row_class = idm_tables.UserClickableRow
class AuthorizedOrganizationsTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_ORG_MEDIUM_AVATAR)) name = tables.Column('name', verbose_name=('Applications')) description = tables.Column(lambda obj: getattr(obj, 'description', '')) empty_message = 'This application does not have any authorized organizations.' pagination_url = 'fiware_complex_server_filters_organizations' filter_data = {} def __init__(self, *args, **kwargs): super(AuthorizedOrganizationsTable, self).__init__(*args, **kwargs) self.filter_data.update( {'application_id': self.kwargs['application_id']}) class Meta: name = "organizations" verbose_name = ("Authorized Organizations") table_actions = ( tables.FilterAction, ManageAuthorizedOrganizationsLink, ) row_class = idm_tables.OrganizationClickableRow
class OrganizationsTable(tables.DataTable): avatar = tables.Column(lambda obj: idm_utils.get_avatar( obj, 'img_medium', idm_utils.DEFAULT_ORG_MEDIUM_AVATAR)) name = tables.Column('name', verbose_name=('Name')) description = tables.Column(lambda obj: getattr(obj, 'description', '')) switch = tables.Column(lambda obj: idm_utils.get_switch_url(obj)) view_all_url = 'horizon:idm:organizations:index' pagination_url = 'fiware_complex_server_filters_organizations' empty_message = 'You don\'t have any organizations.' filter_data = {} def __init__(self, *args, **kwargs): super(OrganizationsTable, self).__init__(*args, **kwargs) self.filter_data.update({'user_id': self.request.user.id}) class Meta: name = "organizations" verbose_name = 'Organizations' table_actions = (CreateOrganization, ) multi_select = False row_class = idm_tables.OrganizationClickableRow template = 'idm/home/_data_table.html'
def api_call(self, request, filters): user_id = filters.pop('user_id', None) organizations = idm_utils.filter_default( fiware_api.keystone.project_list(request, filters=filters, user=user_id)) attrs = [ 'id', 'name', 'img_medium', 'description', ] # add MEDIA_URL to avatar paths or the default avatar json_orgs = [] for org in organizations: json_org = idm_utils.obj_to_jsonable_dict(org, attrs) json_org['img_medium'] = idm_utils.get_avatar( json_org, 'img_medium', idm_utils.DEFAULT_ORG_MEDIUM_AVATAR) json_orgs.append(json_org) return json_orgs
def _list_all_owners(self, request, superset_id): all_organizations = fiware_api.keystone.project_list(request) return [ (org.id, idm_utils.get_avatar(org, 'img_small', idm_utils.DEFAULT_ORG_SMALL_AVATAR) + '$' + org.name) for org in idm_utils.filter_default(all_organizations)]