Example #1
0
def groups_invite_api(request, group_name, uid_or_email, uninvite=False):
	"""
	API for adding or removing group members, or group invitations
	"""
	if request.method != "POST":
		return jsonResponse({"error": "Unsupported HTTP method."})
	group = Group().load({"name": group_name})
	if not group:
		return jsonResponse({"error": "No group named %s." % group_name})
	if request.user.id not in group.admins:
		return jsonResponse({"error": "You must be a group admin to invite new members."})

	user = UserProfile(email=uid_or_email)
	if not user.exists():
		if uninvite:
			group.remove_invitation(uid_or_email)
			message = "Invitation removed."
		else:
			group.invite_member(uid_or_email, request.user.id)
			message = "Invitation sent."
	else:
		is_new_member = not group.is_member(user.id)

		if is_new_member:
			group.add_member(user.id)
			from sefaria.model.notification import Notification
			notification = Notification({"uid": user.id})
			notification.make_group_add(adder_id=request.user.id, group_name=group_name)
			notification.save()
			message = "Group member added."
		else:
			message = "%s is already a member of this group." % user.full_name

	group_content = group.contents(with_content=True, authenticated=True)
	return jsonResponse({"group": group_content, "message": message})
Example #2
0
def broadcast_sheet_publication(publisher_id, sheet_id):
	"""
	Notify everyone who follows publisher_id about sheet_id's publication
	"""
	followers = FollowersSet(publisher_id)
	for follower in followers.uids:
		n = Notification({"uid": follower})
		n.make_sheet_publish(publisher_id=publisher_id, sheet_id=sheet_id)
		n.save()
Example #3
0
	def follow(self):
		db.following.save(vars(self))

		# Notification for the Followee
		notification = Notification({"uid": self.followee})
		notification.make_follow(follower_id=self.follower)
		notification.save()
		
		return self
Example #4
0
def add_like_to_sheet(sheet_id, uid):
	"""
	Add uid as a liker of sheet_id.
	"""
	db.sheets.update({"id": sheet_id}, {"$addToSet": {"likes": uid}})
	sheet = get_sheet(sheet_id)

	notification = Notification({"uid": sheet["owner"]})
	notification.make_sheet_like(liker_id=uid, sheet_id=sheet_id)
	notification.save()
Example #5
0
	def follow(self):
		from sefaria.model.notification import Notification

		db.following.save(vars(self))

		# Notification for the Followee
		notification = Notification({"uid": self.followee})
		notification.make_follow(follower_id=self.follower)
		notification.save()
		
		return self
Example #6
0
def broadcast_sheet_publication(publisher_id, sheet_id):
    """
	Notify everyone who follows publisher_id about sheet_id's publication
	"""
    followers = FollowersSet(publisher_id)
    for follower in followers.uids:
        n = Notification({"uid": follower})
        n.make_sheet_publish(publisher_id=publisher_id, sheet_id=sheet_id)
        n.save()
Example #7
0
def add_like_to_sheet(sheet_id, uid):
    """
	Add uid as a liker of sheet_id.
	"""
    db.sheets.update({"id": sheet_id}, {"$addToSet": {"likes": uid}})
    sheet = get_sheet(sheet_id)

    notification = Notification({"uid": sheet["owner"]})
    notification.make_sheet_like(liker_id=uid, sheet_id=sheet_id)
    notification.save()
Example #8
0
def broadcast_sheet_publication(publisher_id, sheet_id):
    """
	Notify everyone who follows publisher_id about sheet_id's publication
	"""
    #todo: work on batch creation / save pattern
    followers = FollowersSet(publisher_id)
    for follower in followers.uids:
        n = Notification({"uid": follower})
        n.make_sheet_publish(publisher_id=publisher_id, sheet_id=sheet_id)
        n.save()
        UserStory.from_sheet_publish(follower, publisher_id, sheet_id).save()
Example #9
0
    def follow(self):
        from sefaria.model.notification import Notification

        db.following.save(vars(self))

        # Notification for the Followee
        notification = Notification({"uid": self.followee})
        notification.make_follow(follower_id=self.follower)
        notification.save()

        return self
Example #10
0
def collections_invite_api(request, slug, uid_or_email, uninvite=False):
    """
    API for adding or removing collection members, or collection invitations
    """
    if request.method != "POST":
        return jsonResponse({"error": "Unsupported HTTP method."})
    collection = Collection().load({"slug": slug})
    if not collection:
        return jsonResponse(
            {"error": "No collection with slug {}.".format(slug)})
    if request.user.id not in collection.admins:
        return jsonResponse(
            {"error": "You must be a collection owner to invite new members."})

    user = UserProfile(email=uid_or_email)
    if not user.exists():
        if uninvite:
            collection.remove_invitation(uid_or_email)
            message = "Invitation removed."
        else:
            collection.invite_member(uid_or_email, request.user.id)
            message = "Invitation sent."
    else:
        is_new_member = not collection.is_member(user.id)

        if is_new_member:
            collection.add_member(user.id)
            from sefaria.model.notification import Notification
            notification = Notification({"uid": user.id})
            notification.make_collection_add(adder_id=request.user.id,
                                             collection_slug=collection.slug)
            notification.save()
            message = "Collection editor added."
        else:
            message = "%s is already a editor of this collection." % user.full_name

    collection_content = collection.contents(with_content=True,
                                             authenticated=True)
    del collection_content["lastModified"]
    return jsonResponse({"collection": collection_content, "message": message})
Example #11
0
def groups_invite_api(request, group_name, uid_or_email, uninvite=False):
    """
	API for adding or removing group members, or group invitations
	"""
    if request.method != "POST":
        return jsonResponse({"error": "Unsupported HTTP method."})
    group = Group().load({"name": group_name})
    if not group:
        return jsonResponse({"error": "No group named %s." % group_name})
    if request.user.id not in group.admins:
        return jsonResponse(
            {"error": "You must be a group admin to invite new members."})

    user = UserProfile(email=uid_or_email)
    if not user.exists():
        if uninvite:
            group.remove_invitation(uid_or_email)
            message = "Invitation removed."
        else:
            group.invite_member(uid_or_email, request.user.id)
            message = "Invitation sent."
    else:
        is_new_member = not group.is_member(user.id)

        if is_new_member:
            group.add_member(user.id)
            from sefaria.model.notification import Notification
            notification = Notification({"uid": user.id})
            notification.make_group_add(adder_id=request.user.id,
                                        group_name=group_name)
            notification.save()
            message = "Group member added."
        else:
            message = "%s is already a member of this group." % user.full_name

    group_content = group.contents(with_content=True, authenticated=True)
    return jsonResponse({"group": group_content, "message": message})