mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-10 00:42:06 +00:00
Don't remove news articles when attached email is removed
At this point, we set the field to PROTECTED and dont' allow the deletion at all. In the future we might want to allow a set null operation, but for now we require the users to contact webmaster@ to handle that, so we keep it under control.
This commit is contained in:
@ -88,6 +88,13 @@ class OrganisationForm(forms.ModelForm):
|
||||
raise ValidationError("Cannot remove all managers from an organsation!")
|
||||
return self.cleaned_data['remove_manager']
|
||||
|
||||
def clean_remove_email(self):
|
||||
if self.cleaned_data['remove_email']:
|
||||
for e in self.cleaned_data['remove_email']:
|
||||
if e.newsarticle_set.exists():
|
||||
raise ValidationError("Cannot remove an email address that has been used to post news articles. Please contact webmaster@postgresql.org to have this removed.")
|
||||
return self.cleaned_data['remove_email']
|
||||
|
||||
def save(self, commit=True):
|
||||
model = super(OrganisationForm, self).save(commit=False)
|
||||
|
||||
|
@ -15,6 +15,6 @@ class Migration(migrations.Migration):
|
||||
migrations.AddField(
|
||||
model_name='newsarticle',
|
||||
name='email',
|
||||
field=models.ForeignKey(blank=True, help_text='Pick a confirmed email associated with the organisation. This will be used as the reply address of posted news.', null=True, on_delete=django.db.models.deletion.CASCADE, to='core.OrganisationEmail', verbose_name='Reply email'),
|
||||
field=models.ForeignKey(blank=True, help_text='Pick a confirmed email associated with the organisation. This will be used as the reply address of posted news.', null=True, on_delete=django.db.models.deletion.PROTECT, to='core.OrganisationEmail', verbose_name='Reply email'),
|
||||
),
|
||||
]
|
||||
|
@ -26,7 +26,7 @@ class NewsTag(models.Model):
|
||||
|
||||
class NewsArticle(TwoModeratorsMixin, TristateModerateModel):
|
||||
org = models.ForeignKey(Organisation, null=False, blank=False, verbose_name="Organisation", help_text="If no organisations are listed, please check the <a href=\"/account/orglist/\">organisation list</a> and contact the organisation manager or <a href=\"mailto:webmaster@postgresql.org\">webmaster@postgresql.org</a> if none are listed.", on_delete=models.CASCADE)
|
||||
email = models.ForeignKey(OrganisationEmail, null=True, blank=True, verbose_name="Reply email", help_text="Pick a confirmed email associated with the organisation. This will be used as the reply address of posted news.", on_delete=models.CASCADE)
|
||||
email = models.ForeignKey(OrganisationEmail, null=True, blank=True, verbose_name="Reply email", help_text="Pick a confirmed email associated with the organisation. This will be used as the reply address of posted news.", on_delete=models.PROTECT)
|
||||
date = models.DateField(null=False, blank=False, default=date.today, db_index=True)
|
||||
title = models.CharField(max_length=200, null=False, blank=False)
|
||||
content = models.TextField(null=False, blank=False)
|
||||
|
Reference in New Issue
Block a user