diff --git a/migrate.py b/migrate.py index 70308570..5f381715 100644 --- a/migrate.py +++ b/migrate.py @@ -83,6 +83,14 @@ def topics(export_topics, topics_by_slug, topics_by_oid, cats_data, tags_data): if len(sys.argv) > 2: limit = int(sys.argv[2]) print('migrating %d topics...' % limit) counter = 0 + for tag in tags_data: + old_id = tag["createdBy"] + tag["createdBy"] = user_id_map.get(old_id, 0) + topic = migrateTag(tag) + topics_by_title[topic['title']] = topic + topics_by_oid[topic['tag_id']] = topic + if not topics_by_slug.get(topic['slug']): topics_by_slug[topic['slug']] = topic + counter += 1 for cat in cats_data: old_id = cat["createdBy"] # cat["createdBy"] = user_id_map[old_id] @@ -90,15 +98,9 @@ def topics(export_topics, topics_by_slug, topics_by_oid, cats_data, tags_data): except Exception as e: raise e topics_by_oid[topic['cat_id']] = topic topics_by_slug[topic['slug']] = topic + topics_by_title[topic['title']] = topic counter += 1 - for tag in tags_data: - old_id = tag["createdBy"] - tag["createdBy"] = user_id_map.get(old_id, 0) - topic = migrateTag(tag) - topics_by_oid[topic['tag_id']] = topic - if not topics_by_slug.get(topic['slug']): topics_by_slug[topic['slug']] = topic - counter += 1 - export_topics = dict(topics_by_slug.items()) # sorted(topics_by_slug.items(), key=lambda item: str(item[1]['createdAt']))) # NOTE: sorting does not work :) + export_topics = dict(topics_by_title.items()) def shouts(content_data, shouts_by_slug, shouts_by_oid): ''' migrating content items one by one ''' diff --git a/migration/content/.DS_Store b/migration/content/.DS_Store deleted file mode 100644 index 5b679579..00000000 Binary files a/migration/content/.DS_Store and /dev/null differ diff --git a/migration/content/article/.gitkeep b/migration/content/article/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/migration/content/image/.gitkeep b/migration/content/image/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/migration/content/music/.gitkeep b/migration/content/music/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/migration/content/prose/.gitkeep b/migration/content/prose/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/migration/content/video/.gitkeep b/migration/content/video/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/resolvers/__init__.py b/resolvers/__init__.py index 736682fe..7d164795 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -7,7 +7,8 @@ from resolvers.topics import topic_subscribe, topic_unsubscribe, topics_by_autho topics_by_community, topics_by_slugs from resolvers.comments import create_comment, delete_comment, update_comment, rate_comment from resolvers.collab import get_shout_proposals, create_proposal, delete_proposal, \ - update_proposal, rate_proposal, decline_proposal, disable_proposal, accept_proposal + update_proposal, rate_proposal, decline_proposal, disable_proposal, accept_proposal, \ + invite_author, remove_author from resolvers.editor import create_shout, delete_shout, update_shout from resolvers.community import create_community, delete_community, get_community, get_communities @@ -72,5 +73,7 @@ __all__ = [ "disable_proposal", "accept_proposal", "decline_proposal", - "delete_proposal" + "delete_proposal", + "invite_author", + "remove_author" ] diff --git a/resolvers/collab.py b/resolvers/collab.py index 733fbf7a..8131cc51 100644 --- a/resolvers/collab.py +++ b/resolvers/collab.py @@ -189,3 +189,56 @@ async def decline_proposal(_, info, id): await ProposalStorage.put(result) return {} + + +@mutation.field("inviteAuthor") +@login_required +async def invite_author(_, author_slug, shout): + auth = info.context["request"].auth + user_id = auth.user_id + + with local_session() as session: + shout = session.query(Shout).filter(Shout.slug == shout).first() + if not shout: + return {"error": "invalid shout slug"} + authors = [author.id for author in shout.authors] + if user_id not in authors: + return {"error": "access denied"} + author = session.query(User).filter(User.slug == author_slug).first() + if author.id in authors: + return {"error": "already added"} + shout.authors.append(author) + session.commit() + + # result = Result("INVITED") + # FIXME: await ShoutStorage.put(result) + + # TODO: email notify + + return {} + +@mutation.field("removeAuthor") +@login_required +async def invite_author(_, author_slug, shout): + auth = info.context["request"].auth + user_id = auth.user_id + + with local_session() as session: + shout = session.query(Shout).filter(Shout.slug == shout).first() + if not shout: + return {"error": "invalid shout slug"} + authors = [author.id for author in shout.authors] + if user_id not in authors: + return {"error": "access denied"} + author = session.query(User).filter(User.slug == author_slug).first() + if author.id not in authors: + return {"error": "not in authors"} + shout.authors.remove(author) + session.commit() + + # result = Result("INVITED") + # FIXME: await ShoutStorage.put(result) + + # TODO: email notify + + return {} \ No newline at end of file diff --git a/schema.graphql b/schema.graphql index 81ee53a4..a5b77615 100644 --- a/schema.graphql +++ b/schema.graphql @@ -137,6 +137,10 @@ type Mutation { updateCommunity(community: CommunityInput!): Community! deleteCommunity(id: Int!): Result! + # collab + inviteAuthor(author: String!, shout: String!): Result! + removeAuthor(author: String!, shout: String!): Result! + # proposal createProposal(body: String!, range: String): Proposal! updateProposal(body: String!, range: String): Proposal!