-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Required Skills for Task - evaluation logic #41
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b4c7e0
feat: add editorconfig
radimsuckr 1722e6e
feat: add Docker Compose config
radimsuckr 057d3db
feat(admin): add skills to User admin
radimsuckr e2db2ea
feat(task): check if user has required permissions before starting task
radimsuckr 20334e4
feat: only task assignee and owner can update the task
radimsuckr aab7f7f
feat: simple test for Task.start
radimsuckr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.py] | ||
indent_size = 4 | ||
indent_style = space | ||
|
||
[*.{yaml,yml}] | ||
indent_size = 2 | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,41 @@ | ||
from django.contrib import admin | ||
from django.contrib.auth.admin import UserAdmin | ||
from .models import User, Task, Skill | ||
from django.contrib.auth.forms import UserChangeForm | ||
|
||
from .models import Skill, Task, User | ||
|
||
|
||
class UserChangeForm(UserChangeForm): | ||
class Meta(UserChangeForm.Meta): | ||
model = User | ||
|
||
|
||
class ComradeUserAdmin(UserAdmin): | ||
form = UserChangeForm | ||
fieldsets = UserAdmin.fieldsets + ((None, {"fields": ("skills",)}),) | ||
|
||
|
||
class TaskAdmin(admin.ModelAdmin): | ||
list_display = ['name', 'owner', 'state', 'lat', 'lon', 'respawn', 'respawn_time', 'base_value', 'criticality', 'contribution'] | ||
list_filter = ['state', 'respawn', 'criticality'] | ||
search_fields = ['name', 'description'] | ||
list_display = [ | ||
"name", | ||
"owner", | ||
"state", | ||
"lat", | ||
"lon", | ||
"respawn", | ||
"respawn_time", | ||
"base_value", | ||
"criticality", | ||
"contribution", | ||
] | ||
list_filter = ["state", "respawn", "criticality"] | ||
search_fields = ["name", "description"] | ||
|
||
|
||
class SkillInline(admin.StackedInline): | ||
model = Skill | ||
|
||
|
||
admin.site.register(User, UserAdmin) | ||
admin.site.register(User, ComradeUserAdmin) | ||
admin.site.register(Task, TaskAdmin) | ||
admin.site.register(Skill) | ||
admin.site.register(Skill) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,39 @@ | ||
from django.core.exceptions import ValidationError | ||
from django.test import TestCase | ||
|
||
# Create your tests here. | ||
from comrade_core.models import Skill, Task, User | ||
|
||
|
||
class TaskTestCase(TestCase): | ||
def test_task_start_throws_error_to_user_with_no_skill(self): | ||
s = Skill.objects.create(name="tasktestcase1") | ||
u = User.objects.create(username="tasktestcase") | ||
t = Task.objects.create() | ||
t.skill_execute.add(s) | ||
|
||
self.assertTrue(t.skill_execute.count() == 1) | ||
self.assertTrue(u.skills.count() == 0) | ||
|
||
try: | ||
t.start(u) | ||
except ValidationError: | ||
pass | ||
else: | ||
self.fail( | ||
"start should throw an error when the user has not the required skill for execute" | ||
) | ||
|
||
def test_task_start_succeeds_when_user_has_required_execute_skills(self): | ||
s = Skill.objects.create(name="tasktestcase1") | ||
u = User.objects.create(username="tasktestcase") | ||
t = Task.objects.create() | ||
t.skill_execute.add(s) | ||
u.skills.add(s) | ||
|
||
self.assertTrue(t.skill_execute.count() == 1) | ||
self.assertTrue(u.skills.count() == 1) | ||
|
||
try: | ||
t.start(u) | ||
except ValidationError: | ||
self.fail("start should pass when user has at least one required skill") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
version: "3.8" | ||
services: | ||
redis: | ||
image: redis:alpine | ||
ports: | ||
- 6379:6379 | ||
postgres: | ||
environment: | ||
POSTGRES_USER: comrade | ||
POSTGRES_PASSWORD: comrade | ||
POSTGRES_DB: comrade | ||
image: postgres:alpine | ||
ports: | ||
- 5432:5432 | ||
volumes: | ||
- postgres-data:/var/lib/postgresql/data | ||
volumes: | ||
postgres-data: |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should work. 😅 I hope it will because it's much more readable.