comparison data/plugin/script/account/subscribe.py @ 562:0a13d4186fa0

script.account.subscribe: introduced a cli script for subscribing/unsubscribing a user, members of a group or all valid users of the wiki to a page
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Thu, 07 Apr 2011 19:16:24 +0200
parents
children 127da830be6c
comparison
equal deleted inserted replaced
561:6a0ea7cf7c43 562:0a13d4186fa0
1 # -*- coding: iso-8859-1 -*-
2 """
3 MoinMoin - subscribes or unsubscribes users to a page
4
5 @copyright: 2011 MoinMoin:ReimarBauer
6 @license: GNU GPL, see COPYING for details.
7 """
8
9 from MoinMoin import user
10 from MoinMoin.Page import Page
11 from MoinMoin.script import MoinScript
12
13 class PluginScript(MoinScript):
14 """\
15 Purpose:
16 ========
17 This tool allows you to subscribe or unsubscribe users of a wiki to a page
18
19 Detailed Instructions:
20 ======================
21 General syntax: moin [options] account subscribe [subscribe-options]
22
23 [options] usually should be:
24 --config-dir=/path/to/my/cfg/ --wiki-url=http://wiki.example.org/
25
26 1. Required is one of the options --name, ---group, --all-users.
27 To subscribe a user to a page use the --name argument. For subscribe by a group of users
28 give the --group page argument. Or with --all-users you subscribe ALL users.
29 2. Required is also the pagename of the page to subscribe too
30 3. Optional the selected users could be unsubscribed by --unsubscribe
31 """
32
33 def __init__(self, argv, def_values):
34 MoinScript.__init__(self, argv, def_values)
35
36 self.parser.add_option(
37 "-u", "--user", dest="priviledged_user",
38 help="User as whom the homepage creation operation will be performed as."
39 )
40
41 self.parser.add_option(
42 "-n", "--name", dest="user_subscribe",
43 help="The name of the user to subscribe to a page."
44 )
45
46 self.parser.add_option(
47 "-g", "--group", dest="name_of_group_page",
48 help="The name of the group page to select users to subscribe to a page"
49 )
50
51 self.parser.add_option(
52 "-a", "--all-users", dest="all_users", action="store_true",
53 help="All existing users of the wiki to subscribe to a page"
54 )
55
56 self.parser.add_option(
57 "-r", "--unsubscribe", dest="unsubscribe", action="store_true",
58 help="unsubscribe users of a wiki page"
59 )
60
61 self.parser.add_option(
62 "-p", "--pagename", dest="pagename",
63 help="The name of the page to subscribe"
64 )
65
66
67 def write_subscription(self, account, pagename, unsubscribe=False):
68 # subscribes to a page
69 if account.exists() and not account.disabled and Page(self.request, pagename).exists():
70 if unsubscribe:
71 account.unsubscribe(pagename)
72 else:
73 account.subscribe(pagename)
74 account.save()
75
76 def mainloop(self):
77 # we don't expect non-option arguments
78 self.init_request()
79 request = self.request
80 # Check for user
81 if self.options.priviledged_user:
82 uid = user.getUserId(request, self.options.priviledged_user)
83 request.user = user.User(request, uid)
84 # Check for Group definition
85 members = []
86 if self.options.user_subscribe:
87 members = [self.options.user_subscribe, ]
88 elif self.options.name_of_group_page:
89 members = request.groups.get(self.options.name_of_group_page, [])
90 elif self.options.all_users:
91 uids = user.getUserList(request)
92 members = [user.User(request, uid).name for uid in uids]
93
94 if not members:
95 print "No user selected!"
96 return
97 if not self.options.pagename:
98 print "No pagename given!"
99 return
100
101 # loop through members for doing the subscription
102 for name in members:
103 uid = user.getUserId(request, name)
104 account = user.User(request, uid)
105 self.write_subscription(account, self.options.pagename, unsubscribe=self.options.unsubscribe)
106