Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/g3w-suite/g3w-admin into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
volterra79 committed Nov 28, 2023
2 parents 5cd8019 + eb21e1c commit 3c89958
Show file tree
Hide file tree
Showing 21 changed files with 894 additions and 66 deletions.
2 changes: 2 additions & 0 deletions g3w-admin/core/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@
# signal send for execute model searches.
execute_search_on_models = django.dispatch.Signal(providing_args=['request', 'search_text'])

# signal to load actions for project layers pages
load_project_layers_actions = django.dispatch.Signal(providing_args=["app_name", "project"])


14 changes: 14 additions & 0 deletions g3w-admin/core/static/css/g3wadmin.css
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,18 @@ a.layer-action {

.recaptcha-registration {
padding-left: 11.5px;
}

.project_layers_action-content > div.row {
font-size: 16px;
margin: -10px;
margin-bottom: 20px;
margin-top: 20px;
}

.project_layers_action-content > div.row > div:first-child {
text-align: right;
}
.project_layers_action-content > div.row > div:last-child {
font-size: 22px;
}
2 changes: 1 addition & 1 deletion g3w-admin/core/static/dist/css/g3wadmin.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion g3w-admin/core/templatetags/g3wadmin_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
from django import template
from django.apps import apps
from django.conf.urls.static import static
from core.signals import load_project_widgets, load_layer_actions
from core.signals import (
load_project_widgets,
load_layer_actions,
load_project_layers_actions
)
from core.models import GroupProjectPanoramic


Expand Down Expand Up @@ -106,6 +110,19 @@ def g3wadmin_layer_actions(layer, app_name, user):

return template_actions

@register.simple_tag()
def g3wadmin_project_layers_actions(project, app_name, user):
"""
Template tag to get actions from load_project_layers_actions signal
"""
actions = load_project_layers_actions.send(user, project=project, app_name=app_name)

template_actions = []
for action in actions:
if actions and action[1]:
template_actions.append(action[1])

return template_actions

@register.filter
def lookup(d, key):
Expand Down
143 changes: 109 additions & 34 deletions g3w-admin/editing/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,61 @@
from usersmanage.utils import get_users_for_object, get_groups_for_object, userHasGroups, get_viewers_for_object
from usersmanage.forms import label_users
from usersmanage.configs import *
from qdjango.models import Layer

from qgis.PyQt.QtCore import QVariant

class ActiveEditingMixin(object):

class ActiveEditingLayerForm(G3WRequestFormMixin, G3WProjectFormMixin, forms.Form):
def _set_viewer_users_choices(self):
"""
Set choices for viewer_users select by permission on project and by user main role
"""

with_anonymous = getattr(settings, 'EDITING_ANONYMOUS', False)
viewers = get_viewers_for_object(self.project, self.request.user, 'view_project', with_anonymous=with_anonymous)

# get Editor Level 1 and Editor level 2 to clear from list
editor_pk = self.project.editor.pk if self.project.editor else None
editor2_pk = self.project.editor2.pk if self.project.editor2 else None

self.fields['viewer_users'].choices = [(v.pk, label_users(v)) for v in viewers
if v.pk not in (editor_pk, editor2_pk)]

def _set_viewer_user_groups_choices(self):
"""
Set choices for viewer_user_groups select by permission on project and by user main role
"""

# add user_groups_viewer choices
user_groups_viewers = get_groups_for_object(self.project, 'view_project', grouprole='viewer')

# for Editor level filter by his groups
if userHasGroups(self.request.user, [G3W_EDITOR1]):
editor1_user_gorups_viewers = get_objects_for_user(self.request.user, 'auth.change_group',
AuthGroup).order_by('name').filter(
grouprole__role='viewer')

user_groups_viewers = list(set(user_groups_viewers).intersection(set(editor1_user_gorups_viewers)))

self.fields['user_groups_viewer'].choices = [(v.pk, v) for v in user_groups_viewers]



class ActiveEditingLayerForm(ActiveEditingMixin, G3WRequestFormMixin, G3WProjectFormMixin, forms.Form):
"""
Form for sinlge layer editing mode activation
"""

active = forms.BooleanField(label=_('Active'), required=False)
scale = forms.IntegerField(label=_('Scale'), required=False, help_text=_('Scale after that editing mode is active'))
viewer_users = forms.MultipleChoiceField(choices=[], label=_('Viewers'), required=False,
help_text=_('Select user with viewer role can do editing on layer'))
user_groups_viewer = forms.MultipleChoiceField(
choices=[], required=False, help_text=_('Select VIEWER groups can do editing on layer'),
choices=[], required=False, help_text=_('Select VIEWER groups can do editing on layer'),
label=_('User viewer groups')
)

add_user_field = forms.ChoiceField(choices=[], label=_('User adding data field'), required=False,
help_text=_('Optional: select layer field to store '
'username that entered the data. '
Expand Down Expand Up @@ -59,7 +100,7 @@ def __init__(self, *args, **kwargs):
self.helper.form_tag = False

layout_args = [
HTML(_('Check on uncheck to attive/deactive editing layer capabilities:')),
HTML(_('Check on uncheck to active/deactive editing layer capabilities:')),
'active'
]

Expand Down Expand Up @@ -90,37 +131,6 @@ def clean_edit_user_field(self):

return self.cleaned_data['edit_user_field']

def _set_viewer_users_choices(self):
"""
Set choices for viewer_users select by permission on project and by user main role
"""

with_anonymous = getattr(settings, 'EDITING_ANONYMOUS', False)
viewers = get_viewers_for_object(self.project, self.request.user, 'view_project', with_anonymous=with_anonymous)

# get Editor Level 1 and Editor level 2 to clear from list
editor_pk = self.project.editor.pk if self.project.editor else None
editor2_pk = self.project.editor2.pk if self.project.editor2 else None

self.fields['viewer_users'].choices = [(v.pk, label_users(v)) for v in viewers
if v.pk not in (editor_pk, editor2_pk)]

def _set_viewer_user_groups_choices(self):
"""
Set choices for viewer_user_groups select by permission on project and by user main role
"""

# add user_groups_viewer choices
user_groups_viewers = get_groups_for_object(self.project, 'view_project', grouprole='viewer')

# for Editor level filter by his groups
if userHasGroups(self.request.user, [G3W_EDITOR1]):
editor1_user_gorups_viewers = get_objects_for_user(self.request.user, 'auth.change_group',
AuthGroup).order_by('name').filter(grouprole__role='viewer')

user_groups_viewers = list(set(user_groups_viewers).intersection(set(editor1_user_gorups_viewers)))

self.fields['user_groups_viewer'].choices = [(v.pk, v) for v in user_groups_viewers]

def _set_add_edit_user_field_choices(self):
"""
Expand All @@ -137,3 +147,68 @@ def _set_add_edit_user_field_choices(self):

self.fields['edit_user_field'].choices = \
self.fields['add_user_field'].choices = [(None, '--------')] + [(f, f) for f in touse]


class ActiveEditingMultiLayerForm(ActiveEditingMixin, G3WRequestFormMixin, G3WProjectFormMixin, forms.Form):
"""
Form for multi layer editing mode activation
"""

layers = forms.MultipleChoiceField(choices=[], label=_('Layers'), required=True,
help_text=_('Select layers on which to activate editing'))

scale = forms.IntegerField(label=_('Scale'), required=False, help_text=_('Scale after that editing mode is active'))

active = forms.BooleanField(label=_('Active'), required=False)
viewer_users = forms.MultipleChoiceField(choices=[], label=_('Viewers'), required=False,
help_text=_('Select user with viewer role can do editing on layer'))
user_groups_viewer = forms.MultipleChoiceField(
choices=[], required=False, help_text=_('Select VIEWER groups can do editing on layer'),
label=_('User viewer groups')
)

def __init__(self, *args, **kwargs):

super().__init__(*args, **kwargs)

# set choices
self._set_layers_choices()
self._set_viewer_users_choices()
self._set_viewer_user_groups_choices()

self.helper = FormHelper(self)
self.helper.form_tag = False

layout_args = [
HTML(_('Check on uncheck to attive/deactive editing layers capabilities:')),
'active'
]

layout_args += [
Field('layers', css_class='select2', style="width:100%;"),
Div(css_class='add_edit_user_fields'),
'scale',
HTML(_('Select viewers with \'view permission\' on project that can edit layer:')),
Field('viewer_users', css_class='select2', style="width:100%;"),
Div(css_class='users_atomic_capabilities'),
Field('user_groups_viewer', css_class='select2', style="width:100%;"),
Div(css_class='user_groups_atomic_capabilities')
]

self.helper.layout = Layout(*layout_args)


def _set_layers_choices(self):
"""
Set choices for layers
"""

project_layers = self.project.layer_set.filter(layer_type__in=(
Layer.TYPES.postgres,
Layer.TYPES.spatialite,
Layer.TYPES.ogr,
Layer.TYPES.mssql,
Layer.TYPES.oracle
))
self.fields['layers'].choices = [(l.pk, l.name) for l in project_layers]

Loading

0 comments on commit 3c89958

Please sign in to comment.