def group_set_settings(user, group, **kwargs): if not group_can_manage(user, group): raise AccessError _set_attributes(group, **kwargs) transaction_commit(None, 'GroupSetSettings') # moved from group/form.ptl/SettingsForm.commit() qon.search.searchengine.notify_edited_group(group)
def user_new(email): # create user and get the initial password in plaintext. email = _unicode_fix(email) user, password = get_user_database().new_user_from_email(email) transaction_commit(None, 'NewUser') # moved from user.ptl/NewUserForm.commit() # send email e = url_quote(email) p = url_quote(password) s = url_quote("Sign in") message = _(_new_user_message) % dict(email=email, password=password, auto_login_url=messages.login_url + "?email=" + e + "&password="******"&submit-login="******"&from_url=Y") extra_headers = ['Content-Type: text/html'] # because of the href sendmail("Welcome to ned.com", message, [email], extra_headers=extra_headers) # send pm using _live_tmpl_pm_new_user in sitedev as the template template_text = qon.util.get_page_template('pm_new_user', format='text') if template_text: message_anon_send(user, "Welcome to ned.com!", template_text, True) # add orientation page to all new users' watch lists try: orientation = get_group_database()['help'].get_wiki().pages['start_here'] user.get_watch_list().watch_item(orientation) except: pass qon.search.searchengine.notify_new_user(user) return (email, message)
def user_delete(user): """Deletes a user object from the ZODB and the Search DB. Does not attempt to find items authored by the user and delete those too. """ get_user_database().remove_user(user.get_user_id()) transaction_commit(None, 'AdminDeleteUser') # moved from admin.ptl/DeleteUserForm.commit() qon.search.searchengine.notify_deleted_user(user)
def user_set_settings(user, **kwargs): """Set user profile: name Full name bio about-me text anon_blog 'yes' if anon users can read personal news email_notify 'yes' if user should receive e-mail notices of incoming messages """ user.set_contact_name(_unicode_fix(kwargs['name'])) user.bio = _unicode_fix(kwargs['bio']) user.location = _unicode_fix(kwargs['location']) user.latitude = kwargs['latitude'] user.longitude = kwargs['longitude'] user.deliciousID = kwargs['deliciousID'] user.flickrID = kwargs['flickrID'] user.skypeID = kwargs['skypeID'] user.blogURL = kwargs['blogURL'] user.get_user_data().set_anon_can_read_blog(kwargs['anon_blog'] == 'yes') user.set_email_notify(kwargs['email_notify'] == 'yes') user.set_copy_self(kwargs['copy_self'] == 'yes') transaction_commit(user, 'UserPrefs') # moved from user.ptl/UserPrefsForm.commit() qon.search.searchengine.notify_edited_user(user) get_observe_database().notify_changed(user) # FIXME this should be in user.py somewhere
def user_set_disabled(user, disabled): user.set_disabled(disabled) if disabled: note = 'AdminDisableUser' else: note = 'AdminEnableUser' transaction_commit(None, note) # moved from admin.ptl/UserUI.enable() & admin.ptl/DisableUserForm.commit()
def group_invite_user(user, group, email, inviter): """Invite email to join group. May raise smtplib.SMTPRecipientsRefused if server rejects email. """ if not group.is_accepted() or not group.get_members().can_manage(user): raise AccessError group.add_invitation(email, inviter) transaction_commit(inviter, 'InviteToGroup') # moved from group/form.ptl/InviteForm.commit() try: user = get_user_database().get_user_by_email(email) except KeyError: # e-mail address is not registered, send an e-mail (rather than internal message) subject=_(_email_invite_subject) % dict(group_name=group.name) body=_(_email_invite_body) % dict(email=email, home_url=messages.home_url, inviter=qon.ui.blocks.user.display_name_plain(inviter), group_name=qon.ui.blocks.group.display_name_plain(group)) sendmail(subject, body, [email]) else: message_send(inviter, user, subject=_(_message_invite_subject) % dict(group_name=group.name), body=_(_message_invite_body) % dict( email=email, inviter=qon.ui.blocks.user.display_name_plain(inviter), group_name=qon.ui.blocks.group.display_name_plain(group) ) )
def message_send(fr, to, subject, body, suppress_email=False, copy_self=False): """Send a message to one or more recipients.""" subject = _unicode_fix(subject) body = _unicode_fix(body) if type(to) is not list: to = [to] # only send messages to users to = [recipient for recipient in to if type(recipient) is User] for recipient in to: msg = message.Message(sender=fr, subject=subject, body=body) recipient.add_message(msg) #qon.log.admin_info('added message for %s' % qon.ui.blocks.util.display_name_plain(recipient)) # log the activity fr.get_user_data().get_activity().new_pm_sent() # let's commit here so that if the commit fails, we won't accidentally # send out an email notice with the wrong msg # in the URL transaction_commit(None, 'NewMessage') # email notification if (not suppress_email): for recipient in to: if recipient.email_notify(): message_email(recipient, msg) # email notification to self if (not suppress_email) and copy_self: message_email_copy_self(fr, to, msg)
def ticket_new_item(tracker, user, title, category, priority, text): title = _unicode_fix(title) text = _unicode_fix(text) t = tracker.new_ticket(user, title, category, priority, text) transaction_commit(user, 'NewTicket') # moved from ticket.ptl/NewTicketForm.commit() return t
def wiki_new_page_like(wiki, page, author): np = wiki.new_page(wiki.get_unique_name(page)) np.versions[-1].set_raw('<include %s latest>\n' % page.name) np.versions[-1].set_author(author) transaction_commit(None, 'NewLikeWikiPage') # moved from wiki/wiki.ptl/WikiPageUI.newlike() qon.search.searchengine.notify_new_wiki_page(np) return np
def poll_create_custom(polls, creator, title, description, end_date, choices, custom): title = _unicode_fix(title) description = _unicode_fix(description) choices = [_unicode_fix(x) for x in choices] """Create a custom poll. custom is a dict with the following keys: min_choice max_choice vote_access results_access intermediate_access vote_required_to_view voter_can_revise display_voters min_karma karma_cost Raises KeyError if custom contains keys not recognized by PollData. """ poll = qon.poll.Poll(creator=creator, title=title, description=description, end_date=end_date, choices=choices) # set custom settings poll.get_data().set_extended_data(custom) poll = polls.add_poll(poll) transaction_commit(None, 'PollCreateCustom') qon.search.searchengine.notify_new_poll(poll) return poll
def user_delete_email(user, email): """Delete a confirmed or unconfirmed e-mail. Raise KeyError if attempt to delete last e-mail. Raise ValueError if email is not in user's email list. """ get_user_database().remove_user_email(user, email) transaction_commit(user, 'UserDeleteEmail') # moved from user.ptl/UserDeleteEmailForm.commit() qon.search.searchengine.notify_edited_user(user)
def do_all_user_blogitems(): """ iterate through each user and index each news item """ i = 1 for userid, user in db.user_db.root.items(): for bi in user.get_blog().get_items(): print "%s) %s BlogItem: %s" % (i, userid, bi.title) bi.populate_parent_blogitem_for_comments() transaction_commit() i+=1
def upgrade_invalidate_html_caches(): """Invalidate all HTML caches""" from base import get_group_database group_db = get_group_database() for g in group_db.root.values(): for p in g.wiki.pages.values(): p.invalidate_html_cache() transaction_commit()
def upgrade_refresh_html_caches(): """Refresh all html caches.""" from base import get_group_database group_db = get_group_database() for g in group_db.root.values(): for p in g.wiki.pages.values(): html = p.get_cached_html() transaction_commit()
def do_all_group_blogitems(): """ iterate through each group and index each discussion topic """ i = 1 for groupid, group in db.group_db.root.items(): for bi in group.get_blog().get_items(): print "%s) %s BlogItem: %s" % (i, groupid, bi.title) bi.populate_parent_blogitem_for_comments() transaction_commit() i+=1
def update_stats(): """Update the expensive site-wide stats.""" list_db = get_list_database() list_db.group_stats_force_update() transaction_commit(None, 'GroupStatsUpdate') list_db.user_stats_force_update() transaction_commit(None, 'UserStatsUpdate')
def upgrade_cap_subpoints(): """Remove pending subpoints from users whose banks are capped.""" from qon.base import get_user_database, transaction_commit for user_id, user in get_user_database().root.iteritems(): if user.bank_is_capped(): if user._HasKarmaBank__subpoints > 0: user._HasKarmaBank__subpoints = 0 transaction_commit(None, 'UpgradeCapSubpoints')
def upgrade_inbound_refs(): """Recreate all pages' inbound_references.""" from base import get_group_database group_db = get_group_database() for g in group_db.root.values(): for p in g.wiki.pages.values(): refs = g.wiki.references_to(p) transaction_commit() print g.get_user_id()
def upgrade_invalidate_outbound_refs(): """Invalidate all outbound references due to type change.""" from base import get_group_database group_db = get_group_database() for g in group_db.root.values(): for p in g.wiki.pages.values(): p.outbound_references = None p.invalidate_html_cache() transaction_commit()
def karma_give_good(fr, to, message=None, message_anon=True, karma=qon.karma.HasKarma.good_karma): message = _unicode_fix(message) if to.can_get_karma_from(fr): try: fr.give_karma(to, karma) _karma_send_message(fr, to, 'positive', '+%d' % karma, message, message_anon) transaction_commit(fr, 'KarmaGiveGood') qon.search.searchengine.notify_karma_given(to) except qon.karma.NoKarmaToGive: pass
def file_upload(group, dir, owner, source_path, filename, desc): filename = _unicode_fix(filename) desc = _unicode_fix(desc) sf = group.file_db.new_file( source_path=source_path, dir=dir) sf.filename = filename sf.description = desc sf.owner = owner transaction_commit(None, 'Upload') # moved from file.ptl/UploadForm.commit()
def user_new_password(user, email): password = user.generate_password() transaction_commit(user, 'NewPassword') # moved from user.ptl/NewPasswordForm.commit() message = _(_new_password_message) % dict( email=email, password=password, ) sendmail("ned.com New Password", message, [email]) return (email, message)
def poll_vote(poll, user, choice_list): if type(choice_list) is not list: choice_list = [choice_list] try: choices = poll.choice_list_to_choices(choice_list) poll.record_vote(user, choices) except ValueError: return None transaction_commit(None, 'PollVote') qon.search.searchengine.notify_poll_vote(poll) return poll
def blog_new_item(blog, author, title, summary, main='', no_mod=1, no_pay=0): """Create a new blog item. If no_mod, don't assign negative karma.""" title = _unicode_fix(title) summary = _unicode_fix(summary) main = _unicode_fix(main) new_item = blog.new_item(author, title, summary, main, no_mod=no_mod, no_pay=no_pay) if new_item: author.notify_authored_item(new_item) transaction_commit(author, 'NewBlogItem') # moved from blog/form.ptl/NewBlogItemForm.commit() & wiki/form.ptl/CommentItemForm.commit() qon.search.searchengine.notify_new_blog_item(new_item) return new_item
def blog_undelete_item(item): item.set_deleted(False) transaction_commit(None, 'UnDeleteBlogItem') # moved from blog/form.ptl/DeleteItemForm.commit() if item.title == 'comment': # NON-CRITICAL TO DO: handle deleted comments--will need access to the # blog item to which this comment refers. # One way to do this is to add a field to BlogItem called hc # which points to the HasComments class that the comment belongs to pass else: # handle undeleted blog entries qon.search.searchengine.notify_edited_blog_item(item)
def blog_delete_item(item, note=None): item.set_deleted(True) if note: item.set_deleted_note(note) transaction_commit(None, 'DeleteBlogItem') # moved from blog/form.ptl/DeleteItemForm.commit() if item.title == 'comment' or item.not_watchable: # XXX hack to find comment assert(item.parent_blogitem) qon.search.searchengine.notify_deleted_blog_comment(item) else: # handle deleted blog entries qon.search.searchengine.notify_deleted_blog_item(item)
def blog_new_comment(item, author, title, summary, main): title = _unicode_fix(title) summary = _unicode_fix(summary) main = _unicode_fix(main) new_comment = item.new_comment(author, title, summary, main) author.notify_authored_comment(new_comment, item) transaction_commit(author, 'CommentBlogItem') # moved from blog/form.ptl/CommentItemForm.commit() & wiki/form.ptl/CommentItemForm.commit() if new_comment: qon.search.searchengine.notify_new_blog_comment(item, new_comment) return new_comment
def file_replace(group, dir, owner, path, source_path, filename, desc): """Replace file with path=path in dir=dir, with data at source_path.""" filename = _unicode_fix(filename) desc = _unicode_fix(desc) sf = group.file_db.replace_file( path=path, source_path=source_path, dir=dir) sf.filename = filename sf.description = desc sf.owner = owner transaction_commit(None, 'UploadReplace') # moved from file.ptl/UploadReplaceForm.commit()
def group_decay_inactive_karma(): """Decay karma of inactive blog items.""" decayed_items = [] for group_id, group in get_group_database().root.iteritems(): decayed_items.extend(group.blog.decay_inactive_items()) decayed_items.extend(group.wiki.decay_inactive_items()) transaction_commit(None, 'DecayInactive') # notify the search engine that the items' karma changed. # The reason we do the notification here, rather than in blog.decay_inactive_items() itself. # is that it's nice keeping all the search engine notifications localized # to this file, rather than sprinkled in the kernel. for item in decayed_items: qon.search.searchengine.notify_karma_given(item)
def poll_create(polls, creator, title, description, end_date, choices): title = _unicode_fix(title) description = _unicode_fix(description) choices = [_unicode_fix(x) for x in choices] poll = qon.poll.Poll(creator=creator, title=title, description=description, end_date=end_date, choices=choices) poll = polls.add_poll(poll) transaction_commit(None, 'PollCreate') qon.search.searchengine.notify_new_poll(poll) return poll