Exemplo n.º 1
0
    def _listPendingSubscriptions(self, request, data=None):
        appchange, script, args, myId = yield self._getBasicArgs(request)
        landing = not self._ajax
        me = args['me']

        group = data['id']
        start = data['start'] or 'GI'

        entities = base.EntitySet(group)

        args.update({"menuId": "pending", "groupId": group.id,
                     "entities": entities, "heading": group.basic['name']})

        if me.id not in group.admins:
            raise errors.InvalidRequest('Access Denied')
        if script and landing:
            t.render(request, "group-settings.mako", **args)
        if script and appchange:
            t.renderScriptBlock(request, "group-settings.mako", "layout",
                                landing, "#mainbar", "set", **args)

        data = yield Group.getPendingRequests(group, me, start)
        args.update(data)
        args["entities"].update(group)
        args["tab"] = 'pending'

        if script:
            t.renderScriptBlock(request, "groups.mako", "titlebar",
                                landing, "#titlebar", "set", **args)
            t.renderScriptBlock(request, "group-settings.mako", "displayUsers",
                                landing, "#groups-wrapper", "set", **args)
            t.renderScriptBlock(request, 'groups.mako', "pendingRequestsPaging",
                                landing, "#groups-paging", "set", **args)
Exemplo n.º 2
0
    def _unsubscribe(self, request, data=None):
        authInfo = request.getSession(IAuthInfo)
        myId = authInfo.username

        group = data['id']
        _pg = data['_pg']
        me = base.Entity(myId)
        yield me.fetchData(['basic'])

        yield Group.unsubscribe(request, group, me)
        args = {"groupId": group.id, "me": me, "myGroups": [],
                "entities": {group.id: group}, "groupFollowers": {group.id: []},
                "pendingConnections": [], "isMember": False}
        t.renderScriptBlock(request, "group-feed.mako", "group_actions", False,
                            "#group-actions-%s" % (group.id), "set", **args)

        if _pg == '/group':
            onload = "(function(obj){$$.convs.load(obj);})(this);"
            onload += "$('#sharebar-attach-fileshare, #sharebar-attach-file-input').attr('disabled', 'disabled');"
            onload += "$('#sharebar-submit').attr('disabled', 'disabled');"
            onload += "$('#group-share-block').addClass('disabled');"
            onload += "$('#group-links').hide();"
            t.renderScriptBlock(request, "group-feed.mako", "feed",
                                False, "#user-feed", "set", True,
                                handlers={"onload": onload}, **args)
Exemplo n.º 3
0
    def _create(self, request, data=None):
        authInfo = request.getSession(IAuthInfo)
        myId = authInfo.username

        name = data['name']
        description = data['desc']
        access = data['access']
        dp = data['dp']
        me = base.Entity(myId)
        yield me.fetchData()
        try:
            yield Group.create(request, me, name, access, description, dp)
        except errors.InvalidGroupName as e:
            request.write("<script> parent.$$.alerts.error('Group with same name already exists.'); </script>")
            raise e

        response = """
                    <script>
                        parent.$$.alerts.info('%s');
                        parent.$.get('/ajax/notifications/new');
                        parent.$$.fetchUri('/groups');
                        parent.$$.dialog.close('addgroup-dlg', true);
                    </script>
                   """ % (_("Group Created"))
        request.write(response)
Exemplo n.º 4
0
    def _subscribe(self, request, data=None):
        authInfo = request.getSession(IAuthInfo)
        myId = authInfo.username
        orgId = authInfo.organization

        myGroups = []
        _pg = data['_pg']
        group = data['id']
        groupFollowers = {group.id: []}
        entities = base.EntitySet([myId, orgId])
        yield entities.fetchData()
        entities.update(group)
        args = {'entities': entities, "me": entities[myId]}

        isNewMember, pendingRequests = yield Group.subscribe(request, group, entities[myId], entities[orgId])
        if isNewMember or pendingRequests:
            if isNewMember:
                myGroups.append(group.id)
                groupFollowers[group.id].append(myId)
            args["isMember"] = isNewMember
            args["pendingConnections"] = pendingRequests
            args["groupFollowers"] = groupFollowers
            args["groupId"] = group.id
            args["myGroups"] = myGroups

            handlers = {}
            if group.basic['access'] == 'open' and _pg == '/group':
                onload = """
                             $('#group_add_invitee').autocomplete({
                                source: '/auto/users',
                               minLength: 2,
                               select: function( event, ui ) {
                                   $('#group_invitee').attr('value', ui.item.uid)
                               }
                              });
                             """
                t.renderScriptBlock(request, "group-feed.mako", "groupLinks",
                                    False, "#group-links", "set",
                                    handlers={"onload": onload}, **args)

                onload = "$('#sharebar-attach-fileshare,"\
                            "#sharebar-attach-file-input,"\
                            "#sharebar-submit').removeAttr('disabled');"
                onload += "$('#group-share-block').removeClass('disabled');"
                onload += "$('#group-links').show();"
                handlers = {'onload': onload}

            t.renderScriptBlock(request, "group-feed.mako", "group_actions",
                                False, "#group-actions-%s" % (group.id),
                                "set", handlers=handlers, **args)
            if group.basic['access'] == 'open' and _pg == '/group':
                feedItems = yield Feed.get(request.getSession(IAuthInfo), feedId=group.id)
                args.update(feedItems)
                onload = "(function(obj){$$.convs.load(obj);})(this);"
                t.renderScriptBlock(request, "group-feed.mako", "feed",
                                    False, "#user-feed", "set", True,
                                    handlers={"onload": onload}, **args)
Exemplo n.º 5
0
    def _unblock(self, request, data=None):
        myId = request.getSession(IAuthInfo).username
        group = data['id']
        user = data['uid']
        me = base.Entity(myId)

        yield Group.unblock(group, user, me)
        t.renderScriptBlock(request, "groups.mako", "groupRequestActions",
                            False, '#group-request-actions-%s-%s' % (user.id, group.id),
                            "set", args=[group.id, user.id, "unblock"])
Exemplo n.º 6
0
 def _unfollow(self, request, data=None):
     myId = request.getSession(IAuthInfo).username
     me = base.Entity(myId)
     group = data['id']
     unfollowed = yield Group.unfollow(group, me)
     if unfollowed:
         args = {"groupId": group.id, "myGroups": [group.id], "me": me,
                 "entities": {group.id: group}, "pendingConnections": {},
                 "groupFollowers": {group.id: []}}
         t.renderScriptBlock(request, "group-feed.mako", "group_actions",
                             False, "#group-actions-%s" % (group.id),
                             "set", **args)
Exemplo n.º 7
0
 def _approve(self, request, data=None):
     authInfo = request.getSession(IAuthInfo)
     myId = authInfo.username
     group = data['id']
     user = data['uid']
     me = base.Entity(myId)
     yield me.fetchData()
     approved = yield Group.approveRequest(request, group, user, me)
     if approved:
         t.renderScriptBlock(request, "groups.mako", "groupRequestActions",
                             False, '#group-request-actions-%s-%s' % (user.id, group.id),
                             "set", args=[group.id, user.id, "accept"])
Exemplo n.º 8
0
    def _cancelGroupInvitation(self, request, data=None):
        myId = request.getSession(IAuthInfo).username
        group = data['id']
        me = base.Entity(myId)
        yield me.fetchData()
        cancelled = yield Group.cancelRequest(group, me)

        if cancelled:
            args = {"groupId": group.id, "entities": {group.id: group},
                    "myGroups": [], "groupFollowers": {group.id: []},
                    "pendingConnections": [], "me": me}
            t.renderScriptBlock(request, "group-feed.mako", "group_actions",
                                False, "#group-actions-%s" % (group.id),
                                "set", **args)
Exemplo n.º 9
0
    def _makeAdmin(self, request, data=None):
        authInfo = request.getSession(IAuthInfo)
        myId = authInfo.username

        group = data['id']
        user = data['uid']
        me = base.Entity(myId)

        yield Group.makeAdmin(request, group, user, me)
        group.admins[user.id] = ''
        args = {'entities': {group.id: group}}

        t.renderScriptBlock(request, "groups.mako", "groupRequestActions",
                            False, '#group-request-actions-%s-%s' % (user.id, group.id),
                            "set", args=[group.id, user.id, "show_manage"], **args)
Exemplo n.º 10
0
    def _remove(self, request, data=None):
        """
            Method to remove an user from a group.
            Note: only a group-administrator can remove a user from the group.
        """
        myId = request.getSession(IAuthInfo).username

        group = data['id']
        user = data['uid']
        me = base.Entity(myId)

        removed = yield Group.removeUser(group, user, me)
        if removed:
            t.renderScriptBlock(request, "groups.mako", "groupRequestActions",
                                False, '#group-request-actions-%s-%s' % (user.id, group.id),
                                "set", args=[group.id, user.id, "removed"])
            request.write("$$.alerts.info('%s is removed from %s');" % (user.basic['name'], group.basic['name']))
Exemplo n.º 11
0
    def _listGroupMembers(self, request, data=None):
        appchange, script, args, myId = yield self._getBasicArgs(request)
        landing = not self._ajax
        me = args['me']

        group = data['id']
        start = data['start']

        groupMembers_d = Group.getMembers(group, me, start=start)
        args.update({"menuId": "members", "groupId": group.id,
                      "entities": {group.id: group}})
        args["tab"] = 'manage' if myId in group.admins else ''

        if script and landing:
            t.render(request, "group-settings.mako", **args)

        if script and appchange:
            t.renderScriptBlock(request, "group-settings.mako", "layout",
                                    landing, "#mainbar", "set", **args)

        entities, relation, userIds, blockedUsers, \
            nextPageStart, prevPageStart = yield groupMembers_d

        #arg.update overwrites existing entities, so add group
        entities.update(group)
        args.update({"relations": relation, "entities": entities,
                     "userIds": userIds, "blockedUsers": blockedUsers,
                     "nextPageStart": nextPageStart,
                     "prevPageStart": prevPageStart,
                     "heading": group.basic['name']})

        if script:
            t.renderScriptBlock(request, "group-settings.mako", "titlebar",
                                landing, "#titlebar", "set", **args)
            t.renderScriptBlock(request, "group-settings.mako", "displayUsers",
                                landing, "#groups-wrapper", "set", **args)
            t.renderScriptBlock(request, "group-settings.mako", "paging",
                                landing, "#groups-paging", "set", **args)
        else:
            t.render(request, "group-settings.mako", **args)
Exemplo n.º 12
0
    def _invite(self, request, data=None):
        appchange, script, args, myId = yield self._getBasicArgs(request)
        landing = not self._ajax

        group = data['id']
        user = data['invitee']
        me = args['me']
        args["groupId"] = group.id
        args["heading"] = group.basic["name"]

        if script and landing:
            t.render(request, "groups.mako", **args)
        if script and appchange:
            t.renderScriptBlock(request, "groups.mako", "layout",
                                landing, "#mainbar", "set", **args)
        try:
            yield Group.invite(group, me, user)
        except ttypes.NotFoundException:
            request.write('$$.alerts.error("You should be member of the group to Invite Others");')
        finally:
            request.write("""$("#group_add_invitee").attr("value", "");"""\
                          """$$.alerts.info("%s is invited to the %s");""" % (user.basic["name"], group.basic["name"]))
Exemplo n.º 13
0
    def _removeAdmin(self, request, data=None):
        authInfo = request.getSession(IAuthInfo)
        myId = authInfo.username

        group = data['id']
        user = data['uid']
        me = base.Entity(myId)
        yield Group.removeAdmin(group, user, me)

        del group.admins[user.id]
        args = {'entities': {group.id: group}}
        if user.id != me.id:
            t.renderScriptBlock(request, "groups.mako", "groupRequestActions",
                                False, '#group-request-actions-%s-%s' % (user.id, group.id),
                                "set", args=[group.id, user.id, "show_manage"], **args)
        else:
            handlers = {'onload': "$$.alerts.info('You are not admin of this group anymore.');"}
            args['groupId'] = group.id
            request.write("$$.fetchUri('/groups/members?id=%s');" % (group.id))
            t.renderScriptBlock(request, "group-settings.mako", "nav_menu",
                                False, "#nav-menu", "set", True,
                                handlers=handlers, **args)
Exemplo n.º 14
0
    def _edit(self, request, data=None):
        myId = request.getSession(IAuthInfo).username

        group = data['id']
        name = data['name']
        desc = data['desc']
        access = data['access']
        dp = data['dp']
        me = base.Entity(myId)
        yield me.fetchData()

        try:
            updated = yield Group.edit(me, group, name, access, desc, dp)
        except errors.InvalidGroupName as e:
            request.write("<script> parent.$$.alerts.error('Group with same name already exists.'); </script>")
            raise e

        if updated:
            if name != group.basic['name']:
                t.renderScriptBlock(request, 'groups.mako', 'titlebar', False,
                                    "#titlebar",  'set', isIframe=True,
                                    **{'heading': name})
            request.write("<script>parent.$$.alerts.info('updated successful');</script>")
Exemplo n.º 15
0
    def _listBannedUsers(self, request, data=None):
        appchange, script, args, myId = yield self._getBasicArgs(request)
        landing = not self._ajax
        me = args['me']

        group = data['id']
        start = data['start']
        start = utils.decodeKey(start)
        entities = base.EntitySet(group)

        args.update({"menuId": "banned", "groupId": group.id,
                     "entities": entities, "heading": group.basic['name']})

        if me.id not in group.admins:
            raise errors.InvalidRequest(_("Access Denied"))

        if script and landing:
            t.render(request, "group-settings.mako", **args)

        if script and appchange:
            t.renderScriptBlock(request, "group-settings.mako", "layout",
                                    landing, "#mainbar", "set", **args)

        data = yield Group.getBlockedMembers(group, me, start)
        print data.keys()
        args.update(data)
        args['entities'].update(group)
        args["tab"] = "banned"

        if script:
            t.renderScriptBlock(request, "group-settings.mako", "titlebar",
                                landing, "#titlebar", "set", **args)
            t.renderScriptBlock(request, "group-settings.mako", "displayUsers",
                                landing, "#groups-wrapper", "set", **args)
            t.renderScriptBlock(request, "group-settings.mako", "bannedUsersPaging",
                                landing, "#groups-paging", "set", **args)
Exemplo n.º 16
0
    def _listGroups(self, request):
        appchange, script, args, myId = yield self._getBasicArgs(request)
        landing = not self._ajax
        me = args['me']

        viewType = utils.getRequestArg(request, 'type') or 'myGroups'
        start = utils.getRequestArg(request, 'start') or ''
        start = utils.decodeKey(start)

        viewTypes = ['myGroups', 'allGroups', 'adminGroups', 'pendingRequests', 'invitations']
        viewType = 'myGroups' if viewType not in viewTypes else viewType

        args["menuId"] = "groups"
        args['viewType'] = viewType

        cols = yield db.get_slice(myId, "entities", super_column='adminOfGroups')
        managedGroupIds = [col.column.name for col in cols]

        ##TODO: can we use getLatestCounts instead of fetching pendingConnections?
        cols = yield db.multiget_slice(managedGroupIds, "pendingConnections", count=1)
        cols = utils.multiColumnsToDict(cols)

        showPendingRequestsTab = sum([len(cols[groupId]) for groupId in cols]) > 0
        args["showPendingRequestsTab"] = showPendingRequestsTab

        if viewType == 'pendingRequests' and not showPendingRequestsTab:
            viewType = 'myGroups'
            args["viewType"] = viewType

        cols = yield db.get_slice(myId, "pendingConnections", start="GI:", count=1)
        args["showInvitationsTab"] = bool(len([col for col in cols if col.column.name.startswith('GI:')]))

        if viewType == 'invitations' and not args["showInvitationsTab"]:
            viewType = 'myGroups'
            args['viewType'] = viewType

        counts = yield utils.getLatestCounts(request, False)
        groupRequestCount = args["groupRequestCount"] = counts["groups"]

        if script and landing:
            t.render(request, "groups.mako", **args)

        if script and appchange:
            t.renderScriptBlock(request, "groups.mako", "layout",
                                landing, "#mainbar", "set", **args)

        if viewType not in ['pendingRequests', 'invitations']:
            if viewType == 'myGroups':
                data = yield Group.getGroups(me, me, start)
            elif viewType == 'allGroups':
                data = yield Group.getGroups(me, args['org'], start)
            else:
                data = yield Group.getManagedGroups(me, start)
            args.update(data)

        elif viewType == 'pendingRequests':
            data = yield Group.getGroupRequests(me, start)
            args.update(data)
            args['tab'] = 'pending'
        elif viewType == 'invitations':
            data = yield Group.getAllInvitations(me, start)
            args.update(data)

        if script:
            t.renderScriptBlock(request, "groups.mako", "titlebar",
                                landing, "#titlebar", "set", **args)
            t.renderScriptBlock(request, "groups.mako", "viewOptions",
                                landing, "#groups-view", "set", args=[viewType],
                                showPendingRequestsTab=showPendingRequestsTab,
                                showInvitationsTab=args['showInvitationsTab'],
                                groupRequestCount=groupRequestCount)
            if viewType == "pendingRequests":
                t.renderScriptBlock(request, "groups.mako", "allPendingRequests",
                                    landing, "#groups-wrapper", "set", **args)
            else:
                t.renderScriptBlock(request, "groups.mako", "listGroups",
                                    landing, "#groups-wrapper", "set", **args)
            t.renderScriptBlock(request, "groups.mako", "paging",
                                landing, "#groups-paging", "set", **args)

        if not script:
            t.render(request, "groups.mako", **args)