(ctx context.Context, users []*common.User)
| 167 | } |
| 168 | |
| 169 | func (x *Xray) UpdateUsers(ctx context.Context, users []*common.User) error { |
| 170 | handler := x.handler |
| 171 | inboundByTag, updates := x.config.buildInboundUpdates(users) |
| 172 | var errMessage string |
| 173 | |
| 174 | for tag, update := range updates { |
| 175 | removeEmails := make([]string, 0, len(update.removeEmailSet)) |
| 176 | for email := range update.removeEmailSet { |
| 177 | removeEmails = append(removeEmails, email) |
| 178 | } |
| 179 | |
| 180 | inbound := inboundByTag[tag] |
| 181 | inbound.updateUsers(update.accounts, removeEmails) |
| 182 | |
| 183 | for _, email := range removeEmails { |
| 184 | handler.RemoveInboundUser(ctx, tag, email) |
| 185 | } |
| 186 | |
| 187 | for _, account := range update.accounts { |
| 188 | _ = handler.RemoveInboundUser(ctx, tag, account.GetEmail()) |
| 189 | if err := handler.AddInboundUser(ctx, tag, accountForAPI(inbound, account)); err != nil { |
| 190 | log.Println(err) |
| 191 | errMessage += "\n" + err.Error() |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if errMessage != "" { |
| 197 | return errors.New("failed to update users:" + errMessage) |
| 198 | } |
| 199 | |
| 200 | return nil |
| 201 | } |
| 202 | |
| 203 | func (x *Xray) UpdateUsersAndRestart(ctx context.Context, users []*common.User) error { |
| 204 | x.config.updateUsers(users) |
nothing calls this directly
no test coverage detected