Sefaria / Sefaria-Project

New Interfaces for Jewish Texts
https://www.sefaria.org
654 stars 268 forks source link

Bug/sc 28696/allow unsetting the license field on versions #2002

Closed stevekaplan123 closed 1 week ago

stevekaplan123 commented 1 month ago

Description

Allows user to unset the license field on versions using UI.

Code Changes

  1. Front-end changes -- The code already had built-in half the code necessary for this feature: The existing line {licenses.map(v => <option key={v} value={v}>{v?v:"(None Listed)"}</option>)} means that a license value of "" will be shown as "(None Listed)", so I just had to add the line: let licenses = [...Object.keys(Sefaria.getLicenseMap()), ""]; to make sure the licenses array contained an empty string. (By the way, to make sure we don't end with two empty strings, I removed the property 'license' when its value was the empty string for 8 versions on prod).
  2. Back-end changes -- I modified the flag_text_api in two ways. First of all, there was a lot of duplication of code so I re-factored it by creating a function update_version that gets called from two places in the API. Second, I added a line so that if license is set to the empty string, the property will be removed from the Version:
    if flag == 'license' and flags[flag] == "":
         delattr(vobj, flag)