Ejemplo 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)
Ejemplo n.º 2
0
    def create_desktop(request, desktop_name, private):
        slug = slugify(desktop_name)
        if not slug:
            return Result('fail', message='Invalid characters in desktop name.')

        num_desktops = Desktop.objects.filter(owner=request.user).count()

        if num_desktops >= 10:
            return Result('fail', message="Sorry, there is currently a limit of 10 desktops per user.")

        user = request.user
        uid = u'%s.%s' % (user.username, slug)

        private = private != 'false';

        try:
            desktop = Desktop.objects.create(   owner=user,
                                                name=desktop_name,
                                                slug=slug,
                                                uid=uid,
                                                private=private )
        except IntegrityError:
            return Result('fail', message='You already have a desktop of this name.')

        user_desktops_changed.send(sender=DesktopAPI, username=user.username)

        return Result('success',
                      slug=slug,
                      username=user.username,
                      url=desktop.get_edit_url())
Ejemplo n.º 3
0
 def rename_desktop(request, username, desktop_slug, new_name):
     new_slug = slugify(new_name)
     if Desktop.objects.filter(owner__username=username, slug=new_slug).count():
         return Result('fail', message="Can't rename this desktop, a desktop of that name already exists.")
     if not new_slug:
         return Result('fail', message="Invalid name. Desktop was not renamed.")
     if len(new_slug) >= 30:
         return Result('fail', message="Name is too long (must be less that 30 characters)")
     if request.user.username != username and not request.user.is_staff:
         return Result('nopermission',
                       message="You must be the owner of the desktop to rename it")
     user_desktops_changed.send(sender=DesktopAPI, username=username)
     desktop = Desktop.objects.get(owner__username=username, slug=desktop_slug)
     desktop.name = new_name
     desktop.slug = new_slug
     desktop.save()
     #user_desktops_changed.send(sender=DesktopAPI, username=username)
     return Result(url=desktop.get_absolute_url())
Ejemplo n.º 4
0
    def delete_desktop(request, username, desktop_slug):

        if desktop_slug == 'default':
            return Result('fail',
                          message="Sorry, you may not delete the default desktop.")
        if request.user.username=='test':
            return Result('fail',
                          mesage="Sorry, you can not delete desktops for this account.")

        if request.user.username != username and not request.user.is_staff:
            return Result('nopermission',
                          message="You must be the owner of the desktop to delete it")

        user_desktops_changed.send(sender=DesktopAPI, username=username)
        Desktop.objects.filter(owner=request.user, slug=desktop_slug).delete()
        url = '/' + request.user.username + '/'

        return Result('success', message='Desktop was deleted successfuly.', url=url)
Ejemplo n.º 5
0
 def set_settings(request):
     """ Sets the settings json for the currently logged in user. """
     settings = request.REQUEST.get('settings')
     Profile.objects.filter(user__pk=request.user.pk).update(settings_json=settings)
     user_desktops_changed.send(sender=DesktopAPI, username=request.user.username)