Exemple #1
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        userid = authenticated_userid(request)
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))

        context.title = converted['title']
        context.text = converted['text']
        context.description = extract_description(converted['text'])

        # tags and attachments
        set_tags(context, request, converted['tags'])
        creator = userid
        attachments_folder = context['attachments']
        upload_attachments(converted['attachments'], attachments_folder,
                           creator, request)

        # modified
        context.modified_by = userid
        objectEventNotify(ObjectModifiedEvent(context))

        self.filestore.clear()
        location = resource_url(context, request)
        msg = "?status_message=Page%20edited"
        return HTTPFound(location=location + msg)
Exemple #2
0
    def handle_submit(self, converted):
        request = self.request
        context = self.context
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if converted.get('middle_portlets'):
            middle_portlets = split_lines(converted['middle_portlets'])
        else:
            middle_portlets = []
        if converted.get('right_portlets'):
            right_portlets = split_lines(converted['right_portlets'])
        else:
            right_portlets = []
        context.title = converted['title']
        context.address = converted['address']
        context.city = converted['city']
        context.state = converted['state']
        context.country = converted['country']
        context.zipcode = converted['zipcode']
        context.telephone = converted['telephone']
        context.navigation = clean_html(converted['navigation'])
        context.middle_portlets = middle_portlets
        context.right_portlets = right_portlets
        # *modified* event
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context.__parent__['intranets'], request)
        return HTTPFound(location=location)
Exemple #3
0
 def handle_submit(self, converted):
     context = self.context
     request = self.request
     users = self.users
     userid = self.userid
     user = self.user
     if user is not None:
         login = converted.get('login')
         login_changed = users.get_by_login(login) != user
         if (login_changed and (users.get_by_id(login) is not None
                                or users.get_by_login(login) is not None
                                or login in context)):
             msg = "Login '%s' is already in use" % login
             raise ValidationError(login=msg)
     objectEventNotify(ObjectWillBeModifiedEvent(context))
     if user is not None:
         # Set new login
         try:
             users.change_login(userid, converted['login'])
         except ValueError, e:
             raise ValidationError(login=str(e))
         # Set group memberships
         user_groups = self.user_groups
         chosen_groups = set(converted['groups'])
         for group, group_title in self.group_options:
             if group in chosen_groups and group not in user_groups:
                 users.add_user_to_group(userid, group)
             if group in user_groups and group not in chosen_groups:
                 users.remove_user_from_group(userid, group)
         # Edit password
         if converted.get('password', None):
             users.change_password(userid, converted['password'])
Exemple #4
0
    def update(self, item):
        objectEventNotify(ObjectWillBeModifiedEvent(item))

        item.title = self._element_value(self.element, 'title')
        item.description = self._element_value(self.element, 'description')

        objectEventNotify(ObjectModifiedEvent(item))
Exemple #5
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if 'security_state' in converted:
            if workflow is not None:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])

        context.title = converted['title']
        context.text = converted['text']
        context.description = extract_description(converted['text'])

        # Tags and attachments
        set_tags(context, request, converted['tags'])
        creator = authenticated_userid(request)
        attachments_folder = context['attachments']
        upload_attachments(
            filter(lambda x: x is not None, converted['attachments']),
            attachments_folder, creator, request)

        # modified
        context.modified_by = authenticated_userid(request)
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context, request)
        self.filestore.clear()
        return HTTPFound(location=location)
Exemple #6
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow

        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if workflow is not None:
            if 'security_state' in converted:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])

        context.title = converted['title']
        context.text = converted['text']
        context.description = extract_description(converted['text'])

        # Save the tags on it
        set_tags(context, request, converted['tags'])

        # Save new attachments
        creator = authenticated_userid(request)
        if support_attachments(context):
            upload_attachments(converted['attachments'], context['attachments'],
                               creator, request)

        # Modified
        context.modified_by = authenticated_userid(request)
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context, request,
                             query={'status_message':'Forum Topic Edited'})
        return HTTPFound(location=location)
Exemple #7
0
    def handle_submit(self, params):
        context = self.context
        objectEventNotify(ObjectWillBeModifiedEvent(context))

        if self.use_folder_options:
            noLongerProvides(context, IReferencesFolder)
            noLongerProvides(context, INetworkNewsMarker)
            noLongerProvides(context, INetworkEventsMarker)
            marker = params.get('marker')
            if marker == 'reference_manual':
                alsoProvides(context, IReferencesFolder)
            elif marker == 'network_news':
                alsoProvides(context, INetworkNewsMarker)
            elif marker == 'network_events':
                alsoProvides(context, INetworkEventsMarker)

        keywords = params.get('keywords')
        if keywords is not None:
            context.search_keywords = keywords

        weight = params.get('weight')
        if weight is not None:
            context.search_weight = weight

        if self.use_unlock and params.get('unlock'):
            lock.clear(context)

        objectEventNotify(ObjectModifiedEvent(context))
        return HTTPFound(location=resource_url(
            self.context,
            self.request,
            query={'status_message': 'Advanced settings changed.'}))
Exemple #8
0
    def handle_submit(self, converted):
        request = self.request
        context = self.context

        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))

        simple_fields = ['title', 'text', 'caption', 'publication_date']
        for field in simple_fields:
            setattr(context, field, converted[field])

        # save tags, attachments, photo
        set_tags(context, request, converted['tags'])
        userid = authenticated_userid(request)
        attachments_folder = context['attachments']
        upload_attachments(converted['attachments'], attachments_folder,
                           userid, request)
        handle_photo_upload(context, converted)
        self.filestore.clear

        # mark as modified
        context.modified_by = userid
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context, request)
        msg = "?status_message=News%20Item%20edited"
        return HTTPFound(location=location + msg)
Exemple #9
0
    def handle_submit(self, converted):
        if lock.owns_lock(self.context, self.userid):
            lock.clear(self.context)

        context = self.context
        request = self.request
        workflow = self.workflow
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if workflow is not None:
            if 'security_state' in converted:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])

        context.text = converted['text']
        context.description = extract_description(converted['text'])
        newtitle = converted['title']
        if newtitle != context.title:
            context.change_title(newtitle)

        # Save the tags on it
        set_tags(context, request, converted['tags'])

        # Modified
        context.modified_by = authenticated_userid(request)
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context, request)
        msg = "?status_message=Wiki%20Page%20edited"
        return HTTPFound(location=location + msg)
Exemple #10
0
 def handle_submit(self, converted):
     context = self.context
     request = self.request
     objectEventNotify(ObjectWillBeModifiedEvent(context))
     _normalize_websites(converted)
     # Handle the easy ones
     for name in self.simple_field_names:
         setattr(context, name, converted.get(name))
     # Handle the picture and clear the temporary filestore
     try:
         handle_photo_upload(context, converted)
     except Invalid, e:
         raise ValidationError(**e.error_dict)
Exemple #11
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))

        context.title = converted['title']
        context.description = converted['description']
        # save the tags
        set_tags(context, request, converted['tags'])

        # modified
        context.modified_by = authenticated_userid(request)
        objectEventNotify(ObjectModifiedEvent(context))
        location = resource_url(context, request)
        msg = "?status_message=%s" % self.success_msg
        return HTTPFound(location='%s%s' % (location, msg))
Exemple #12
0
 def handle_submit(self, converted):
     context = self.context
     request = self.request
     users = self.users
     userid = self.userid
     user = self.user
     if user is not None:
         login = converted.get('login')
         login_changed = users.get_by_login(login) != user
         if (login_changed and (users.get_by_id(login) is not None
                                or users.get_by_login(login) is not None
                                or login in context)):
             msg = "Login '%s' is already in use" % login
             raise ValidationError(login=msg)
     objectEventNotify(ObjectWillBeModifiedEvent(context))
     if user is not None:
         # Set new login
         try:
             users.change_login(userid, converted['login'])
         except ValueError, e:
             raise ValidationError(login=str(e))
         # Set group memberships
         user_groups = self.user_groups
         chosen_groups = set(converted['groups'])
         for group, group_title in self.group_options:
             if group in chosen_groups and group not in user_groups:
                 users.add_user_to_group(userid, group)
             if group in user_groups and group not in chosen_groups:
                 users.remove_user_from_group(userid, group)
         # Edit password
         if converted.get('password', None):
             new_password = converted['password']
             sha_password = get_sha_password(new_password)
             if context.last_passwords is None:
                 context.last_passwords = PersistentList()
             if sha_password in context.last_passwords:
                 msg = "Please use a password that was not previously used"
                 raise ValidationError(password=msg)
             users.change_password(userid, new_password)
             context.last_passwords.append(sha_password)
             if len(context.last_passwords) > 10:
                 context.last_passwords = context.last_passwords[1:]
             self.request.session['password_expired'] = False
             context.password_expiration_date = (datetime.utcnow() +
                                                 timedelta(days=180))
Exemple #13
0
def evolve(context):
    # Some users that are former stuff didn't have their categories properly
    # removed.  In OSI, no non-KarlStaff should be in any categories.
    profiles = find_profiles(context)
    users = find_users(context)

    for profile in profiles.values():
        username = profile.__name__
        if users.member_of_group(username, 'group.KarlStaff'):
            # No change needed for KarlStaff
            continue

        has_categories = filter(None,
                                getattr(profile, 'categories', {}).values())
        if has_categories:
            print "Removing categories for ", username, profile.categories
            objectEventNotify(ObjectWillBeModifiedEvent(profile))
            del profile.categories
            objectEventNotify(ObjectModifiedEvent(profile))
Exemple #14
0
    def handle_submit(self, converted):
        """
        Have to copy this code from the base class so the events will
        fire at the right time.
        """
        context = self.context
        request = self.request
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        workflow = self.workflow
        if workflow is not None:
            if 'security_state' in converted:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])
        context.title = converted['title']
        context.description = converted['description']
        context.text = converted['text']
        if converted.get('feature'):
            context.feature = clean_feature_html(converted['feature'])
        else:
            context.feature = sample_feature
        # NB: this is an edit form, so tags are added immediately via
        # AJAX; we needn't deal with setting them in the form post
        tools_present = [None]
        available_tools = self.available_tools
        for info in available_tools:
            component = info['component']
            tool_name = info['name']
            tools_present.append(tool_name)
            present = component.is_present(context, request)
            if (not present) and tool_name in converted['tools']:
                component.add(context, request)
            if present and (tool_name not in converted['tools']):
                component.remove(context, request)
                tools_present.remove(tool_name)
        if converted['default_tool'] in tools_present:
            context.default_tool = converted['default_tool']
        elif not (context.default_tool in tools_present):
            context.default_tool = None

        # *modified* event
        objectEventNotify(ObjectModifiedEvent(context))
        location = resource_url(context, request)
        return HTTPFound(location=location)
Exemple #15
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow =  get_workflow(IComment, 'security', context)

        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if workflow is not None:
            if 'security_state' in converted:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])
        context.text = converted['add_comment']
        context.description = extract_description(context.text)
        creator = authenticated_userid(request)
        if support_attachments(context):
            upload_attachments(converted['attachments'], context, creator,
                               request)
        context.modified_by = creator
        objectEventNotify(ObjectModifiedEvent(context))
        location = resource_url(context, request)
        self.filestore.clear()
        return HTTPFound(location=location)
Exemple #16
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        workflow = self.workflow
        # *will be* modified event
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        if workflow is not None:
            if 'security_state' in converted:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])

        context.title = converted['title']
        context.description = converted['description']

        # Modified
        context.modified_by = authenticated_userid(request)
        objectEventNotify(ObjectModifiedEvent(context))

        location = resource_url(context, request,
                             query={'status_message':'Forum Edited'})
        return HTTPFound(location=location)
Exemple #17
0
    def update(self, profile):
        objectEventNotify(ObjectWillBeModifiedEvent(profile))

        if profile.security_state == 'active':
            element = self.element
            login = self._element_value(element, 'username')
            username = profile.__name__
            groups = self._groups(element)

            # Don't clobber user's community memberships
            users = find_users(profile)
            info = users.get_by_id(username)
            if info is not None:
                prev_groups = info['groups']
                community_groups = [
                    g for g in prev_groups if g.startswith('group.community')
                ]
                groups = groups | set(community_groups)

            if info is not None:
                # keep old password
                password = info['password']
                users.remove(username)
                users.add(username, login, password, groups, encrypted=True)
            else:
                # can it be that we have a new user here?
                password = get_random_password()
                users.add(username, login, password, groups, encrypted=False)
                user = users.get_by_id(username)
                request = get_current_request()
                settings = get_settings()
                app_url = settings.get('script_app_url')
                request_password_reset(user, profile, request, app_url=app_url)

        self._populate(profile)
        reset_security_workflow(profile)

        objectEventNotify(ObjectModifiedEvent(profile))
Exemple #18
0
    def handle_submit(self, converted):
        context = self.context
        request = self.request
        objectEventNotify(ObjectWillBeModifiedEvent(context))
        workflow = self.workflow
        if workflow is not None:
            if 'security_state' in converted:
                workflow.transition_to_state(context, request,
                                             converted['security_state'])
        context.title = converted['title']
        context.description = converted['description']
        context.text = converted['text']
        context.modified_by = authenticated_userid(request)
        # NB: this is an edit form, so tags are added immediately via
        # AJAX; we needn't deal with setting them in the form post
        tools_present = [None]
        available_tools = self.available_tools
        for info in available_tools:
            component = info['component']
            tool_name = info['name']
            tools_present.append(tool_name)
            present = component.is_present(context, request)
            if (not present) and tool_name in converted['tools']:
                component.add(context, request)
            if present and (tool_name not in converted['tools']):
                component.remove(context, request)
                tools_present.remove(tool_name)
        if converted['default_tool'] in tools_present:
            context.default_tool = converted['default_tool']
        elif not (context.default_tool in tools_present):
            context.default_tool = None
        context.sendalert_default = converted['sendalert_default']

        # *modified* event
        objectEventNotify(ObjectModifiedEvent(context))
        location = resource_url(context, request)
        return HTTPFound(location=location)
Exemple #19
0
    def syncuser(self, data, missing):
        for key in self.required_keys:
            if not data.get(key):
                raise ValueError("Invalid user data: '%s' key is required" %
                                 key)
        users = find_users(self.context)
        profiles = find_profiles(self.context)
        username = data.pop("username")
        profile = profiles.get(username)
        active = profile and profile.security_state == 'active'
        if username in missing:
            missing.remove(username)
        if not profile:
            profile = self.createuser(data)
            self.update(profile, data)
            profiles[username] = profile
            activate = data.pop('active', 'true')
            security_state = 'active' if activate else 'inactive'
            log.info('Created user: %s', username)
        else:
            objectEventNotify(ObjectWillBeModifiedEvent(profile))
            self.update(profile, data)
            objectEventNotify(ObjectModifiedEvent(profile))
            activate = data.pop('active', None)
            if activate is not None:
                security_state = 'active' if activate else 'inactive'
            else:
                security_state = profile.security_state
                activate = active
            if type(missing) is Empty:
                log.info("Updated user: %s", username)
        profile.usersync_managed = True

        if active:
            info = users.get(username)
            password = data.pop('password', info['password'])
            groups = data.pop('groups', info['groups'])
            login = data.pop('login', info['login'])
            users.remove(username)

        elif activate:  # reactivate
            log.info("Reactivating user: %s", username)
            login = data.pop('login', username)
            password = data.pop('password', None)
            groups = data.pop('groups', [])
            if not password:
                raise ValueError(
                    "Invalid user data: 'password' key is required to "
                    "reactivate user")

        if activate:
            users.add(username, login, password, groups, encrypted=True)

        if security_state != getattr(profile, 'security_state', None):
            workflow = get_workflow(IProfile, 'security', profile)
            workflow.transition_to_state(profile, None, security_state)
            if security_state == 'inactive':
                log.info("Deactivated user: %s", username)

        if data:
            raise ValueError(
                "Unrecognized keys in sync data for user: %s: %s" %
                (username, data.keys()))