| 127 | ) |
| 128 | }, |
| 129 | toggleUserFlag({ |
| 130 | environmentFlag, |
| 131 | environmentId, |
| 132 | identity, |
| 133 | identityFlag, |
| 134 | projectFlag, |
| 135 | }) { |
| 136 | store.saving() |
| 137 | API.trackEvent(Constants.events.EDIT_USER_FEATURE) |
| 138 | const prom = |
| 139 | identityFlag.identity || identityFlag.identity_uuid |
| 140 | ? data.put( |
| 141 | `${ |
| 142 | Project.api |
| 143 | }environments/${environmentId}/${Utils.getIdentitiesEndpoint()}/${identity}/${Utils.getFeatureStatesEndpoint()}/${ |
| 144 | identityFlag.id || identityFlag.featurestate_uuid |
| 145 | }/`, |
| 146 | Object.assign( |
| 147 | {}, |
| 148 | { |
| 149 | enabled: !identityFlag.enabled, |
| 150 | feature: projectFlag.id, |
| 151 | feature_state_value: identityFlag |
| 152 | ? identityFlag.feature_state_value |
| 153 | : environmentFlag && environmentFlag.feature_state_value, |
| 154 | id: identityFlag.id || identityFlag.featurestate_uuid, |
| 155 | }, |
| 156 | ), |
| 157 | ) |
| 158 | : data.post( |
| 159 | `${ |
| 160 | Project.api |
| 161 | }environments/${environmentId}/${Utils.getIdentitiesEndpoint()}/${identity}/${Utils.getFeatureStatesEndpoint()}/`, |
| 162 | { |
| 163 | enabled: !environmentFlag || !environmentFlag.enabled, |
| 164 | feature: projectFlag.id, |
| 165 | feature_state_value: environmentFlag |
| 166 | ? environmentFlag.feature_state_value |
| 167 | : undefined, |
| 168 | }, |
| 169 | ) |
| 170 | |
| 171 | prom.then((res) => { |
| 172 | store.model.features[res.feature] = res |
| 173 | store.saved() |
| 174 | }) |
| 175 | }, |
| 176 | } |
| 177 | |
| 178 | const store = Object.assign({}, BaseStore, { |