def save(self): org = self.context['organization'] if 'openMembership' in self.init_data: org.flags.allow_joinleave = self.init_data['openMembership'] if 'allowSharedIssues' in self.init_data: org.flags.disable_shared_issues = not self.init_data[ 'allowSharedIssues'] if 'enhancedPrivacy' in self.init_data: org.flags.enhanced_privacy = self.init_data['enhancedPrivacy'] if 'isEarlyAdopter' in self.init_data: org.flags.early_adopter = self.init_data['isEarlyAdopter'] if 'name' in self.init_data: org.name = self.init_data['name'] if 'slug' in self.init_data: org.slug = self.init_data['slug'] org.save() for key, option, type_ in ORG_OPTIONS: if key in self.init_data: OrganizationOption.objects.set_value( organization=org, key=option, value=type_(self.init_data[key]), ) if 'avatar' in self.init_data or 'avatarType' in self.init_data: OrganizationAvatar.save_avatar( relation={'organization': org}, type=self.init_data.get('avatarType', 'upload'), avatar=self.init_data.get('avatar'), filename='{}.png'.format(org.slug), ) return org
def save(self): org = self.context['organization'] if 'openMembership' in self.init_data: org.flags.allow_joinleave = self.init_data['openMembership'] if 'allowSharedIssues' in self.init_data: org.flags.disable_shared_issues = not self.init_data['allowSharedIssues'] if 'enhancedPrivacy' in self.init_data: org.flags.enhanced_privacy = self.init_data['enhancedPrivacy'] if 'isEarlyAdopter' in self.init_data: org.flags.early_adopter = self.init_data['isEarlyAdopter'] if 'name' in self.init_data: org.name = self.init_data['name'] if 'slug' in self.init_data: org.slug = self.init_data['slug'] org.save() for key, option, type_ in ORG_OPTIONS: if key in self.init_data: OrganizationOption.objects.set_value( organization=org, key=option, value=type_(self.init_data[key]), ) if 'avatar' in self.init_data or 'avatarType' in self.init_data: OrganizationAvatar.save_avatar( relation={'organization': org}, type=self.init_data.get('avatarType', 'upload'), avatar=self.init_data.get('avatar'), filename='{}.png'.format(org.slug), ) return org
def save(self): rv = super(OrganizationSerializer, self).save() # XXX(dcramer): this seems wrong, but cant find documentation on how to # actually access this data if 'projectRateLimit' in self.init_data: OrganizationOption.objects.set_value( organization=self.object, key='sentry:project-rate-limit', value=int(self.init_data['projectRateLimit']), ) if 'accountRateLimit' in self.init_data: OrganizationOption.objects.set_value( organization=self.object, key='sentry:account-rate-limit', value=int(self.init_data['accountRateLimit']), ) if 'avatar' in self.init_data or 'avatarType' in self.init_data: OrganizationAvatar.save_avatar( relation={'organization': self.object}, type=self.init_data.get('avatarType', 'upload'), avatar=self.init_data.get('avatar'), filename='{}.png'.format(self.object.slug), ) return rv
def save(self): org = self.context['organization'] changed_data = {} for key, option, type_ in ORG_OPTIONS: if key not in self.init_data: continue try: option_inst = OrganizationOption.objects.get( organization=org, key=option) except OrganizationOption.DoesNotExist: OrganizationOption.objects.set_value( organization=org, key=option, value=type_(self.init_data[key]), ) # TODO(kelly): This will not work if new ORG_OPTIONS are added and their # default value evaluates as truthy, but this should work for now with the # current ORG_OPTIONS (assumes ORG_OPTIONS are falsy) if type_(self.init_data[key]): changed_data[key] = self.init_data[key] else: option_inst.value = self.init_data[key] # check if ORG_OPTIONS changed if option_inst.has_changed('value'): old_val = option_inst.old_value('value') changed_data[key] = u'from {} to {}'.format(old_val, option_inst.value) option_inst.save() if 'openMembership' in self.init_data: org.flags.allow_joinleave = self.init_data['openMembership'] if 'allowSharedIssues' in self.init_data: org.flags.disable_shared_issues = not self.init_data['allowSharedIssues'] if 'enhancedPrivacy' in self.init_data: org.flags.enhanced_privacy = self.init_data['enhancedPrivacy'] if 'isEarlyAdopter' in self.init_data: org.flags.early_adopter = self.init_data['isEarlyAdopter'] if 'require2FA' in self.init_data: org.flags.require_2fa = self.init_data['require2FA'] if 'name' in self.init_data: org.name = self.init_data['name'] if 'slug' in self.init_data: org.slug = self.init_data['slug'] org_tracked_field = { 'name': org.name, 'slug': org.slug, 'default_role': org.default_role, 'flag_field': { 'allow_joinleave': org.flags.allow_joinleave.is_set, 'enhanced_privacy': org.flags.enhanced_privacy.is_set, 'disable_shared_issues': org.flags.disable_shared_issues.is_set, 'early_adopter': org.flags.early_adopter.is_set, 'require_2fa': org.flags.require_2fa.is_set, } } # check if fields changed for f, v in six.iteritems(org_tracked_field): if f is not 'flag_field': if org.has_changed(f): old_val = org.old_value(f) changed_data[f] = u'from {} to {}'.format(old_val, v) else: # check if flag fields changed for f, v in six.iteritems(org_tracked_field['flag_field']): if org.flag_has_changed(f): changed_data[f] = u'to {}'.format(v) org.save() if 'avatar' in self.init_data or 'avatarType' in self.init_data: OrganizationAvatar.save_avatar( relation={'organization': org}, type=self.init_data.get('avatarType', 'upload'), avatar=self.init_data.get('avatar'), filename='{}.png'.format(org.slug), ) if 'require2FA' in self.init_data and self.init_data['require2FA'] is True: org.send_setup_2fa_emails() return org, changed_data
def save(self): from sentry import features org = self.context["organization"] changed_data = {} if not hasattr(org, "__data"): update_tracked_data(org) for key, option, type_, default_value in ORG_OPTIONS: if key not in self.initial_data: continue try: option_inst = OrganizationOption.objects.get(organization=org, key=option) update_tracked_data(option_inst) except OrganizationOption.DoesNotExist: OrganizationOption.objects.set_value( organization=org, key=option, value=type_(self.initial_data[key])) if self.initial_data[key] != default_value: changed_data[key] = f"to {self.initial_data[key]}" else: option_inst.value = self.initial_data[key] # check if ORG_OPTIONS changed if has_changed(option_inst, "value"): old_val = old_value(option_inst, "value") changed_data[ key] = f"from {old_val} to {option_inst.value}" option_inst.save() trusted_realy_info = self.validated_data.get("trustedRelays") if trusted_realy_info is not None: self.save_trusted_relays(trusted_realy_info, changed_data, org) if "openMembership" in self.initial_data: org.flags.allow_joinleave = self.initial_data["openMembership"] if "allowSharedIssues" in self.initial_data: org.flags.disable_shared_issues = not self.initial_data[ "allowSharedIssues"] if "enhancedPrivacy" in self.initial_data: org.flags.enhanced_privacy = self.initial_data["enhancedPrivacy"] if "isEarlyAdopter" in self.initial_data: org.flags.early_adopter = self.initial_data["isEarlyAdopter"] if "require2FA" in self.initial_data: org.flags.require_2fa = self.initial_data["require2FA"] if (features.has("organizations:required-email-verification", org) and "requireEmailVerification" in self.initial_data): org.flags.require_email_verification = self.initial_data[ "requireEmailVerification"] if "name" in self.initial_data: org.name = self.initial_data["name"] if "slug" in self.initial_data: org.slug = self.initial_data["slug"] org_tracked_field = { "name": org.name, "slug": org.slug, "default_role": org.default_role, "flag_field": { "allow_joinleave": org.flags.allow_joinleave.is_set, "enhanced_privacy": org.flags.enhanced_privacy.is_set, "disable_shared_issues": org.flags.disable_shared_issues.is_set, "early_adopter": org.flags.early_adopter.is_set, "require_2fa": org.flags.require_2fa.is_set, }, } # check if fields changed for f, v in org_tracked_field.items(): if f != "flag_field": if has_changed(org, f): old_val = old_value(org, f) changed_data[f] = f"from {old_val} to {v}" else: # check if flag fields changed for f, v in org_tracked_field["flag_field"].items(): if flag_has_changed(org, f): changed_data[f] = f"to {v}" org.save() if "avatar" in self.initial_data or "avatarType" in self.initial_data: OrganizationAvatar.save_avatar( relation={"organization": org}, type=self.initial_data.get("avatarType", "upload"), avatar=self.initial_data.get("avatar"), filename=f"{org.slug}.png", ) if self.initial_data.get("require2FA") is True: org.handle_2fa_required(self.context["request"]) if (features.has("organizations:required-email-verification", org) and self.initial_data.get("requireEmailVerification") is True): org.handle_email_verification_required(self.context["request"]) return org, changed_data
def save(self): org = self.context['organization'] changed_data = {} for key, option, type_, default_value in ORG_OPTIONS: if key not in self.init_data: continue try: option_inst = OrganizationOption.objects.get( organization=org, key=option) except OrganizationOption.DoesNotExist: OrganizationOption.objects.set_value( organization=org, key=option, value=type_(self.init_data[key]), ) if self.init_data[key] != default_value: changed_data[key] = u'to {}'.format(self.init_data[key]) else: option_inst.value = self.init_data[key] # check if ORG_OPTIONS changed if option_inst.has_changed('value'): old_val = option_inst.old_value('value') changed_data[key] = u'from {} to {}'.format(old_val, option_inst.value) option_inst.save() if 'openMembership' in self.init_data: org.flags.allow_joinleave = self.init_data['openMembership'] if 'allowSharedIssues' in self.init_data: org.flags.disable_shared_issues = not self.init_data['allowSharedIssues'] if 'enhancedPrivacy' in self.init_data: org.flags.enhanced_privacy = self.init_data['enhancedPrivacy'] if 'isEarlyAdopter' in self.init_data: org.flags.early_adopter = self.init_data['isEarlyAdopter'] if 'disableNewVisibilityFeatures' in self.init_data: org.flags.disable_new_visibility_features = self.init_data['disableNewVisibilityFeatures'] if 'require2FA' in self.init_data: org.flags.require_2fa = self.init_data['require2FA'] if 'name' in self.init_data: org.name = self.init_data['name'] if 'slug' in self.init_data: org.slug = self.init_data['slug'] org_tracked_field = { 'name': org.name, 'slug': org.slug, 'default_role': org.default_role, 'flag_field': { 'allow_joinleave': org.flags.allow_joinleave.is_set, 'enhanced_privacy': org.flags.enhanced_privacy.is_set, 'disable_shared_issues': org.flags.disable_shared_issues.is_set, 'early_adopter': org.flags.early_adopter.is_set, 'require_2fa': org.flags.require_2fa.is_set, } } # check if fields changed for f, v in six.iteritems(org_tracked_field): if f is not 'flag_field': if org.has_changed(f): old_val = org.old_value(f) changed_data[f] = u'from {} to {}'.format(old_val, v) else: # check if flag fields changed for f, v in six.iteritems(org_tracked_field['flag_field']): if org.flag_has_changed(f): changed_data[f] = u'to {}'.format(v) org.save() if 'avatar' in self.init_data or 'avatarType' in self.init_data: OrganizationAvatar.save_avatar( relation={'organization': org}, type=self.init_data.get('avatarType', 'upload'), avatar=self.init_data.get('avatar'), filename=u'{}.png'.format(org.slug), ) if 'require2FA' in self.init_data and self.init_data['require2FA'] is True: org.handle_2fa_required(self.context['request']) return org, changed_data
def save(self): org = self.context["organization"] changed_data = {} for key, option, type_, default_value in ORG_OPTIONS: if key not in self.initial_data: continue try: option_inst = OrganizationOption.objects.get(organization=org, key=option) except OrganizationOption.DoesNotExist: OrganizationOption.objects.set_value( organization=org, key=option, value=type_(self.initial_data[key]) ) if self.initial_data[key] != default_value: changed_data[key] = u"to {}".format(self.initial_data[key]) else: option_inst.value = self.initial_data[key] # check if ORG_OPTIONS changed if option_inst.has_changed("value"): old_val = option_inst.old_value("value") changed_data[key] = u"from {} to {}".format(old_val, option_inst.value) option_inst.save() if "openMembership" in self.initial_data: org.flags.allow_joinleave = self.initial_data["openMembership"] if "allowSharedIssues" in self.initial_data: org.flags.disable_shared_issues = not self.initial_data["allowSharedIssues"] if "enhancedPrivacy" in self.initial_data: org.flags.enhanced_privacy = self.initial_data["enhancedPrivacy"] if "isEarlyAdopter" in self.initial_data: org.flags.early_adopter = self.initial_data["isEarlyAdopter"] if "require2FA" in self.initial_data: org.flags.require_2fa = self.initial_data["require2FA"] if "name" in self.initial_data: org.name = self.initial_data["name"] if "slug" in self.initial_data: org.slug = self.initial_data["slug"] org_tracked_field = { "name": org.name, "slug": org.slug, "default_role": org.default_role, "flag_field": { "allow_joinleave": org.flags.allow_joinleave.is_set, "enhanced_privacy": org.flags.enhanced_privacy.is_set, "disable_shared_issues": org.flags.disable_shared_issues.is_set, "early_adopter": org.flags.early_adopter.is_set, "require_2fa": org.flags.require_2fa.is_set, }, } # check if fields changed for f, v in six.iteritems(org_tracked_field): if f is not "flag_field": if org.has_changed(f): old_val = org.old_value(f) changed_data[f] = u"from {} to {}".format(old_val, v) else: # check if flag fields changed for f, v in six.iteritems(org_tracked_field["flag_field"]): if org.flag_has_changed(f): changed_data[f] = u"to {}".format(v) org.save() if "avatar" in self.initial_data or "avatarType" in self.initial_data: OrganizationAvatar.save_avatar( relation={"organization": org}, type=self.initial_data.get("avatarType", "upload"), avatar=self.initial_data.get("avatar"), filename=u"{}.png".format(org.slug), ) if "require2FA" in self.initial_data and self.initial_data["require2FA"] is True: org.handle_2fa_required(self.context["request"]) return org, changed_data