зеркало из https://github.com/mozilla/kitsune.git
[578510] Fix can_tag permission's absence and many other neglected migrations.
I couldn't agree with myself whether to use can_tag or tag_question as the permission's codename. Fixed that. Also, we've been neglecting from the beginning to add entries to django_content_type and auth_permission when we add new models. Since we don't run syncdb, this isn't taken care of automatically. Went back and added the right things to old migrations.
This commit is contained in:
Родитель
91ac3d23fb
Коммит
c416b3bb73
|
@ -35,7 +35,8 @@ class Question(ModelBase, TaggableMixin):
|
|||
class Meta:
|
||||
ordering = ['-updated']
|
||||
permissions = (
|
||||
('can_tag', 'Can add tags to and remove tags from questions'),
|
||||
('tag_question',
|
||||
'Can add tags to and remove tags from questions'),
|
||||
)
|
||||
|
||||
def __unicode__(self):
|
||||
|
|
|
@ -239,9 +239,9 @@ class TaggingViewTestsAsTagger(TaggingTestCaseBase):
|
|||
def setUp(self):
|
||||
super(TaggingViewTestsAsTagger, self).setUp()
|
||||
|
||||
# Assign can_tag permission to the "tagger" user.
|
||||
# Would be if there were a natural key for doing this via a fixture.
|
||||
self._can_tag = Permission.objects.get_by_natural_key('can_tag',
|
||||
# Assign tag_question permission to the "tagger" user.
|
||||
# Would be nice to have a natural key for doing this via a fixture.
|
||||
self._can_tag = Permission.objects.get_by_natural_key('tag_question',
|
||||
'questions',
|
||||
'question')
|
||||
self._user = User.objects.get(username='tagger')
|
||||
|
|
|
@ -194,7 +194,7 @@ def answer_vote(request, question_id, answer_id):
|
|||
return HttpResponseRedirect(answer.get_absolute_url())
|
||||
|
||||
|
||||
@permission_required('questions.can_tag')
|
||||
@permission_required('questions.tag_question')
|
||||
def add_tag(request, question_id):
|
||||
"""Add a (case-insensitive) tag to question.
|
||||
|
||||
|
@ -225,7 +225,7 @@ def add_tag(request, question_id):
|
|||
return jingo.render(request, 'questions/answers.html', template_data)
|
||||
|
||||
|
||||
@permission_required('questions.can_tag')
|
||||
@permission_required('questions.tag_question')
|
||||
@require_POST
|
||||
def add_tag_async(request, question_id):
|
||||
"""Add a (case-insensitive) tag to question asyncronously. Return empty.
|
||||
|
@ -249,7 +249,7 @@ def add_tag_async(request, question_id):
|
|||
status=400)
|
||||
|
||||
|
||||
@permission_required('questions.can_tag')
|
||||
@permission_required('questions.tag_question')
|
||||
@require_POST
|
||||
def remove_tag(request, question_id):
|
||||
"""Remove a (case-insensitive) tag from question.
|
||||
|
@ -269,7 +269,7 @@ def remove_tag(request, question_id):
|
|||
reverse('questions.answers', args=[question_id]))
|
||||
|
||||
|
||||
@permission_required('questions.can_tag')
|
||||
@permission_required('questions.tag_question')
|
||||
@require_POST
|
||||
def remove_tag_async(request, question_id):
|
||||
"""Remove a (case-insensitive) tag from question.
|
||||
|
@ -302,7 +302,7 @@ def _answers_data(request, question_id, form=None):
|
|||
'form': form or AnswerForm(),
|
||||
'feeds': feed_urls,
|
||||
'tag_vocab': json.dumps(vocab),
|
||||
'can_tag': request.user.has_perm('questions.can_tag'),
|
||||
'can_tag': request.user.has_perm('questions.tag_question'),
|
||||
'can_create_tags': request.user.has_perm('taggit.add_tag')}
|
||||
|
||||
|
||||
|
|
|
@ -10,3 +10,5 @@ ALTER TABLE `notifications_eventwatch` ADD CONSTRAINT `content_type_id_refs_id_1
|
|||
CREATE INDEX `notifications_eventwatch_content_type_id` ON `notifications_eventwatch` (`content_type_id`);
|
||||
CREATE INDEX `notifications_eventwatch_watch_id` ON `notifications_eventwatch` (`watch_id`);
|
||||
CREATE INDEX `notifications_eventwatch_email` ON `notifications_eventwatch` (`email`);
|
||||
|
||||
-- django_content_type and auth_permission entries are made in 10-create-questions-app.sql due to an historical deployment contingency.
|
||||
|
|
|
@ -1,4 +1,12 @@
|
|||
BEGIN;
|
||||
|
||||
-- The eventwatch type is made here due to an historical deployment contingency:
|
||||
INSERT INTO django_content_type (name, app_label, model) VALUES ('event watch', 'notifications', 'eventwatch');
|
||||
SET @ct = (SELECT LAST_INSERT_ID());
|
||||
INSERT INTO auth_permission (name, content_type_id, codename) VALUES ('Can add event watch', @ct, 'add_eventwatch'),
|
||||
('Can change event watch', @ct, 'change_eventwatch'),
|
||||
('Can delete event watch', @ct, 'delete_eventwatch');
|
||||
|
||||
CREATE TABLE `questions_questionforum` (
|
||||
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
|
||||
`name` varchar(50) NOT NULL UNIQUE,
|
||||
|
@ -62,4 +70,22 @@ CREATE INDEX `questions_answer_created` ON `questions_answer` (`created`);
|
|||
CREATE INDEX `questions_answer_updated` ON `questions_answer` (`updated`);
|
||||
CREATE INDEX `questions_answer_updated_by_id` ON `questions_answer` (`updated_by_id`);
|
||||
CREATE INDEX `questions_answer_upvotes` ON `questions_answer` (`upvotes`);
|
||||
|
||||
INSERT INTO django_content_type (name, app_label, model) VALUES ('question', 'questions', 'question');
|
||||
SET @ct = (SELECT LAST_INSERT_ID());
|
||||
INSERT INTO auth_permission (name, content_type_id, codename) VALUES ('Can add question', @ct, 'add_question'),
|
||||
('Can change question', @ct, 'change_question'),
|
||||
('Can delete question', @ct, 'delete_question');
|
||||
|
||||
INSERT INTO django_content_type (name, app_label, model) VALUES ('question meta data', 'questions', 'questionmetadata');
|
||||
SET @ct = (SELECT LAST_INSERT_ID());
|
||||
INSERT INTO auth_permission (name, content_type_id, codename) VALUES ('Can add question meta data', @ct, 'add_questionmetadata'),
|
||||
('Can change question meta data', @ct, 'change_questionmetadata'),
|
||||
('Can delete question meta data', @ct, 'delete_questionmetadata');
|
||||
|
||||
INSERT INTO django_content_type (name, app_label, model) VALUES ('answer', 'questions', 'answer');
|
||||
SET @ct = (SELECT LAST_INSERT_ID());
|
||||
INSERT INTO auth_permission (name, content_type_id, codename) VALUES ('Can add answer', @ct, 'add_answer'),
|
||||
('Can change answer', @ct, 'change_answer'),
|
||||
('Can delete answer', @ct, 'delete_answer');
|
||||
COMMIT;
|
||||
|
|
|
@ -11,4 +11,10 @@ ALTER TABLE `questions_questionvote` ADD CONSTRAINT `creator_id_refs_id_699edd80
|
|||
CREATE INDEX `questions_questionvote_question_id` ON `questions_questionvote` (`question_id`);
|
||||
CREATE INDEX `questions_questionvote_created` ON `questions_questionvote` (`created`);
|
||||
CREATE INDEX `questions_questionvote_creator_id` ON `questions_questionvote` (`creator_id`);
|
||||
CREATE INDEX `questions_questionvote_anonymous_id` ON `questions_questionvote` (`anonymous_id`);
|
||||
CREATE INDEX `questions_questionvote_anonymous_id` ON `questions_questionvote` (`anonymous_id`);
|
||||
|
||||
INSERT INTO django_content_type (name, app_label, model) VALUES ('question vote', 'questions', 'questionvote');
|
||||
SET @ct = (SELECT LAST_INSERT_ID());
|
||||
INSERT INTO auth_permission (name, content_type_id, codename) VALUES ('Can add question vote', @ct, 'add_questionvote'),
|
||||
('Can change question vote', @ct, 'change_questionvote'),
|
||||
('Can delete question vote', @ct, 'delete_questionvote');
|
||||
|
|
|
@ -13,3 +13,9 @@ CREATE INDEX `questions_answervote_answer_id` ON `questions_answervote` (`answer
|
|||
CREATE INDEX `questions_answervote_created` ON `questions_answervote` (`created`);
|
||||
CREATE INDEX `questions_answervote_creator_id` ON `questions_answervote` (`creator_id`);
|
||||
CREATE INDEX `questions_answervote_anonymous_id` ON `questions_answervote` (`anonymous_id`);
|
||||
|
||||
INSERT INTO django_content_type (name, app_label, model) VALUES ('answer vote', 'questions', 'answervote');
|
||||
SET @ct = (SELECT LAST_INSERT_ID());
|
||||
INSERT INTO auth_permission (name, content_type_id, codename) VALUES ('Can add answer vote', @ct, 'add_answervote'),
|
||||
('Can change answer vote', @ct, 'change_answervote'),
|
||||
('Can delete answer vote', @ct, 'delete_answervote');
|
||||
|
|
|
@ -21,8 +21,16 @@ CREATE INDEX `taggit_taggeditem_e4470c6e` ON `taggit_taggeditem` (`content_type_
|
|||
-- Added a unique constraint on taggit_tag.name. This keeps tag names case-insensitively unique, since we use MySQL's default collation for utf8, utf8_general_ci.
|
||||
|
||||
|
||||
-- Make new permissions: --
|
||||
insert into auth_permission (name, content_type_id, codename) values ('Can add tags to and remove tags from questions', (select id from django_content_type where app_label='questions' and model='question'), 'tag_question');
|
||||
|
||||
-- Django doesn't seem to make this custom permission on startup.
|
||||
-- It also doesn't seem to make any permissions except on syncdb, so I have no idea how any of our migrations worked in the past. I suppose it will turn up on staging at worst.
|
||||
insert into auth_permission (name, content_type_id, codename) values ('Can tag question', (select id from django_content_type where app_label='questions' and model='question'), 'tag_question');
|
||||
INSERT INTO django_content_type (name, app_label, model) VALUES ('Tag', 'taggit', 'tag');
|
||||
SET @ct = (SELECT LAST_INSERT_ID());
|
||||
INSERT INTO auth_permission (name, content_type_id, codename) VALUES ('Can add tag', @ct, 'add_tag'),
|
||||
('Can change tag', @ct, 'change_tag'),
|
||||
('Can delete tag', @ct, 'delete_tag');
|
||||
|
||||
INSERT INTO django_content_type (name, app_label, model) VALUES ('Tagged Item', 'taggit', 'taggeditem');
|
||||
SET @ct = (SELECT LAST_INSERT_ID());
|
||||
INSERT INTO auth_permission (name, content_type_id, codename) VALUES ('Can add tagged item', @ct, 'add_taggeditem'),
|
||||
('Can change tagged item', @ct, 'change_taggeditem'),
|
||||
('Can delete tagged item', @ct, 'delete_taggeditem');
|
||||
|
|
Загрузка…
Ссылка в новой задаче