Ejemplo n.º 1
0
 def can_delete(self, request=None, instance=None, child=None, field=None):
     actor = ActorPermission(
         instance=self,
         request=request or get_current_request(),
     )
     actor.can_delete()
     return actor.has_permission()
Ejemplo n.º 2
0
 def can_m2m_remove(self, request=None, instance=None, child=None, field=None):
     actor = ActorPermission(
             instance=instance,
             request=request or get_current_request(),
             child=child,
             field=field,)
     actor.can_m2m_remove()
     return actor.has_permission()
Ejemplo n.º 3
0
def can_add_relation(parent, child, field):
    """
    Groups:
    - being part of editor_group
    - anything but settings.PROTECTED_GROUPS
    """
    request = get_current_request()
    return parent.can_edit(request, instance=parent, child=child, field=field)
def can_add_relation(parent, child, field):
    """
    Groups:
    - being part of editor_group
    - anything but settings.PROTECTED_GROUPS
    """
    request = get_current_request()
    return parent.can_edit(request, instance=parent, child=child, field=field)
Ejemplo n.º 5
0
 def can_edit(self, request, instance, child=None, field=None):
     actor = ActorPermission(
         instance=instance,
         request=request or get_current_request(),
         child=child,
         field=field,
     )
     actor.can_edit()
     return actor.has_permission()
def send_data(data):
    """
    Send data to Changes-socket, making sure that if this fails, the data is saved
    and we retry next time we receive more data.
    """

    request = get_current_request()
    user = None
    if request and isinstance(request.user, User):
        user = request.user.get_fum_user()

    # Verify format
    CHANGES_FORMAT_KEYS = [
        'operation', 'objectType', 'objectUrl', 'objectId', 'timestamp',
        'attrs'
    ]
    final_data = []
    for k in data:
        tmp = {}
        for j in CHANGES_FORMAT_KEYS:
            tmp[j] = k[j]
        final_data.append(tmp)

    if not settings.CHANGES_SOCKET_ENABLED:
        log.debug('Changes websocket not enabled')
        return final_data

    # Load the data that we previously failed to send
    old_data = []
    try:
        with open(_failed_filepath, 'r') as fd:
            old_data = fd.read()
    except IOError:
        old_data = []
    else:
        if old_data:
            old_data = json.loads(old_data)
        else:
            old_data = []

    # Send old data and new data
    all_data = old_data + final_data
    json_data = json.dumps(all_data, default=_dthandler)
    s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    try:
        s.connect(settings.CHANGES_SOCKET)
        s.send(json_data)
    # If sending fails, adds the new data to previous failures
    except Exception as e:
        log.exception('Got exception on main handler')
        with open(_failed_filepath, 'w') as fd:
            fd.write(json.dumps(all_data, default=_dthandler))
    # If sending succeeds, empty the file
    else:
        with open(_failed_filepath, 'w') as fd:
            fd.write('')
    return final_data
Ejemplo n.º 7
0
def send_data(data):
    """
    Send data to Changes-socket, making sure that if this fails, the data is saved
    and we retry next time we receive more data.
    """

    request = get_current_request()
    user = None
    if request and isinstance(request.user, User):
        user = request.user.get_fum_user()

    # Verify format
    CHANGES_FORMAT_KEYS = ['operation','objectType','objectUrl','objectId','timestamp','attrs']
    final_data = []
    for k in data:
        tmp = {}
        for j in CHANGES_FORMAT_KEYS:
            tmp[j] = k[j]
        final_data.append(tmp)

    if not settings.CHANGES_SOCKET_ENABLED:
        log.debug('Changes websocket not enabled')
        return final_data

    # Load the data that we previously failed to send
    old_data = []
    try:
        with open(_failed_filepath, 'r') as fd:
            old_data = fd.read()
    except IOError:
        old_data = []
    else:
        if old_data:
            old_data = json.loads(old_data)
        else:
            old_data = []

    # Send old data and new data
    all_data = old_data + final_data
    json_data = json.dumps(all_data, default=_dthandler)
    s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    try:
        s.connect(settings.CHANGES_SOCKET)
        s.send(json_data)
    # If sending fails, adds the new data to previous failures
    except Exception as e:
        log.exception('Got exception on main handler')
        with open(_failed_filepath, 'w') as fd:
            fd.write(json.dumps(all_data, default=_dthandler))
    # If sending succeeds, empty the file
    else:
        with open(_failed_filepath, 'w') as fd:
            fd.write('')
    return final_data
 def get_fields(self, *args, **kwargs):
     fields = super(QueryFieldsMixin, self).get_fields(*args, **kwargs)
     request = get_current_request()
     if request.GET.get('fields'):
         fields = {k:v for k,v in fields.iteritems() if k in request.GET.get('fields')} or fields
     return fields
Ejemplo n.º 9
0
 def can_delete(self, request=None, instance=None, child=None, field=None):
     actor = ActorPermission(
             instance=self,
             request=request or get_current_request(),)
     actor.can_delete()
     return actor.has_permission()
Ejemplo n.º 10
0
 def delete(self, *args, **kwargs):
     request = get_current_request()
     if not self.can_delete(request):
         raise ValidationError('Permission denied')
     super(Mother, self).delete(*args, **kwargs)
Ejemplo n.º 11
0
 def clean(self):
     super(Mother, self).clean()
     request = get_current_request()
     if not self.can_edit(request=request, instance=self):
         raise ValidationError('Permission denied')
Ejemplo n.º 12
0
 def get_fields(self, *args, **kwargs):
     fields = super(QueryFieldsMixin, self).get_fields(*args, **kwargs)
     request = get_current_request()
     if request and request.GET.get('fields'):
         fields = {k:v for k,v in fields.iteritems() if k in request.GET.get('fields')} or fields
     return fields
Ejemplo n.º 13
0
def can_remove_relation(parent, child, field):
    request = get_current_request()
    return parent.can_m2m_remove(request, instance=parent, child=child, field=field)
Ejemplo n.º 14
0
 def delete(self, *args, **kwargs):
     request = get_current_request()
     if not self.can_delete(request):
         raise ValidationError('Permission denied')
     super(Mother, self).delete(*args, **kwargs)
Ejemplo n.º 15
0
 def clean(self):
     super(Mother, self).clean()
     request = get_current_request()
     if not self.can_edit(request=request, instance=self):
         raise ValidationError('Permission denied')
def can_remove_relation(parent, child, field):
    request = get_current_request()
    return parent.can_m2m_remove(request,
                                 instance=parent,
                                 child=child,
                                 field=field)