def _updateExperimenter(request, conn, eid):
    # update experimenter
    controller = BaseExperimenter(conn, eid)
    name_check = conn.checkOmeName(request.REQUEST.get('omename'), controller.experimenter.omeName)
    email_check = conn.checkEmail(request.REQUEST.get('email'), controller.experimenter.email)
    
    initial={'active':True}
    exclude = list()

    if len(request.REQUEST.getlist('other_groups')) > 0:
        others = controller.getSelectedGroups(request.REQUEST.getlist('other_groups'))   
        initial['others'] = others
        initial['default'] = [(g.id, g.name) for g in others]
        exclude.extend([g.id for g in others])

    available = controller.otherGroupsInitialList(exclude)
    initial['available'] = available

    form = ExperimenterForm(initial=initial, data=request.POST.copy(), name_check=name_check, email_check=email_check)

    if form.is_valid():
        omename = form.cleaned_data['omename']
        firstName = form.cleaned_data['first_name']
        middleName = form.cleaned_data['middle_name']
        lastName = form.cleaned_data['last_name']
        email = form.cleaned_data['email']
        institution = form.cleaned_data['institution']
        admin = toBoolean(form.cleaned_data['administrator'])
        active = toBoolean(form.cleaned_data['active'])
        defaultGroup = form.cleaned_data['default_group']
        otherGroups = form.cleaned_data['other_groups']
        controller.updateExperimenter(omename, firstName, lastName, email, admin, active, defaultGroup, otherGroups, middleName, institution)
    else:
        raise Exception(form.errors.as_text())
Example #2
0
def _updateExperimenter(request, conn, eid):
    groups = list(conn.getObjects("ExperimenterGroup"))
    groups.sort(key=lambda x: x.getName().lower())

    experimenter, defaultGroup, otherGroups, isLdapUser, hasAvatar = prepare_experimenter(
        conn, eid)

    name_check = conn.checkOmeName(request.REQUEST.get('omename'),
                                   experimenter.omeName)
    email_check = conn.checkEmail(request.REQUEST.get('email'),
                                  experimenter.email)
    initial = {'active': True, 'groups': otherGroupsInitialList(groups)}

    form = ExperimenterForm(initial=initial,
                            data=request.POST.copy(),
                            name_check=name_check,
                            email_check=email_check)

    if form.is_valid():
        omename = form.cleaned_data['omename']
        firstName = form.cleaned_data['first_name']
        middleName = form.cleaned_data['middle_name']
        lastName = form.cleaned_data['last_name']
        email = form.cleaned_data['email']
        institution = form.cleaned_data['institution']
        admin = toBoolean(form.cleaned_data['administrator'])
        active = toBoolean(form.cleaned_data['active'])
        defaultGroup = form.cleaned_data['default_group']
        otherGroups = form.cleaned_data['other_groups']

        # default group
        for g in groups:
            if long(defaultGroup) == g.id:
                dGroup = g
                break

        listOfOtherGroups = set()
        # rest of groups
        for g in groups:
            for og in otherGroups:
                # remove defaultGroup from otherGroups if contains
                if long(og) == long(dGroup.id):
                    pass
                elif long(og) == g.id:
                    listOfOtherGroups.add(g)

        conn.updateExperimenter(experimenter, omename, firstName, lastName,
                                email, admin, active, dGroup,
                                listOfOtherGroups, middleName, institution)
    else:
        raise Exception(form.errors.as_text())
Example #3
0
    def test_loginFromForm(self):
        params = {
            'username': '******',
            'password': self.root_password,
            'server':self.server_id,
            'ssl':'on'
        }        
        request = fakeRequest(method="post", params=params)
        
        server_id = request.REQUEST.get('server')
        form = LoginForm(data=request.REQUEST.copy())
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            server_id = form.cleaned_data['server']
            is_secure = toBoolean(form.cleaned_data['ssl'])

            connector = Connector(server_id, is_secure)
            conn = connector.create_connection('OMERO.web', username, password)
            if conn is None:
                self.fail('Cannot connect')
            
            conn.seppuku()
            if conn.isConnected() and conn.keepAlive():
                self.fail('Connection was not closed')
            
        else:
            errors = form.errors.as_text()
            self.fail(errors)
Example #4
0
def _updateExperimenter(request, conn, eid):
    groups = list(conn.getObjects("ExperimenterGroup"))
    groups.sort(key=lambda x: x.getName().lower())
    
    experimenter, defaultGroup, otherGroups, isLdapUser, hasAvatar = prepare_experimenter(conn, eid)
    
    name_check = conn.checkOmeName(request.REQUEST.get('omename'), experimenter.omeName)
    email_check = conn.checkEmail(request.REQUEST.get('email'), experimenter.email)
    initial={'active':True, 'groups':otherGroupsInitialList(groups)}
    
    form = ExperimenterForm(initial=initial, data=request.POST.copy(), name_check=name_check, email_check=email_check)
       
    if form.is_valid():
        omename = form.cleaned_data['omename']
        firstName = form.cleaned_data['first_name']
        middleName = form.cleaned_data['middle_name']
        lastName = form.cleaned_data['last_name']
        email = form.cleaned_data['email']
        institution = form.cleaned_data['institution']
        admin = toBoolean(form.cleaned_data['administrator'])
        active = toBoolean(form.cleaned_data['active'])
        defaultGroup = form.cleaned_data['default_group']
        otherGroups = form.cleaned_data['other_groups']
        
        # default group
        for g in groups:
            if long(defaultGroup) == g.id:
                dGroup = g
                break

        listOfOtherGroups = set()
        # rest of groups
        for g in groups:
            for og in otherGroups:
                # remove defaultGroup from otherGroups if contains
                if long(og) == long(dGroup.id):
                    pass
                elif long(og) == g.id:
                    listOfOtherGroups.add(g)

        conn.updateExperimenter(experimenter, omename, firstName, lastName, email, admin, active, dGroup, listOfOtherGroups, middleName, institution)
    else:
        raise Exception(form.errors.as_text())
def _updateGroup(request, conn, gid):
    # update group
    controller = BaseGroup(conn, gid)
    name_check = conn.checkGroupName(request.REQUEST.get('name'), controller.group.name)
    form = GroupForm(initial={'experimenters':controller.experimenters}, data=request.POST.copy(), name_check=name_check)
    if form.is_valid():
        name = form.cleaned_data['name']
        description = form.cleaned_data['description']
        owners = form.cleaned_data['owners']
        permissions = form.cleaned_data['permissions']
        readonly = toBoolean(form.cleaned_data['readonly'])
        controller.updateGroup(name, owners, permissions, readonly, description)
    else:
        raise Exception(form.errors.as_text())            
Example #6
0
    def test_loginFromRequest(self):
        params = {
            'username': '******',
            'password': self.root_password,
            'server':self.server_id,
            'ssl':'on'
        }        
        request = fakeRequest(method="post", path="/webadmin/login", params=params)
        
        server_id = request.REQUEST.get('server')
        username = request.REQUEST.get('username')
        password = request.REQUEST.get('password')
        is_secure = toBoolean(request.REQUEST.get('ssl'))

        connector = Connector(server_id, is_secure)
        conn = connector.create_connection('TEST.webadmin', username, password)
        if conn is None:
            self.fail('Cannot connect')
        
        conn.seppuku()
        if conn.isConnected() and conn.keepAlive():
            self.fail('Connection was not closed')
Example #7
0
    def test_loginFailure(self):
        params = {
            'username': '******',
            'password': '******',
            'server':self.server_id
        }        
        request = fakeRequest(method="post", params=params)
        
        server_id = request.REQUEST.get('server')
        form = LoginForm(data=request.REQUEST.copy())
        if form.is_valid():
            username = form.cleaned_data['username']
            password = form.cleaned_data['password']
            server_id = form.cleaned_data['server']
            is_secure = toBoolean(form.cleaned_data['ssl'])

            connector = Connector(server_id, is_secure)
            conn = connector.create_connection('OMERO.web', username, password)
            if conn is not None:
                self.fail('This user does not exist. Login failure error!')
        
        else:
            errors = form.errors.as_text()
            self.fail(errors)