Clean up code, add some todos

This commit is contained in:
Ramon Wenger 2021-04-26 19:26:47 +02:00
parent 8d6f30b2d2
commit d4a1c201f2
7 changed files with 17 additions and 9 deletions

View File

@ -1,7 +1,8 @@
export default {
methods: {
addTeam(store, team) {
console.log('add team');
// todo
throw new Error('NotImplemented');
}
}
};

View File

@ -35,6 +35,8 @@
updateName(event) {
this.name = event.target.value;
this.error = '';
// todo: display error
throw new Error('Not Implemented');
},
createClass(name) {
let self = this;

View File

@ -36,6 +36,8 @@
updateName(event) {
this.name = event.target.value;
this.error = '';
// todo: pass error to component
throw new Error('NotImplemented');
},
createTeam(name) {
this.$apollo.mutate({

View File

@ -26,11 +26,11 @@ class ChapterSnapshot(models.Model):
class SnapshotManager(models.Manager):
def create_snapshot(self, module, school_class, user, *args, **kwargs):
snapshot = self.create(module=module, *args, **kwargs)
chapters = Chapter.get_by_parent(module).filter(
chapters_with_hidden_properties = Chapter.get_by_parent(module).filter(
Q(description_hidden_for=school_class)
| Q(title_hidden_for=school_class)
)
for chapter in chapters:
for chapter in chapters_with_hidden_properties:
ChapterSnapshot.objects.create(
chapter=chapter,
snapshot=snapshot,
@ -41,7 +41,7 @@ class SnapshotManager(models.Manager):
for content_block in base_qs.filter(user_created=False):
if content_block.hidden_for.filter(id=school_class.id).exists():
snapshot.hidden_content_blocks.add(content_block)
for content_block in base_qs.filter(user_created=True).filter(owner=user):
for content_block in base_qs.filter(Q(user_created=True) & Q(owner=user)):
new_content_block = ContentBlockSnapshot(
hidden=False,
snapshot=snapshot,

View File

@ -21,6 +21,8 @@ class CreateSnapshot(relay.ClientIDMutation):
module_id = args.get('module')
module = get_object(Module, module_id)
user = info.context.user
# todo: check user
raise NotImplementedError('Permissions')
selected_class_id = args.get('selected_class')
selected_class = get_object(SchoolClass, selected_class_id)
snapshot = Snapshot.objects.create_snapshot(module, selected_class, user)

View File

@ -8,13 +8,11 @@ from notes.models import ContentBlockBookmark
from notes.schema import ContentBlockBookmarkNode
from rooms.models import ModuleRoomSlug
from core.logger import get_logger
logger = get_logger(__name__)
class TextBlockNode(graphene.ObjectType):
text = graphene.String()
@ -33,6 +31,10 @@ class ContentNode(graphene.Union):
return TextBlockNode
def is_solution_and_hidden_for_user(type, user, module):
return type == 'solution' and not (are_solutions_enabled_for(user, module) or user.is_teacher())
class ContentBlockNode(DjangoObjectType):
mine = graphene.Boolean()
bookmarks = graphene.List(ContentBlockBookmarkNode)
@ -56,8 +58,7 @@ class ContentBlockNode(DjangoObjectType):
updated_stream_data = []
for content in self.contents.stream_data:
# only show solutions to teachers and students for whom their teachers have them enabled
if content['type'] == 'solution' \
and not (are_solutions_enabled_for(info.context.user, self.module) or info.context.user.is_teacher()):
if is_solution_and_hidden_for_user(content['type'], info.context.user, self.module):
logger.debug('Solution is hidden for this user')
continue

View File

@ -37,7 +37,7 @@ class Command(BaseCommand):
cursor.execute("DROP SCHEMA IF EXISTS public CASCADE;")
cursor.execute(
"CREATE SCHEMA IF NOT EXISTS public AUTHORIZATION {};".format(settings.DATABASES['default']['USER']))
cursor.execute("GRANT ALL ON SCHEMA public TO postgres;")
cursor.execute("GRANT ALL ON SCHEMA public TO {};".format(settings.DATABASES['default']['USER']))
management.call_command('migrate', verbosity=0, interactive=False)
self.ensure_clean_dir('images')