Example #1
0
def invitation_accepted(event):
    """
    When an invitation is accepted, add the user to the team
    """
    request = getRequest()
    storage = get_storage()
    if event.token_id not in storage:
        return

    ws_uid, username = storage[event.token_id]
    storage[event.token_id]
    acl_users = api.portal.get_tool("acl_users")
    acl_users.updateCredentials(request, request.response, username, None)
    catalog = api.portal.get_tool(name="portal_catalog")
    brain = catalog.unrestrictedSearchResults(UID=ws_uid)[0]
    with api.env.adopt_roles(["Manager"]):
        ws = IWorkspace(brain.getObject())
        for name in ws.members:
            member = api.user.get(username=name)
            if member is not None:
                if member.getUserName() == username:
                    api.portal.show_message(_("Oh boy, oh boy, you are already a member"), request)
                    break
        else:
            ws.add_to_team(user=username)
            api.portal.show_message(_("Welcome to our family, Stranger"), request)
Example #2
0
 def roles(self):
     ws_policy = self.context.participant_policy
     title = (_('Default role for this workspace')
              + ' ({})'.format(PARTICIPANT_POLICY[ws_policy]['title']))
     yield {'id': ws_policy.title(),
            'title': title}
     for policy_id, policy_info in PARTICIPANT_POLICY.items():
         if policy_id == ws_policy:
             continue
         yield {'id': policy_id.title(),
                'title': policy_info['title']}
     yield {'id': 'Admins',
            'title': _(u'Workspace Administrator')}
def existing_users(context):
    """
    Look up the full user details for current workspace members
    """
    members = IWorkspace(context).members
    info = []
    for userid, details in members.items():
        user = api.user.get(userid)
        if user is None:
            continue
        user = user.getUser()
        title = user.getProperty("fullname") or user.getId() or userid
        # XXX tbd, we don't know what a persons description is, yet
        description = _(u"Here we could have a nice status of this person")
        classes = description and "has-description" or "has-no-description"
        portal = api.portal.get()
        portrait = "%s/portal_memberdata/portraits/%s" % (portal.absolute_url(), userid)
        info.append(
            dict(
                id=userid,
                title=title,
                description=description,
                portrait=portrait,
                cls=classes,
                member=True,
                admin="Admins" in details["groups"],
            )
        )

    return info
Example #4
0
def existing_users(context):
    """
    Look up the full user details for current workspace members
    """
    members = IWorkspace(context).members
    info = []
    for userid, details in members.items():
        user = api.user.get(userid)
        if user is None:
            continue
        user = user.getUser()
        title = user.getProperty('fullname') or user.getId() or userid
        # XXX tbd, we don't know what a persons description is, yet
        description = _(u'Here we could have a nice status of this person')
        classes = description and 'has-description' or 'has-no-description'
        portal = api.portal.get()
        portrait = '%s/@@avatars/%s' % \
                   (portal.absolute_url(), userid)
        info.append(
            dict(
                id=userid,
                title=title,
                description=description,
                portrait=portrait,
                cls=classes,
                member=True,
                admin='Admins' in details['groups'],
            )
        )

    return info
    def __call__(self):
        """ write attributes, if any, set state, render
        """
        form = self.request.form

        if self.request.method == "POST" and form:
            ws = self.my_workspace()
            if self.request.form.get('section', None) == 'task':
                current_tasks = self.request.form.get('current-tasks', [])
                active_tasks = self.request.form.get('active-tasks', [])

                catalog = api.portal.get_tool("portal_catalog")
                brains = catalog(UID={'query': current_tasks,
                                      'operator': 'or'})
                for brain in brains:
                    obj = brain.getObject()
                    todo = ITodo(obj)
                    if brain.UID in active_tasks:
                        todo.status = u'done'
                    else:
                        todo.status = u'tbd'
                api.portal.show_message(_(u'Changes applied'),
                                        self.request,
                                        'success')
            else:
                if form.get('title') and form.get('title') != ws.title:
                    ws.title = form.get('title').strip()
                    api.portal.show_message(_(u'Title changed'),
                                            self.request,
                                            'success')

                if form.get('description') and \
                   form.get('description') != ws.description:
                    ws.description = form.get('description').strip()
                    api.portal.show_message(_(u'Description changed'),
                                            self.request,
                                            'success')

                calendar_visible = not not form.get('calendar_visible')
                if calendar_visible != ws.calendar_visible:
                    ws.calendar_visible = calendar_visible
                    api.portal.show_message(_(u'Calendar visibility changed'),
                                            self.request,
                                            'success')

        return self.render()
Example #6
0
    def __call__(self):
        if not self.context.join_policy == "self":
            msg = _(u"Workspace join policy doesn't allow self join")
            raise Unauthorized(msg)

        field = "button.join"
        req_method = self.request.method.lower()
        if req_method == "post" and field in self.request.form:
            user = api.user.get_current()
            workspace = IWorkspace(self.context)
            workspace.add_to_team(user=user.getId())
            msg = _(u"You are a member of this workspace now")
            api.portal.show_message(message=_(msg),
                                    request=self.request)

        referer = self.request.get("HTTP_REFERER", "").strip()
        if not referer:
            referer = self.context.absolute_url()
        return self.request.response.redirect(referer)
Example #7
0
def user_has_email(username):
    """ make sure, that given user has an email associated """
    user = api.user.get(username=username)
    if not user.getProperty("email"):
        msg = _(
            "This user doesn't have an email associated "
            "with their account."
        )
        raise Invalid(msg)

    return True
Example #8
0
 def update_roster(self, REQUEST=None):
     """
     If workspace is team managed, users can add/remove participants.
     Any user with the manage workspace permission can add/remove
     participants and admins.
     """
     CheckAuthenticator(self.request)
     PostOnly(self.request)
     form = self.request.form
     entries = form.get('entries', [])
     self.update_users(entries)
     api.portal.show_message(message=_(u'Roster updated.'),
                             request=self.request)
     return self.request.response.redirect(
         '%s/@@edit-roster' % self.context.absolute_url())
    def __call__(self):
        """ write attributes, if any, set state, render
        """
        form = self.request.form

        if self.request.method == "POST" and form:
            ws = self.my_workspace()

            if form.get('email') and form.get('email') != ws.email:
                ws.email = form.get('email').strip()
                api.portal.show_message(_(u'Email changed'),
                                        self.request,
                                        'success')

        return self.render()
        def update_field(field_name):
            index = int(form.get(field_name)) - 1
            field = getattr(self, field_name)
            value = field.keys()[index]

            if value != getattr(ws, field_name):
                if field_name == "external_visibility":
                    ws.set_external_visibility(value)
                else:
                    setattr(ws, field_name, value)
                api.portal.show_message(
                    _(u'Workspace security policy changes saved'),
                    self.request,
                    'success',
                )
Example #11
0
"""
Defines the policies that can be applied to a workspace
"""
from collections import OrderedDict
from ploneintranet.workspace import MessageFactory as _

EXTERNAL_VISIBILITY = OrderedDict([
    ('secret', {
        "title": _(u"Secret"),
        "help": _(
            u"The workspace is hidden from outsiders. Only workspace "
            u"members know it exists."
        ),
    }),
    ('private', {
        "title": _(u"Private"),
        "help": _(
            u"The workspace is visible, but inaccessible to outsiders. "
            u"Only workspace members can access the workspace."
        ),
    }),
    ('open', {
        "title": _(u"Open"),
        "help": _(
            u"The workspace can be explored by outsiders. Outsiders can "
            u"browse but not actively participate."
        ),
    }),
])

JOIN_POLICY = OrderedDict([
from plone.formwidget.autocomplete import AutocompleteFieldWidget
from z3c.form import button
from z3c.form.interfaces import WidgetActionExecutionError
from zope import schema
from zope.component import getUtility
from zope.interface import directlyProvides, Invalid
from zope.schema.interfaces import IContextSourceBinder
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm

from ploneintranet.invitations.interfaces import ITokenUtility
from ploneintranet.workspace import MessageFactory as _
from ploneintranet.workspace.utils import get_storage, send_email


visibility_vocab = SimpleVocabulary([
    SimpleTerm(value=u'secret', title=_(u'Secret')),
    SimpleTerm(value=u'private', title=_(u'Private')),
    SimpleTerm(value=u'open', title=_(u'Open')),
])

join_vocab = SimpleVocabulary([
    SimpleTerm(value=u'admin', title=_(u'Admin-Managed')),
    SimpleTerm(value=u'team', title=_(u'Team-Managed')),
    SimpleTerm(value=u'self', title=_(u'Self-Managed')),
])

particip_vocab = SimpleVocabulary([
    SimpleTerm(value=u'consumers',
               title=_(u'Consumers (Read only)')),
    SimpleTerm(value=u'producers',
               title=_(u'Producers (Can create content)')),