コード例 #1
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)
コード例 #2
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)
コード例 #3
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)
コード例 #4
0
ファイル: blog.py プロジェクト: araymund/karl
    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)
コード例 #5
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.'}))
コード例 #6
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)
コード例 #7
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)
コード例 #8
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))
コード例 #9
0
ファイル: references.py プロジェクト: zagy/karl
    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))
コード例 #10
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)
コード例 #11
0
ファイル: evolve7.py プロジェクト: iotest3/new
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))
コード例 #12
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)
コード例 #13
0
ファイル: commenting.py プロジェクト: zagy/karl
    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)
コード例 #14
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))
コード例 #15
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)
コード例 #16
0
class EditProfileFormController(object):
    """
    Formish controller for the profile edit form.  Also the base class
    for the controllers for the admin profile edit and add user forms.
    """
    simple_field_names = [
        "firstname",
        "lastname",
        "email",
        "phone",
        "extension",
        "fax",
        "department",
        "position",
        "organization",
        "location",
        "country",
        "websites",
        "languages",
        "office",
        "room_no",
        "biography",
        "date_format",
    ]

    def __init__(self, context, request):
        self.context = context
        self.request = request
        self.filestore = get_filestore(context, request, 'edit-profile')
        self.page_title = "Edit %s" % context.title
        photo = context.get('photo')
        if photo is not None:
            photo = SchemaFile(None, photo.__name__, photo.mimetype)
        self.photo = photo

    def form_fields(self):
        email_field = schemaish.String(
            validator=validator.All(validator.Required(), validator.Email(),
                                    karlvalidators.UniqueEmail(self.context)))
        fields = [('firstname', firstname_field), ('lastname', lastname_field),
                  ('email', email_field), ('phone', phone_field),
                  ('extension', extension_field), ('fax', fax_field),
                  ('department', department_field),
                  ('position', position_field),
                  ('organization', organization_field),
                  ('location', location_field), ('country', country_field),
                  ('websites', websites_field), ('languages', languages_field),
                  ('biography', biography_field), ('photo', photo_field),
                  ('date_format', date_format_field)]
        return fields

    def form_widgets(self, fields):
        api = TemplateAPI(self.context, self.request, self.page_title)
        default_icon = '%s/images/defaultUser.gif' % api.static_url
        show_remove_checkbox = self.photo is not None
        widgets = {
            'firstname':
            formish.Input(empty=''),
            'lastname':
            formish.Input(empty=''),
            'email':
            formish.Input(),
            'phone':
            formish.Input(empty=''),
            'extension':
            formish.Input(empty=''),
            'fax':
            formish.Input(empty=''),
            'department':
            formish.Input(empty=''),
            'position':
            formish.Input(empty=''),
            'organization':
            formish.Input(empty=''),
            'location':
            formish.Input(empty=''),
            'country':
            formish.SelectChoice(options=countries),
            'websites':
            formish.TextArea(rows=3, converter_options={'delimiter': '\n'}),
            'languages':
            formish.Input(empty=''),
            'photo':
            karlwidgets.PhotoImageWidget(
                filestore=self.filestore,
                url_base=resource_url(self.context, self.request),
                image_thumbnail_default=default_icon,
                show_remove_checkbox=show_remove_checkbox),
            'biography':
            karlwidgets.RichTextWidget(empty=''),
            'date_format':
            karlwidgets.VerticalRadioChoice(options=cultures,
                                            none_option=None),
        }
        return widgets

    def form_defaults(self):
        context = self.context
        defaults = {
            'firstname': context.firstname,
            'lastname': context.lastname,
            'email': context.email,
            'phone': context.phone,
            'extension': context.extension,
            'fax': context.fax,
            'department': context.department,
            'position': context.position,
            'organization': context.organization,
            'location': context.location,
            'country': context.country,
            'websites': context.websites,
            'languages': context.languages,
            'photo': self.photo,
            'biography': context.biography,
            'date_format': context.date_format,
        }
        return defaults

    def __call__(self):
        _fix_website_validation_errors(self.request.form)
        api = TemplateAPI(self.context, self.request, self.page_title)
        if api.user_is_admin:
            return HTTPFound(location=resource_url(self.context, self.request,
                                                   'admin_edit_profile.html'))
        layout_provider = get_layout_provider(self.context, self.request)
        layout = layout_provider('generic')
        if api.user_is_staff:
            self.request.form.edge_div_class = 'k3_staff_role'
        else:
            self.request.form.edge_div_class = 'k3_nonstaff_role'
        form_title = 'Edit Profile'
        same_user = authenticated_userid(self.request) == self.context.__name__
        return {
            'api': api,
            'actions': (),
            'layout': layout,
            'same_user': same_user,
            'form_title': form_title,
            'include_blurb': True
        }

    def handle_cancel(self):
        return HTTPFound(location=resource_url(self.context, self.request))

    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)
        self.filestore.clear()
        context.modified_by = authenticated_userid(request)
        # Emit a modified event for recataloging
        objectEventNotify(ObjectModifiedEvent(context))
        # Whew, we made it!
        path = resource_url(context, request)
        msg = '?status_message=Profile%20edited'
        return HTTPFound(location=path + msg)
コード例 #17
0
            # Edit password
            if converted.get('password', None):
                users.change_password(userid, converted['password'])
        _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)
        self.filestore.clear()
        context.modified_by = authenticated_userid(request)
        # Emit a modified event for recataloging
        objectEventNotify(ObjectModifiedEvent(context))
        # Whew, we made it!
        path = resource_url(context, request)
        msg = '?status_message=User%20edited'
        return HTTPFound(location=path + msg)


def get_group_options(context):
    group_options = []
    for group in get_setting(context, "selectable_groups").split():
        if group.startswith('group.'):
            title = group[6:]
        else:
            title = group
        group_options.append((group, title))
    return group_options
コード例 #18
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()))