Пример #1
0
 def test_get_space_user(self):
     space = Space()
     space.save()
     user = User()
     user.save()
     with self.assertRaises(SpaceUser.DoesNotExist): get_space_user(user, space)
     space_user = SpaceUser(user=user, space=space)
     space_user.save()
     self.assertEqual(get_space_user_or_none(user, space), space_user)
Пример #2
0
def index(request):
    """
    homepage
    redirect start space
    """
    try:
        emgibo_space = Space.objects.get(uid='00000000-0000-0000-0000-000000000000')
    except Space.DoesNotExist:
        create_embigo_space()
        emgibo_space = Space.objects.get(uid='00000000-0000-0000-0000-000000000000')
    try:
        get_space_user(request.user, emgibo_space)
    except SpaceUser.DoesNotExist:
        space_user = SpaceUser(
            uid=uuid1(),
            rights=embigo_default_rights(),
            space=emgibo_space,
            user=request.user,
        )
        space_user.save()
    if request.get_full_path() == '/00000000-0000-0000-0000-000000000000/':
        return HttpResponseRedirect("/")
    else:
        return space(request)
Пример #3
0
def space(request, space_id='00000000-0000-0000-0000-000000000000'):
    """
    Display a space

    **Context**
        'space': this space
        'own_spaces': list of login user's spaces
        'other_spaces': list of login user's spaces witch user can see
        'collaborators': list of space's users
        'messages': list of space's messages
        'can_add_message': rights flag
        'can_create_space': rights flag
        'can_edit_space': rights flag
        'can_archive_space': rights flag
        'can_delete_space': rights flag
        'can_add_user:'******'can_edit_user_rights': rights flag

    **Template:**
    :template:`space.html`
    """
    user = request.user
    space = get_object_or_404(Space, pk=space_id)
    if user_see_space(user, space):
        try:
            space_user = get_space_user(user, space)
        except SpaceUser.DoesNotExist:
            if space.is_embigo_space():
                rights = embigo_default_rights()
            else:
                rights = user_default_rights_of_public_space()
            space_user = SpaceUser(uid=uuid1(), rights=rights, space=space, user=user)
            space_user.save()

        children_list = [c for c in space.children.all() if c.is_active()]
        user_spaces = {}
        for c in children_list:
            if user_see_child(user, space_user, c):
                c_user = get_space_user_or_none(user, c)
                user_spaces[c] = [gc for gc in c.children.all() if gc.is_active() and user_see_child(user, c_user, gc)]

        parent_collaborators = []
        if space.parent:
            try:
                parent_user = SpaceUser.objects.get(space=space.parent, user=user)
            except SpaceUser.DoesNotExist:
                parent_user = None
            if parent_user and parent_user.can(SEE_USERS):
                parent_collaborators = SpaceUser.objects.filter(space=space.parent)
                parent_collaborators = [pc for pc in parent_collaborators if
                                        not user_is_space_user(pc.user, space) and space_user.can(SEE_USERS)]

        can_add_message = space_user.can(ADD_MESSAGE)
        can_create_space = space_user.can(CREATE_SPACE)
        can_edit_space = space_user.can(EDIT_SPACE)
        can_archive_space = space_user.can(ARCHIVE_SPACE)
        can_delete_space = space_user.can(DELETE_SPACE)
        can_add_user = space_user.can(ADD_USER)
        can_edit_user_rights = space_user.can(EDIT_RIGHTS)
        can_see_users = space_user.can(SEE_USERS)

        user_key = encrypt(SECRET_KEY_WEBSOCKET, request.session.session_key)

        websocket_ip = urlparse("http://" + request.META["HTTP_HOST"]).hostname
        websocket_server_address = 'ws://' + websocket_ip + ':' + str(WEBSOCKET_PORT) + '/';

        context = {
            'space': space,

            'user_spaces': user_spaces,

            'parent_collaborators': parent_collaborators,

            'can_add_message': can_add_message,
            'can_create_space': can_create_space,
            'can_edit_space': can_edit_space,
            'can_archive_space': can_archive_space,
            'can_delete_space': can_delete_space,
            'can_add_user': can_add_user,
            'can_edit_user_rights': can_edit_user_rights,
            'can_see_users': can_see_users,

            'user_key': user_key,
            'websocket_server_address': websocket_server_address
        }
        return render(request, 'space.html', context)
    else:
        return HttpResponseRedirect("/")