class SGMSettingsEditForm(controlpanel.RegistryEditForm):
    """Media settings form.
    """
    schema = ISimpleGroupManagementSettings
    id = "SGMSettingsEditForm"
    label = _("Groups management proxy settings")
    description = _(
        "help_sgm_settings_editform",
        default="Configure groups management proxy"  # noqa
    )

    @button.buttonAndHandler(pmf('Save'), name='save')
    def handleSave(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return
        changes = self.applyChanges(data)
        IStatusMessage(self.request).addStatusMessage(_("Changes saved"),
                                                      "info")
        self.context.REQUEST.RESPONSE.redirect(
            "@@configure-simple-groups-management"
        )

    @button.buttonAndHandler(pmf('Cancel'), name='cancel')
    def handleCancel(self, action):
        IStatusMessage(self.request).addStatusMessage(_("Edit cancelled"),
                                                      "info")
        self.request.response.redirect("%s/%s" % (self.context.absolute_url(),
                                                  self.control_panel_view))

    def updateWidgets(self):
        super(SGMSettingsEditForm, self).updateWidgets()
        fix_widget_style(self.widgets['sgm_data'])
        fix_widget_style(self.widgets['sgm_never_managed_groups'])
Exemplo n.º 2
0
 def __call__(self):
     request = self.request
     plone_utils = getToolByName(self.context, 'plone_utils')
     if request.get('deleted'):
         plone_utils.addPortalMessage(_('Member(s) removed'))
     elif request.get('added'):
         plone_utils.addPortalMessage(_(u'Member(s) added'))
     if self.request.get("group_id"):
         return self.manage_group_template()
     return self.main_template()
Exemplo n.º 3
0
 def __call__(self):
     request = self.request
     if request.form.get('form.button.Upload'):
         self._bulk_upload()
     plone_utils = getToolByName(self.context, 'plone_utils')
     if request.get('deleted'):
         plone_utils.addPortalMessage(_('Member(s) removed'))
     elif request.get('added'):
         plone_utils.addPortalMessage(_('Member(s) added'))
     if self.request.get("group_id"):
         return self.manage_group_template()
     return self.main_template()
 def handleSave(self, action):
     data, errors = self.extractData()
     if errors:
         self.status = self.formErrorsMessage
         return
     changes = self.applyChanges(data)
     IStatusMessage(self.request).addStatusMessage(_(u"Changes saved"),
                                                   "info")
     self.context.REQUEST.RESPONSE.redirect(
         "@@configure-simple-groups-management")
 def handleSave(self, action):
     data, errors = self.extractData()
     if errors:
         self.status = self.formErrorsMessage
         return
     changes = self.applyChanges(data)
     IStatusMessage(self.request).addStatusMessage(_(u"Changes saved"),
                                                   "info")
     self.context.REQUEST.RESPONSE.redirect(
         "@@configure-simple-groups-management"
     )
 def __call__(self):
     request = self.request
     plone_utils = getToolByName(self.context, "plone_utils")
     group_id = self.request.get("group_id")
     if request.form.get("form.button.Upload"):
         self._bulk_upload()
     if request.form.get("form.button.AddUser"):
         errors = self._add_new_user()
         if errors:
             plone_utils.addPortalMessage(_("Cannot create user"), "error")
             return self.manage_group_template(errors=errors)
         self.request.response.redirect(
             self.context.absolute_url() +
             "/@@simple_groups_management?group_id=%s" % group_id)
     if request.get("deleted"):
         plone_utils.addPortalMessage(_("Member(s) removed"))
     elif request.get("added"):
         plone_utils.addPortalMessage(_(u"Member(s) added"))
     if group_id:
         return self.manage_group_template()
     return self.main_template()
 def handleCancel(self, action):
     IStatusMessage(self.request).addStatusMessage(_(u"Edit cancelled"),
                                                   "info")
     self.request.response.redirect("%s/%s" % (self.context.absolute_url(),
                                               self.control_panel_view))
 def handleCancel(self, action):
     IStatusMessage(self.request).addStatusMessage(_("Edit cancelled"),
                                                   "info")
     self.request.response.redirect("%s/%s" % (self.context.absolute_url(),
                                               self.control_panel_view))
    def _add_new_user(self):
        if not self.can_addusers():
            raise Unauthorized("Creating new user is not allowed")
        group_id = self.request.get("group_id")
        if group_id not in self.manageableGroupIds():
            raise Unauthorized("Managing group is not allowed")

        form = self.request.form
        send_reset_email = form.get("send_reset_email")
        username = form.get("username")
        # Check for password that do not match
        if (form.get("password") and form.get("password2")
                and form.get("password") != form.get("password2")):
            return {
                "password": _(u"Passwords do not match"),
            }
        # Check for user already there
        user = api.user.get(username=username)
        if user:
            return {
                "username": _(u"User already existing"),
            }
        regtool = api.portal.get_tool("portal_registration")
        # Check for valid userid
        if not regtool.isMemberIdAllowed(username):
            return {
                "username": _(u"Username not allowed"),
            }
        # Check for valid email
        if not regtool.isValidEmail(form.get("email")):
            return {
                "email": _(u"Invalid email address"),
            }
        # User creation
        try:
            api.user.create(
                username=username,
                email=form.get("email"),
                password=form.get("password") or None,
                properties={"fullname": form.get("fullname")}
                if form.get("fullname") else None,
            )
        except ConflictError:
            raise
        except Exception as e:
            api.portal.show_message(message=e.args[0],
                                    request=self.request,
                                    type="error")
            return {}
        if form.get("send_reset_email"):
            # reset_tool = api.portal.get_tool("portal_password_reset")
            try:
                regtool.mailPassword(username, self.request)
            except ValueError as e:
                api.portal.show_message(
                    message=_(
                        "reset_email_error",
                        default="Not able to send reset password message",
                    ),
                    request=self.request,
                    type="warning",
                )
                log.exception("Not able to send reset password message")
        # Adding user to the group
        api.group.add_user(groupname=group_id, username=username)
        api.portal.show_message(
            message=_("New user has been created"),
            request=self.request,
            type="info",
        )
        return {}