def generate_invite(self, owner_userid, recipients, sender_name, subj, msg, sender_email): """ Generates an invite request to a particular user. @param owner_username: User making the invite @type owner_username: String @param recipients: List of Zoto usernames @type recipients: List/tuple @param sender_name: Plaintext name of the sender (for personal greeting in the email) @type sender_name: String @param subj: Subject of the email @type subj: String @param msg: Body of the message (to be inserted into Zoto canned text) @type msg: String @param sender_email: Email address of the sender @type sender_email: String """ try: owner_userid = validation.cast_integer(owner_userid, 'owner_userid') rec = [] for email_addr in recipients: rec.append(validation.email(email_addr)) recipients = rec sender_name = validation.string(sender_name) subj = validation.string(subj) msg = validation.string(msg) sender_email = validation.email(sender_email) except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def publish_beta_blogger(self, owner_userid, export_info, image_ids, title, description, options): """ Publishes to beta-blogger. @param owner_username: User making the post @type owner_username: String @param export_id: User's export service they are wanting to publish with @type export_id: Integer @param media_ids: List of media id's to be published @type media_ids: List @param title: Title of the post @type title: String @param description: Body of the post @type description: String @param options: Options to be used for the post (alignment, etc) @type options: Dictionary """ self.log.debug("publish_blogger_beta: %s" % pformat(options)) try: owner_userid = validation.cast_integer(owner_userid, 'owner_userid') validation.sequence(image_ids, 'image_ids') title = validation.string(title) validation.string(description) options = validation.dict_keys(options, ('alignment', 'image_size'), 'options') except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def send_message(self, from_userid, to_userids, subject, body, reply_to_id): """ Sends a message to 1 or more recipients. @param from_username: User sending the message. @type from_username: String @param to_usernames: List of recipients @type to_usernames: List @param subject: Subject/heading of the message @type subject: String @param body: Body of the message @type body: String @param reply_to_id: Message being replied to, if applicable @type reply_to_id: Integer """ try: from_userid = validation.cast_integer(from_userid, 'from_userid') subject = validation.string(subject) validation.required(subject, 'subject') body = validation.string(body) validation.required(body, 'body') reply_to_id = validation.cast_integer(reply_to_id, 'reply_to_id') recipients = [] if not isinstance(to_userids, (list, tuple)): to_userids = [to_userids] for user in to_userids: recipients.append(validation.cast_integer(user, 'to_userid')) except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def share(self, owner_userid, recipients, sender_name, subject, message, album_ids): """ Sends an invite to the list of recipients, asking them to view the specified albums. @param owner_username: Owner of the albums @type owner_username: String @param recipients: List of recipients...each entry can be a contact list name, a username, or an email address. @type recipients: List/Tuple @param subject: Subject of the invite email @type subject: String @param message: Actual text of the email @type message: String @param album_ids: List of album id's @type album_ids: List/Tuple """ try: if not isinstance(recipients, (list, tuple)): recipients = [recipients] if not isinstance(album_ids, (list, tuple)): album_ids = [album_ids] owner_userid = validation.cast_integer(owner_userid, 'owner_userid') subject = validation.string(subject) message = validation.string(message) temp_ids = [] for album_id in album_ids: temp_ids.append(validation.cast_integer(album_id, 'album_id')) album_ids = temp_ids except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def create_contact_list(self, owner_userid, group_name): """ Adds a contact group to a user's account. @param owner_username: Account username. @type owner_username: String @param group_name: Name of the group to be added. @type group_name: String """ try: owner_userid = validation.cast_integer(owner_userid, "owner_userid") group_name = validation.string(group_name) except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def get_album_from_gallery_name(self, owner_userid, gallery_name): """ Tries to map an old 2.0 style gallery name (url) to a new album_id. @param owner_username: User who owns the album @type owner_username: String @param gallery_name: Old style gallery name @type gallery_name: String """ try: owner_userid = validation.cast_integer(owner_userid, 'owner_userid') gallery_name = validation.string(gallery_name) except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def check_album_title(self, owner_userid, title): """ Checks to see if an album with a certain title already exists for a particular user. @param owner_userid: User who would own the album. @type owner_userid: Integer @param title: Title to check @type title: String """ try: owner_userid = validation.cast_integer(owner_userid, 'owner_userid') title = validation.string(title) except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def check_set_title(self, owner_userid, title): """ Checks to see if a set with a certain title already exists for a particular user. @param owner_username: User who owns the set. @type owner_username: String @param title: Title to check @type title: String """ try: owner_username = validation.cast_integer(owner_userid, 'owner_userid') title = validation.string(title) except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def share(self, owner_userid, recipients, sender_name, subject, message, image_ids): """ Emails a list of photos to a list of recipients. @param owner_username: Owner of the image. @type owner_username: String @param recipients: List of recipients...each entry can be a contact list name, a username, or an email address. @type recipients: List/Tuple @param subject: Subject of the email to be sent @type subject: String @param message: Body of the email @type message: String @param media_ids: List of media id's @type media_ids: List/Tuple """ self.log.debug("inside images.share") try: if not isinstance(recipients, (list, tuple)): recipients = [recipients] if not isinstance(image_ids, (list, tuple)): image_ids = [image_ids] owner_userid = validation.cast_integer(owner_userid, 'owner_userid') sender_name = validation.string(sender_name) subject = validation.string(subject) message = validation.string(message) temp_ids = [] for image_id in image_ids: temp_ids.append(validation.cast_integer(image_id, 'image_id')) image_ids = temp_ids except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def check_contact_list_title(self, owner_userid, group_name): """ Changes the name of the specified user's group to the new name given @param owner_username: The groups owner. @type owner_username: String @param new_name: The name of the group to look for. @type new_name: String """ try: owner_userid = validation.cast_integer(owner_userid, "owner_userid") group_name = validation.string(group_name) except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def beta_blogger_get_blog_list(self, owner_userid, token): """ Gets a user's list of blogger blogs. @param owner_username: User to get blogs for. @type owner_username: String @param token: Auth token to use for communicating with beta blogger. @type token: String """ try: owner_userid = validation.cast_integer(owner_userid, 'owner_userid') token = validation.string(token) validation.required(token, 'token') except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def set_attr(self, owner_userid, set_id, key, value): """ Changes an attribute on a set. @param set_id: Set ID @type set_id: Integer @param key: Value to be changed @type key: String @param value: New value @type value: String """ try: set_id = validation.cast_integer(set_id, 'set_id') validation.oneof(key, self.valid_set_attrs, 'key') value = validation.string(value) except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def update_contact_list(self, owner_userid, group_id, new_name): """ Changes the name of the specified user's group to the new name given @param owner_username: The groups owner. @type owner_username: String @param group_id: Id of the group to be updated. @type group_name: Integer @param new_name: The new name of the group. @type new_name: String """ try: owner_userid = validation.cast_integer(owner_userid, "owner_userid") group_id = validation.cast_integer(group_id, 'group_id') new_name = validation.string(new_name) except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
def set_album_permission(self, owner_userid, album_id, perm_type, flag, groups): """ Sets the flag and groups for a specific perm type (view, tag, etc) @param owner_userid: User who owns the album @type owner_userid: Int @param album_id: ID of the album @type album_id: String @param perm_type: Permission being set @type perm_type: String @param flag: Permission value @type flag: Integer @param groups: (optional) groups to be added if flag = 2 @type groups: List """ owner_userid = validation.cast_integer(owner_userid, "owner_userid") album_id = validation.cast_integer(album_id, 'album_id') validation.oneof(perm_type, ('view', 'comment'), 'perm_type') flag = validation.cast_integer(flag, 'flag') group_list = [] group_val = "{}" if groups: for g in groups: validation.integer(g, 'group_id') group_list.append(validation.string(g)) group_val = "{%s}" % ', '.join(group_list) d = self.app.db.query( """ SELECT zoto_update_album_permission( %s, %s, %s, %s, %s) """, (owner_userid, album_id, perm_type, flag, group_val)) d.addCallback(lambda _: (0, "success")) d.addErrback(lambda _: (-1, _.getErrorMessage())) return d
def set_album_permission(self, owner_userid, album_id, perm_type, flag, groups): """ Sets the flag and groups for a specific perm type (view, tag, etc) @param owner_userid: User who owns the album @type owner_userid: Int @param album_id: ID of the album @type album_id: String @param perm_type: Permission being set @type perm_type: String @param flag: Permission value @type flag: Integer @param groups: (optional) groups to be added if flag = 2 @type groups: List """ owner_userid = validation.cast_integer(owner_userid, "owner_userid") album_id = validation.cast_integer(album_id, 'album_id') validation.oneof(perm_type, ('view', 'comment'), 'perm_type') flag = validation.cast_integer(flag, 'flag') group_list = [] group_val = "{}" if groups: for g in groups: validation.integer(g, 'group_id') group_list.append(validation.string(g)) group_val = "{%s}" % ', '.join(group_list) d = self.app.db.query(""" SELECT zoto_update_album_permission( %s, %s, %s, %s, %s) """, (owner_userid, album_id, perm_type, flag, group_val)) d.addCallback(lambda _: (0, "success")) d.addErrback(lambda _: (-1, _.getErrorMessage())) return d
def set_account_image_permission(self, userid, perm_type, flag, groups): """ Sets one of the account level image permissions for the specified user. @param userid: userid of the User to set permissions for @type userid: Int @param perm_type: Type of permission being set. one of (view, tag, comment, print, download, geotag, vote, blog) @type perm_type: String @param flag: Permission state - one of (0, 1, 2, 3) @type flag: Integer @param groups: If flag is 2 (private - some contacts), then this is the list of group ids applied. @type groups: List or None """ try: userid = validation.cast_integer(userid, 'userid') perm_type = validation.string(perm_type) flag = validation.cast_integer(flag, 'flag') validation.sequence(groups, 'groups') except errors.ValidationError, ex: return utils.return_deferred_error(ex.value)
@param groups: If flag is 2 (private - some contacts), then this is the list of group ids applied. @type groups: List or None """ try: userid = validation.cast_integer(userid, 'userid') perm_type = validation.string(perm_type) flag = validation.cast_integer(flag, 'flag') validation.sequence(groups, 'groups') except errors.ValidationError, ex: return utils.return_deferred_error(ex.value) group_list = [] if groups: for g in groups: validation.integer(g, 'group_id') group_list.append(validation.string(g)) group_val = "{%s}" % ', '.join(group_list) d = self.app.api.contacts.get_contact_groups(userid, 0, 0, "group_id-asc") else: group_val = None d = Deferred() d.callback([]) @stack def process_groups(result): if not result: if group_val: raise errors.AZTKError, "userid %s doesn't have any groups, but groups were specified" % userid else: user_groups = [] for group_rec in result:
@param groups: If flag is 2 (private - some contacts), then this is the list of group ids applied. @type groups: List or None """ try: userid = validation.cast_integer(userid, 'userid') perm_type = validation.string(perm_type) flag = validation.cast_integer(flag, 'flag') validation.sequence(groups, 'groups') except errors.ValidationError, ex: return utils.return_deferred_error(ex.value) group_list = [] if groups: for g in groups: validation.integer(g, 'group_id') group_list.append(validation.string(g)) group_val = "{%s}" % ', '.join(group_list) d = self.app.api.contacts.get_contact_groups( userid, 0, 0, "group_id-asc") else: group_val = None d = Deferred() d.callback([]) @stack def process_groups(result): if not result: if group_val: raise errors.AZTKError, "userid %s doesn't have any groups, but groups were specified" % userid else: user_groups = []