Skip to content

Commit d544d77

Browse files
committed
Update label creation process
1 parent 5c9ca17 commit d544d77

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

app/api/serializers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ def validate(self, attrs):
4141
pass # unit tests don't always have the correct context set up
4242
else:
4343
if Label.objects.filter(suffix_key=suffix_key,
44-
prefix_key__isnull=True,
44+
prefix_key=prefix_key,
4545
project=project_id).exists():
4646
raise ValidationError('Duplicate key.')
47-
4847
return super().validate(attrs)
4948

5049
class Meta:

app/api/tests/test_api.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,26 @@ def test_can_create_same_label_in_multiple_projects(self):
209209
response = self.client.post(self.other_url, format='json', data=label)
210210
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
211211

212+
def test_can_create_same_suffix_with_different_prefix(self):
213+
self.client.login(username=self.super_user_name,
214+
password=self.super_user_pass)
215+
label = {'text': 'Person', 'prefix_key': None, 'suffix_key': 'p'}
216+
response = self.client.post(self.url, format='json', data=label)
217+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
218+
label = {'text': 'Percentage', 'prefix_key': 'ctrl', 'suffix_key': 'p'}
219+
response = self.client.post(self.url, format='json', data=label)
220+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
221+
222+
def test_cannot_create_same_shortcut_key(self):
223+
self.client.login(username=self.super_user_name,
224+
password=self.super_user_pass)
225+
label = {'text': 'Person', 'prefix_key': None, 'suffix_key': 'p'}
226+
response = self.client.post(self.url, format='json', data=label)
227+
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
228+
label = {'text': 'Percentage', 'prefix_key': None, 'suffix_key': 'p'}
229+
response = self.client.post(self.url, format='json', data=label)
230+
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
231+
212232
def test_disallows_project_member_to_create_label(self):
213233
self.client.login(username=self.project_member_name,
214234
password=self.project_member_pass)

app/server/static/components/label.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,9 @@ export default {
252252
},
253253
254254
addLabel() {
255+
if (this.newLabel.prefix_key === '') {
256+
this.newLabel.prefix_key = null;
257+
}
255258
HTTP.post('labels', this.newLabel)
256259
.then((response) => {
257260
this.cancelCreate();

0 commit comments

Comments
 (0)