Repository: carpentries/amy

Issue:
Default value for lesson publication consent
Currently, the default value for the lesson publication consent is "No" making it impossible to distinguish between people who have not set the option yet, and people who have explicitly set it to "No".

* is there something we can currently do to try to distinguish between these 2 situations?
* could we add another option (e.g., "not set") that would become the default?

_____
Thank you for submitting this issue to AMY.  If this represents an urgent problem such as AMY not loading at all, please contact team@carpentries.org so we can respond promptly.

Non-urgent issues will be reviewed weekly by @maneesha.  She will follow up here with you and/or other team members if more information is needed. Issues will be prioritized, considering whether they identify broken features, identify potential enhancements to existing features, or request implemention of entirely new features.


After prioritizing, one of the following will happen:

* High priority issues will be included in an upcoming work cycle and labeled for an existing milestone.
* Medium to low priority issues will be considered for a future work cycle and labeled "later."  These will be re-reviewed periodically to consider them for an upcoming work cycle. 
* Issues that are stale, redundant, or are otherwise assessed not to positively impact user workflows will be closed and labeled "wont-fix"


Comments in the issue itself will provide further context. Please contact team@carpentries.org with any questions.  Thank you again for your contribution and helping us improve AMY.



Discussion:
We could add an option for "unknown" and set that as default or make the default value be `null`.  @pbanaszkiewicz  What would make more sense to you?
@maneesha I'll have to test which option is most suitable. Unfortunately I don't think there's a way to change "No" -> "Unknown" for people already in the database...
@pbanaszkiewicz it looks like the history of the edits made to a profile is stored in the database. Could we query the history to know if someone has edited their own profile since the option has been introduced? it wouldn't be perfect as some people might have not seen the option but it could be an appropriate approximation.

Resolving patch:
diff --git a/amy/workshops/migrations/0185_revamp_lesson_publication_consent.py b/amy/workshops/migrations/0185_revamp_lesson_publication_consent.py
new file mode 100644
--- /dev/null
+++ b/amy/workshops/migrations/0185_revamp_lesson_publication_consent.py
@@ -0,0 +1,53 @@
+# Generated by Django 2.1.7 on 2019-07-07 18:47
+
+from django.db import migrations, models
+
+
+def change_default_for_existing_users(apps, schema_editor):
+    """Change default value in `lesson_publication_consent` for users, who
+    have no record of changing their profile after this field was introduced
+    in migration 'workshops.0165_person_lesson_publication_consent'.
+
+    This function uses a few tricks for find out who has no recorded changes
+    after aforementioned migration was applied."""
+
+    Person = apps.get_model('workshops', 'Person')
+
+    # 1. find out migration application timestamp
+    from django.db.migrations.recorder import MigrationRecorder
+
+    # MigrationRecorder.Migration is a model for all migrations, their metadata
+    # is stored in DB in a special table
+    migration = MigrationRecorder.Migration.objects.get(
+        app='workshops',
+        name='0165_person_lesson_publication_consent',
+    )
+
+    # 2. get all users who still have 'no' as their consent
+    no_consent = Person.objects.filter(lesson_publication_consent='no')
+
+    # 3. from these users, find out who has any revision made after migration
+    #    application date
+    users_no_changes = []
+    for user in no_consent.prefetch_related('revision_set'):
+        if not user.revision_set.filter(date_created__gt=migration.applied):
+            users_no_changes.append(user.pk)
+
+    Person.objects.filter(pk__in=users_no_changes) \
+                  .update(lesson_publication_consent='unset')
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('workshops', '0184_auto_20190416_1837'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='person',
+            name='lesson_publication_consent',
+            field=models.CharField(blank=True, choices=[('yes-profile', 'Yes, and use the name associated with my profile'), ('yes-orcid', 'Yes, and use the name associated with my ORCID profile'), ('yes-github', 'Yes, and only use my GitHub handle'), ('no', 'No'), ('unset', 'Unset')], default='unset', help_text='When we publish our lessons, we like to include everyone who has contributed via pull request as an author. If you do make any contributions, would you like to be included as an author when we publish the lesson?', max_length=40, verbose_name='Do you consent to have your name or identity associated with lesson publications?'),
+        ),
+        migrations.RunPython(change_default_for_existing_users),
+    ]
diff --git a/amy/workshops/models.py b/amy/workshops/models.py
--- a/amy/workshops/models.py
+++ b/amy/workshops/models.py
@@ -567,10 +567,11 @@ class Person(AbstractBaseUser, PermissionsMixin, DataPrivacyAgreementMixin,
          'Yes, and use the name associated with my ORCID profile'),
         ('yes-github', 'Yes, and only use my GitHub handle'),
         ('no', 'No'),
+        ('unset', 'Unset'),
     )
     lesson_publication_consent = models.CharField(
         max_length=STR_MED, choices=LESSON_PUBLICATION_CHOICES,
-        blank=True, default='no', null=False,
+        blank=True, default='unset', null=False,
         verbose_name='Do you consent to have your name or identity associated '
                      'with lesson publications?',
         help_text='When we publish our lessons, we like to include everyone '


Test patch: