Skip to content
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

ESN Accounts & Sections Synchronisation #27

Open
thejoeejoee opened this issue Feb 8, 2022 · 3 comments
Open

ESN Accounts & Sections Synchronisation #27

thejoeejoee opened this issue Feb 8, 2022 · 3 comments
Labels
🟰 feature New feature or request

Comments

@thejoeejoee
Copy link
Member

thejoeejoee commented Feb 8, 2022

{
  "mail": "[email protected]",
  "sc": "CZ-BRNO-VUT",
  "first": "Josef",
  "last": "Kolář",
  "nationality": "CZ",
  "roles": [
    "Local.activeMember",
    "Local.eventCoordinator",
    "Local.regularBoardMember"
  ],
  "extended_roles": [
    "Local.alumnus:LV-RIGA-ESN",
    "Local.activeMember:CZ-BRNO-VUT",
    "Local.eventCoordinator:CZ-BRNO-VUT",
    "Local.regularBoardMember:CZ-BRNO-VUT"
  ],
  "picture": "https://accounts.esn.org/sites/default/files/avatars/2020-09/9f17b98072388c0eae4711192e776796ae8004e947a5b186f316bf0b06ec380b.jpg",
  "gender": "M",
  "section": "ESN VUT Brno",
  "country": "ESN Czech Republic",
  "uid": "thejoeejoee"
}
  • some of the synchronisation from ESN sources is needed:
    • https://accounts.esn.org/api/v2/sections
   {
  "label": "ESN VUT Brno",
  "code": "CZ-BRNO-VUT",
  "website": "https://esnvutbrno.cz/",
  "country": "Czechia",
  "cc": "CZ",
  "state": "active",
  "address": {
    "street_address": "Kolejní 2906/4\r\n612 00\r\nBrno\r\nCzechia",
    "locality": "Brno",
    "postal_code": "612 00",
    "country": "Czechia"
  },
  "cities": [
    {
      "name": "Brno",
      "cc": "CZ"
    }
  ],
  "geolocation": {
    "lat": "49.2311847",
    "lng": "16.5736247",
    "lat_sin": 0.7573505844605075,
    "lat_cos": 0.6530084932199027,
    "lng_rad": 0.2892643200048574
  },
  "university_name": "Brno University of Technology",
  "university_website": "https://www.vutbr.cz/en/",
  "updated": "1639496271",
  "facebook": "https://www.facebook.com/esn.vut.brno/",
  "instagram": "https://www.instagram.com/esnvutbrno/",
  "twitter": "",
  "video": "https://www.youtube.com/watch?v=pMPFoxjdXOI",
  "logo": "/sites/default/files/logos/CZ-BRNO-VUT.png"
}
  • https://accounts.esn.org/api/v2/countries
  {
    "label": "ESN Czech Republic",
    "website": "https://www.esncz.org/",
    "cc": "CZ",
    "country": "Czechia",
    "address": {
      "street_address": "Žerotínovo náměstí 9\r\n601 77\r\nBrno\r\nCzechia",
      "locality": "Brno",
      "postal_code": "601 77",
      "country": "Czechia"
    },
    "updated": "1638545216",
    "facebook": "https://www.facebook.com/esncz",
    "instagram": "https://www.instagram.com/esn_cz/",
    "twitter": "https://twitter.com/esn_cz?s=20",
    "video": "",
    "logo": "/sites/default/files/logos/CZ.png"
  }
@thejoeejoee thejoeejoee added the 🟰 feature New feature or request label Feb 8, 2022
thejoeejoee added a commit that referenced this issue Feb 9, 2022
* Added support for CAS ESN Accounts login #27

* Added section membership spawn from ESN Accounts login

* [pre-commit.ci] auto fixes from pre-commit.com hooks

* Linted

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@Jiri-Soukup
Copy link

Jiri-Soukup commented Feb 17, 2022

my extra data

{
  "mail": "[email protected]",
  "sc": "CZ-BRNO-VUT",
  "first": "Jiří",
  "last": "Soukup",
  "nationality": "CZ",
  "picture": "https://accounts.esn.org/sites/default/files/avatars/2021-05/86e6647c4bf99c5ac11ae298e9bc8624fccdcffa4a6380b7492c186cbb10055a.jpg",
  "section": "ESN VUT Brno",
  "country": "ESN Czech Republic",
  "uid": "jiri_soukup"
}

@thejoeejoee
Copy link
Member Author

thejoeejoee commented Feb 18, 2022

@samuelsimun battleplan:

Synchronizer

  • class ESNAccountsSectionsImporter in apps/sections/importer.py
  • it gets url parameter in constructor, which will be the target JSON endpoint
  • method sync(only=None) will start synchronisation from endpoint to Section model
  • parameter only with None means sync everything
  • only='<SECTION-CODE>'means synchronize only that single one section (eg CZ-BRNO-VUT)
  • only=section_object means synchronize only that single one section
  • only=section_queryset means synchronize listed sections from queryset
  • only=['SECTION-CODE1', 'SECTION-CODE2'] means synchronize only that listed sections
  • only sections with state=active are taken to synchronization
  • method returns list/queryset of synchronized Sections

Synchronization process

  • the only matching attribute from API to our models is code -- Secton.code should be unique=True
  • the rest are just data attributes:
    • label is our name
    • country/cc are redundant, sync to one attribute
    • skip cities, updated
    • address/geolocation sync to JSONField -- see ESNcardApplication.history
    • university_* sync to University model (create/update based on _name) and link to section via SectionUniversity
    • the rest of attrs map to our, newly created and migrated, attrs on Section model

Running synchronization

  • create Django command in sections app
  • command takes optionally the list of sections to sync (by list of codes) and calls the Synchronizer

@thejoeejoee
Copy link
Member Author

thejoeejoee commented Feb 22, 2022

btw. max_length for Section attributes could be taken from https://git.esn.org/composer/drupal-modules/esn-accounts-api/-/blob/master/esn_accounts_api.install#L32-93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🟰 feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants