This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an admin handler that can be used to unsubscribe other users from
feeds. A user was susbcribed to http://www.dcde.ru/feeds/atom, which updates several times a minute.
- Loading branch information
Showing
5 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/info/persistent/pushbot/commands/AdminCommandHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,34 @@ | |||
// Copyright 2011 Google Inc. All Rights Reserved. | |||
|
|||
package info.persistent.pushbot.commands; | |||
|
|||
import com.google.appengine.api.xmpp.JID; | |||
|
|||
import info.persistent.pushbot.util.Xmpp; | |||
|
|||
import java.util.Arrays; | |||
|
|||
/** | |||
* Base class for commands that require administrator access. | |||
*/ | |||
public abstract class AdminCommandHandler implements CommandHandler { | |||
|
|||
@Override | |||
public void handle(JID adminUser, String... args) { | |||
if (!Xmpp.toShortJid(adminUser).getId().equals("mihai.parparita@gmail.com")) { | |||
Xmpp.sendMessage(adminUser, "You're not an administrator"); | |||
return; | |||
} | |||
|
|||
if (args.length == 0) { | |||
Xmpp.sendMessage(adminUser, "Need arguments"); | |||
return; | |||
} | |||
|
|||
JID targetUser = new JID(args[0]); | |||
|
|||
handle(adminUser, targetUser, Arrays.copyOfRange(args, 1, args.length)); | |||
} | |||
|
|||
protected abstract void handle(JID adminUser, JID targetUser, String... args); | |||
} |
61 changes: 61 additions & 0 deletions
61
src/info/persistent/pushbot/commands/AdminUnsubscribeCommandHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,61 @@ | |||
// Copyright 2011 Google Inc. All Rights Reserved. | |||
|
|||
package info.persistent.pushbot.commands; | |||
|
|||
import com.google.appengine.api.xmpp.JID; | |||
|
|||
import info.persistent.pushbot.data.Subscription; | |||
import info.persistent.pushbot.util.Hubs; | |||
import info.persistent.pushbot.util.Persistence; | |||
import info.persistent.pushbot.util.Xmpp; | |||
|
|||
import java.net.MalformedURLException; | |||
import java.net.URL; | |||
import java.util.List; | |||
import java.util.logging.Level; | |||
import java.util.logging.Logger; | |||
|
|||
import javax.jdo.PersistenceManager; | |||
|
|||
/** | |||
* Remove another user's subscription. | |||
*/ | |||
public class AdminUnsubscribeCommandHandler extends AdminCommandHandler { | |||
private static final Logger logger = | |||
Logger.getLogger(AdminUnsubscribeCommandHandler.class.getName()); | |||
|
|||
@Override | |||
public void handle(JID adminUser, JID targetUser, String... args) { | |||
if (args.length != 1) { | |||
Xmpp.sendMessage(adminUser, "No feed URL not specified"); | |||
return; | |||
} | |||
|
|||
URL feedUrl; | |||
try { | |||
feedUrl = new URL(args[0]); | |||
} catch (MalformedURLException err) { | |||
logger.log(Level.INFO, "URL parse exception", err); | |||
Xmpp.sendMessage(adminUser, "Feed URL is malformed"); | |||
return; | |||
} | |||
|
|||
final List<Subscription> subscriptions = | |||
Subscription.getSubscriptionsForUserAndFeedUrl(targetUser, feedUrl); | |||
|
|||
if (subscriptions.isEmpty()) { | |||
Xmpp.sendMessage(adminUser, "No subscriptions match."); | |||
} | |||
|
|||
for (Subscription subscription : subscriptions) { | |||
Hubs.sendRequestToHub(targetUser, subscription.getHubUrl(), feedUrl, false); | |||
} | |||
|
|||
Persistence.withManager(new Persistence.Closure() { | |||
@Override public void run(PersistenceManager manager) { | |||
manager.deletePersistentAll(subscriptions); | |||
} | |||
}); | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters