Esempio n. 1
0
    def set_desktop_setting(request, username, desktop_slug, key, value):

        if request.user.username != username and not request.user.is_staff:
            raise APIError('nopermission',
                           "You aren't the owner of this desktop and can not make changes")

        if request.user.username == 'test':
            return Result('fail', msg="Sorry, you can not change settings for this desktop.")

        if key not in DesktopAPI.VALID_DESKTOP_SETTINGS:
            raise APIError("invalidsetting",
                           "Setting does not exist, or you have no permission")

        value_type = DesktopAPI.VALID_DESKTOP_SETTINGS[key]

        if value_type == bool:
            value = value.lower() in ('1', 'true')

        key = str(key)

        if key == 'private' and desktop_slug == "default":
            return Result( "fail", key=key, value=value,
                           message="Sorry, you can't make your default desktop private")

        if not Desktop.objects.filter(owner__username=username, slug=desktop_slug).update(**{key:value}):
            return Result('fail', key=key, value=value, message="Could not find desktop")

        desktop_changed.send(sender=None, username=username, desktop_slug=desktop_slug)
        user_desktops_changed.send(sender=DesktopAPI, username=username)

        return Result('success', key=key, value=value)
Esempio n. 2
0
 def set_desktop_definition(cls, username, desktop_slug, definition_json):
     """ Sets a desktop definition, invalidates the cache and emits a signal. """
     num_rows = Desktop.objects.filter(owner__username=username, slug=desktop_slug)\
         .update(definition_json=definition_json, date_modified=datetime.now())
     if not num_rows:
         raise APIError('nodesktop', 'No such desktop')
     assert num_rows <= 1, "More than one row set by set_desktop_definition"
     cls.set_desktop_cache(username, desktop_slug, definition_json)
     desktop_changed.send(sender=cls, username=username, desktop_slug=desktop_slug)