shout under organization
This commit is contained in:
parent
f37c1f4839
commit
a146a8dd1d
|
@ -9,9 +9,17 @@ from orm.base import Base
|
||||||
class Shout(Base):
|
class Shout(Base):
|
||||||
__tablename__ = 'shout'
|
__tablename__ = 'shout'
|
||||||
|
|
||||||
|
id = None
|
||||||
|
|
||||||
|
slug: str = Column(String, primary_key=True)
|
||||||
|
org: str = Column(String, nullable=False)
|
||||||
author_id: str = Column(ForeignKey("user.id"), nullable=False, comment="Author")
|
author_id: str = Column(ForeignKey("user.id"), nullable=False, comment="Author")
|
||||||
body: str = Column(String, nullable=False, comment="Body")
|
body: str = Column(String, nullable=False, comment="Body")
|
||||||
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
createdAt: str = Column(DateTime, nullable=False, default = datetime.now, comment="Created at")
|
||||||
updatedAt: str = Column(DateTime, nullable=True, comment="Updated at")
|
updatedAt: str = Column(DateTime, nullable=True, comment="Updated at")
|
||||||
|
replyTo: str = Column(ForeignKey("shout.slug"), nullable=True)
|
||||||
|
versionOf: str = Column(ForeignKey("shout.slug"), nullable=True)
|
||||||
|
tags: str = Column(String, nullable=True)
|
||||||
|
topics: str = Column(String, nullable=True)
|
||||||
|
|
||||||
# TODO: add all the fields
|
# TODO: add all the fields
|
||||||
|
|
|
@ -9,32 +9,49 @@ from settings import SHOUTS_REPO
|
||||||
import subprocess
|
import subprocess
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
class GitTask:
|
class GitTask:
|
||||||
|
|
||||||
queue = asyncio.Queue()
|
queue = asyncio.Queue()
|
||||||
|
|
||||||
def __init__(self, shout_id, shout_body, username, user_email, comment):
|
def __init__(self, input, username, user_email, comment):
|
||||||
self.shout_id = shout_id;
|
self.slug = input["slug"];
|
||||||
self.shout_body = shout_body;
|
self.org = input["org"];
|
||||||
|
self.shout_body = input["body"];
|
||||||
self.username = username;
|
self.username = username;
|
||||||
self.user_email = user_email;
|
self.user_email = user_email;
|
||||||
self.comment = comment;
|
self.comment = comment;
|
||||||
|
|
||||||
GitTask.queue.put_nowait(self)
|
GitTask.queue.put_nowait(self)
|
||||||
|
|
||||||
def execute(self):
|
def init_repo(self):
|
||||||
cmd = "cd %s; git checkout master" % (SHOUTS_REPO)
|
repo_path = "%s/%s" % (SHOUTS_REPO, self.org)
|
||||||
|
|
||||||
|
Path(repo_path).mkdir()
|
||||||
|
|
||||||
|
cmd = "cd %s && git init && touch initial && git add initial && git commit -m 'init repo'" % (repo_path)
|
||||||
output = subprocess.check_output(cmd, shell=True)
|
output = subprocess.check_output(cmd, shell=True)
|
||||||
print(output)
|
print(output)
|
||||||
|
|
||||||
shout_filename = "shout%s.md" % (self.shout_id)
|
def execute(self):
|
||||||
shout_full_filename = "%s/%s" % (SHOUTS_REPO, shout_filename)
|
repo_path = "%s/%s" % (SHOUTS_REPO, self.org)
|
||||||
|
|
||||||
|
if not Path(repo_path).exists():
|
||||||
|
self.init_repo()
|
||||||
|
|
||||||
|
cmd = "cd %s && git checkout master" % (repo_path)
|
||||||
|
output = subprocess.check_output(cmd, shell=True)
|
||||||
|
print(output)
|
||||||
|
|
||||||
|
shout_filename = "%s.md" % (self.slug)
|
||||||
|
shout_full_filename = "%s/%s" % (repo_path, shout_filename)
|
||||||
with open(shout_full_filename, mode='w', encoding='utf-8') as shout_file:
|
with open(shout_full_filename, mode='w', encoding='utf-8') as shout_file:
|
||||||
shout_file.write(self.shout_body)
|
shout_file.write(self.shout_body)
|
||||||
|
|
||||||
author = "%s <%s>" % (self.username, self.user_email)
|
author = "%s <%s>" % (self.username, self.user_email)
|
||||||
cmd = "cd %s; git add %s; git commit -m '%s' --author='%s'" % \
|
cmd = "cd %s && git add %s && git commit -m '%s' --author='%s'" % \
|
||||||
(SHOUTS_REPO, shout_filename, self.comment, author)
|
(repo_path, shout_filename, self.comment, author)
|
||||||
output = subprocess.check_output(cmd, shell=True)
|
output = subprocess.check_output(cmd, shell=True)
|
||||||
print(output)
|
print(output)
|
||||||
|
|
||||||
|
@ -63,7 +80,7 @@ async def top_shouts(_, info):
|
||||||
|
|
||||||
@mutation.field("createShout")
|
@mutation.field("createShout")
|
||||||
@login_required
|
@login_required
|
||||||
async def create_shout(_, info, body):
|
async def create_shout(_, info, input):
|
||||||
auth = info.context["request"].auth
|
auth = info.context["request"].auth
|
||||||
user_id = auth.user_id
|
user_id = auth.user_id
|
||||||
|
|
||||||
|
@ -71,16 +88,21 @@ async def create_shout(_, info, body):
|
||||||
user = session.query(User).filter(User.id == user_id).first()
|
user = session.query(User).filter(User.id == user_id).first()
|
||||||
|
|
||||||
new_shout = Shout.create(
|
new_shout = Shout.create(
|
||||||
|
slug = input["slug"],
|
||||||
|
org = input["org"],
|
||||||
author_id = user_id,
|
author_id = user_id,
|
||||||
body = body
|
body = input["body"],
|
||||||
|
replyTo = input.get("replyTo"),
|
||||||
|
versionOf = input.get("versionOf"),
|
||||||
|
tags = input.get("tags"),
|
||||||
|
topics = input.get("topics")
|
||||||
)
|
)
|
||||||
|
|
||||||
task = GitTask(
|
task = GitTask(
|
||||||
new_shout.id,
|
input,
|
||||||
body,
|
|
||||||
user.username,
|
user.username,
|
||||||
user.email,
|
user.email,
|
||||||
"new shout %s" % (new_shout.id)
|
"new shout %s" % (new_shout.slug)
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -22,6 +22,19 @@ type MessageResult {
|
||||||
message: Message
|
message: Message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input ShoutInput {
|
||||||
|
org: String!
|
||||||
|
slug: String!
|
||||||
|
body: String!
|
||||||
|
replyTo: String # another shout
|
||||||
|
tags: [String] # actual values
|
||||||
|
topics: [String] # topic-slugs
|
||||||
|
title: String
|
||||||
|
versionOf: String
|
||||||
|
visibleForRoles: [String] # role ids are strings
|
||||||
|
visibleForUsers: [Int]
|
||||||
|
}
|
||||||
|
|
||||||
type ShoutResult {
|
type ShoutResult {
|
||||||
error: String
|
error: String
|
||||||
shout: Shout
|
shout: Shout
|
||||||
|
@ -45,9 +58,9 @@ type Mutation {
|
||||||
registerUser(email: String!, password: String!): SignInResult!
|
registerUser(email: String!, password: String!): SignInResult!
|
||||||
|
|
||||||
# shout
|
# shout
|
||||||
createShout(body: String!): ShoutResult!
|
createShout(input: ShoutInput!): ShoutResult!
|
||||||
deleteShout(shoutId: Int!): Result!
|
deleteShout(slug: String!): Result!
|
||||||
rateShout(shoutId: Int!, value: Int!): Result!
|
rateShout(slug: String!, value: Int!): Result!
|
||||||
|
|
||||||
# profile
|
# profile
|
||||||
# rateUser(value: Int!): ResultPayload!
|
# rateUser(value: Int!): ResultPayload!
|
||||||
|
|
Loading…
Reference in New Issue
Block a user