def tag_item (tags, user, item_oid, group, comment = None, is_user=False): """ all tags are applied through this function, which keeps the various databases consistent with each other.""" user_id = user.get_user_id() tags = qon.tags.standardize_tags(tags) # clear out any removed tags tags_db = get_tags_database() tidb = get_tagged_item_database() if is_user: user_db = get_user_database() # what gets removed? what gets added? old_tags = tidb.get_tags(item_oid, user_id) tags_to_remove = [tag for tag in old_tags if tag not in tags] tags_to_add = [tag for tag in tags if tag not in old_tags] if tags_to_remove: # remove user from removed tags tags_db.remove_tags(tags_to_remove, item_oid, user_id) if group: group.remove_tags(tags_to_remove, item_oid, user_id) # remove the tag from the user's list too. user.remove_tags(tags_to_remove, item_oid) if is_user: user_db.remove_tags(tags_to_remove, item_oid, user_id) # # if tags_to_add: # add to the global database tags_db.tag_item(user.get_user_id(), item_oid, tags, comment) # group gets its tag information if group: group.tag_item(user_id, item_oid, tags_to_add, comment) # update the user's tag cloud user.tag_item(tags, item_oid) if is_user: user_db.tag_item(user_id, item_oid, tags_to_add, comment) # # get_transaction().commit()
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_cancel_karma_given(user, staff_user): if not staff_user.is_staff() and not staff_user.is_admin(): raise AccessError # since this is not reversible, log all data (which would otherwise be lost) karma_given_data = user.karma_given_report() karma_given = ['%s:%d' % (u.get_user_id(), karma) for u, karma in karma_given_data] qon.log.admin_info('CancelUserKarmaGiven\t%s\t%s' % (user.get_user_id(), ",".join(karma_given))) user.cancel_karma_given()
def _get_session_user_id(self, session_id): """Return user_id of user referred to by session_id, or None.""" session = self._get_session(session_id) if not session: return None user = session.user if user: return user.get_user_id() else: return None
def _create_login_bundle(self, user): """Given a user, return a login_bundle for the user.""" (digest, creation, nonce) = qon.atom.create_password_digest(user.get_password_hash()) atom_tag = atom_id(user) return dict( username=user.get_user_id(), passdigest=digest, created=creation, nonce=nonce, atom_tag=atom_tag, )