def get_form_kwargs(self): kwargs = super(G3WACLViewMixin, self).get_form_kwargs() kwargs['request'] = self.request # get editor level 1 users editor_user_pk = None editor_users = get_users_for_object(self.object, self.editor_permission, [G3W_EDITOR2, G3W_EDITOR1]) if editor_users: editor_user_pk = editor_users[0].id if self.request.user.is_superuser: kwargs['initial']['editor_user'] = editor_users[0].id # get editor level2 users editor2_user_pk = None editor2_users = get_users_for_object(self.object, self.editor2_permission, [G3W_EDITOR2]) if editor2_users: editor2_user_pk = editor2_users[0].id if self.request.user.is_superuser or userHasGroups(self.request.user, [G3W_EDITOR1]): kwargs['initial']['editor2_user'] = editor2_users[0].id # get viewer users viewers = get_viewers_for_object(self.object, self.request.user, self.viewer_permission) # get only user id and check if user is group or project editor kwargs['initial']['viewer_users'] = [o.id for o in viewers if o.id not in [editor_user_pk, editor2_user_pk]] # get initial editor user_groups group_editors = get_user_groups_for_object(self.object, self.request.user, self.editor2_permission, 'editor') kwargs['initial']['editor_user_groups'] = [o.id for o in group_editors] group_viewers = get_user_groups_for_object(self.object, self.request.user, self.viewer_permission, 'viewer') kwargs['initial']['viewer_user_groups'] = [o.id for o in group_viewers] return kwargs
def get_queryset(self): """ This view should return a list o users groups with view_project permission. """ if 'layer_id' in self.kwargs: # get 'context' GET parameter if is present possible values: [v (view), e (editing), ve (view + editing)] context = self.request.GET.get('context', 'v') # get viewer users layer = Layer.objects.get(pk=self.kwargs['layer_id']) if context == 'e': # get viewer user groups with change_layer grant qs = get_user_groups_for_object(layer, self.request.user, 'change_layer', 'viewer') else: # get viewer user groups with view_project and change_layer qs = get_user_groups_for_object(layer.project, self.request.user, 'view_project', 'viewer') else: qs = None return qs
def get_form_kwargs(self): kwargs = super(ActiveEditingLayerView, self).get_form_kwargs() # get model by app Layer = apps.get_app_config(self.app_name).get_model('layer') self.layer = Layer.objects.get(pk=self.layer_id) # try to find notes config try: self.activated = G3WEditingLayer.objects.get( app_name=self.app_name, layer_id=self.layer_id) kwargs['initial']['active'] = True kwargs['initial']['scale'] = self.activated.scale except: self.activated = None kwargs['initial']['active'] = False # get viewer users with_anonymous = getattr(settings, 'EDITING_ANONYMOUS', False) viewers = get_viewers_for_object(self.layer, self.request.user, 'change_layer', with_anonymous=with_anonymous) editor_pk = self.layer.project.editor.pk if self.layer.project.editor else None self.initial_viewer_users = kwargs['initial']['viewer_users'] = [ int(o.id) for o in viewers if o.id != editor_pk ] group_viewers = get_user_groups_for_object(self.layer, self.request.user, 'change_layer', 'viewer') self.initial_viewer_user_groups = kwargs['initial'][ 'user_groups_viewer'] = [o.id for o in group_viewers] return kwargs
def _set_user_groups_queryset(self): """ Set query set for viewer user groups chosen fields Take Viewer User Groups from Group :return: None """ super(QdjangoProjetForm, self)._set_user_groups_queryset() editor_user_groups = get_user_groups_for_object( self.group, self.request.user, 'view_group', 'editor') self.fields['editor_user_groups'].queryset = AuthGroup.objects.filter( pk__in=[v.pk for v in editor_user_groups]) viewer_user_groups = get_user_groups_for_object( self.group, self.request.user, 'view_group', 'viewer') self.fields['viewer_user_groups'].queryset = AuthGroup.objects.filter( pk__in=[v.pk for v in viewer_user_groups])
def get_form_kwargs(self): kwargs = super(ActiveEditingLayerView, self).get_form_kwargs() # get model by app Layer = apps.get_app_config(self.app_name).get_model('layer') self.layer = Layer.objects.get(pk=self.layer_id) # Add project for form kwargs['layer'] = self.layer # try to find notes config try: self.activated = G3WEditingLayer.objects.get( app_name=self.app_name, layer_id=self.layer_id) kwargs['initial']['active'] = True kwargs['initial']['scale'] = self.activated.scale kwargs['initial']['add_user_field'] = self.activated.add_user_field kwargs['initial'][ 'edit_user_field'] = self.activated.edit_user_field except: self.activated = None kwargs['initial']['active'] = False # get viewer users with_anonymous = getattr(settings, 'EDITING_ANONYMOUS', False) viewers = get_viewers_for_object(self.layer, self.request.user, 'change_layer', with_anonymous=with_anonymous) editor_pk = self.layer.project.editor.pk if self.layer.project.editor else None self.initial_viewer_users = kwargs['initial']['viewer_users'] = [ int(o.id) for o in viewers if o.id != editor_pk ] self.initial_atomic_capabilitites['user'][ 'change_layer'] = self.initial_viewer_users group_viewers = get_user_groups_for_object(self.layer, self.request.user, 'change_layer', 'viewer') self.initial_viewer_user_groups = kwargs['initial'][ 'user_groups_viewer'] = [o.id for o in group_viewers] self.initial_atomic_capabilitites['group'][ 'change_layer'] = self.initial_viewer_user_groups # Get atomic editing capabilities for users and user_groups form data self.get_initial_atomic_capabilitites(with_anonymous, editor_pk) if 'data' in kwargs: self.get_atomic_capabilities(kwargs['data']) return kwargs
def get_queryset(self): """ This view should return a list o users groups with editing grant layer on qdjango editing layer id. """ qs = super(EditingLayerAuthGroupInfo, self).get_queryset() if 'editing_layer_id' in self.kwargs: # get viewer users layer = Layer.objects.get(pk=self.kwargs['editing_layer_id']) qs = get_user_groups_for_object(layer, self.request.user, 'change_layer', 'viewer') return qs
def get_queryset(self): """ This view should return a list o users groups with view_project permission. """ if 'layer_id' in self.kwargs: # get viewer users layer = Layer.objects.get(pk=self.kwargs['layer_id']) qs = get_user_groups_for_object(layer.project, self.request.user, 'view_project', 'viewer') else: qs = None return qs
def get_initial_atomic_capabilitites(self, with_anonymous, editor_pk): """Set initial users and user_groups atomic capabilities""" for ap in EDITING_ATOMIC_PERMISSIONS: viewers = get_viewers_for_object(self.layer, self.request.user, ap, with_anonymous=with_anonymous) self.initial_atomic_capabilitites['user'][ap] = [ int(o.id) for o in viewers if o.id != editor_pk ] group_viewers = get_user_groups_for_object(self.layer, self.request.user, ap, 'viewer') self.initial_atomic_capabilitites['group'][ap] = [ o.id for o in group_viewers ]