cosent / plonesocial.microblog

ACHIVED - USE PLONEINTRANET. Simple microblogging for Plone
4 stars 8 forks source link

Feature: Remove microblog item #11

Open maartenkling opened 10 years ago

maartenkling commented 10 years ago

As a manager/siteadministrator i need to be able to delete one (1) microblog item from another user, as it can contain text that does not match the site terms and conditions

hvelarde commented 10 years ago

:+1:

macagua commented 10 years ago

:+1:

maartenkling commented 10 years ago

for now in browser view :)

<form method="post">
user: <input type="text" name="user" tal:attributes="value python: request.form.get('user', '')">
    <input type="submit" name="submit" class="btn">
</form>

<hr />
<tal:block tal:repeat="activity view/findkey">
    <span tal:content="python: activity[0]" /><br />
    <span tal:content="python: activity[1].text" />
    <form method="post">
        <input type="text" name="key" tal:attributes="value python: activity[0]">
        <input type="text" name="user" tal:attributes="value python: request.form.get('user', '')">
        <input type="submit" name="delete" value="delete" class="btn">
    </form>
     <br /><br />

</tal:block>

from plonesocial.activitystream.integration import PLONESOCIAL from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from Products.Five import BrowserView

class activityPopperView(BrowserView):

template = ViewPageTemplateFile('templates/activitypopper.pt')

def __call__(self):

    if self.request.get('REQUEST_METHOD', 'GET').upper() == 'POST':
        key = self.request.form.get('key', False)
        user = self.request.form.get('user', False)
        if key and user:
            self.pop(key, user)

    return self.index()

def findkey(self):
    container = PLONESOCIAL.microblog
    user = self.request.form.get('user', False)
    if user:
        return container.user_items(user)
    return False

def pop(self, key, user):
    container = PLONESOCIAL.microblog

    # remove from user mapping
    container._user_mapping[user].remove(long(key))

    # remove from tag mapping
    taglist = [x[1] for x in container._tag_mapping.items()]
    for x in taglist:
        if long(key) in x.keys():
            x.remove(long(key))

    # remove from uuid mapping
    uuidlist = [x[1] for x in container._uuid_mapping.items()]
    for x in uuidlist:
        if long(key) in x.keys():
            x.remove(long(key))

    # pop status
    container._status_mapping.pop(long(key))
    return
hvelarde commented 10 years ago

is always better in a pull request with tests ;-)

hvelarde commented 10 years ago

@maartenkling what happened with this?

maartenkling commented 10 years ago

@hvelarde nothing by me, i implemented a browser view in a separated package, but the code is okay

hvelarde commented 10 years ago

@gyst do you want to include this on the package?

gyst commented 10 years ago

@hvelarde yes, but "is always better in a pull request with tests ;-)"