klesh commented on code in PR #2461: URL: https://github.com/apache/incubator-devlake/pull/2461#discussion_r921110354
########## plugins/org/api/blueprint.go: ########## @@ -0,0 +1,52 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package api + +import ( + "encoding/json" + + "github.com/apache/incubator-devlake/plugins/core" + "github.com/apache/incubator-devlake/plugins/helper" +) + +func MakePipelinePlan(subtaskMetas []core.SubTaskMeta, connectionId uint64, scope []*core.BlueprintScopeV100) (core.PipelinePlan, error) { Review Comment: I don't think this is needed. Only data-source plugins need to implement this for the new config-ui flow. ########## plugins/org/tasks/user_account.go: ########## @@ -0,0 +1,119 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package tasks + +import ( + "github.com/apache/incubator-devlake/models/common" + "reflect" + + "github.com/apache/incubator-devlake/models/domainlayer/crossdomain" + "github.com/apache/incubator-devlake/plugins/core" + "github.com/apache/incubator-devlake/plugins/core/dal" + "github.com/apache/incubator-devlake/plugins/helper" +) + +var ConnectUserAccountsExactMeta = core.SubTaskMeta{ + Name: "connectUserAccountsExact", + EntryPoint: ConnectUserAccountsExact, + EnabledByDefault: false, + Description: "associate users and accounts", + DomainTypes: []string{core.DOMAIN_TYPE_CROSS}, +} + +func ConnectUserAccountsExact(taskCtx core.SubTaskContext) error { + db := taskCtx.GetDal() + data := taskCtx.GetData().(*TaskData) + type input struct { + UserId string + AccountId string + common.NoPKModel + } + var users []crossdomain.User + err := db.All(&users) + if err != nil { + return err + } + err = db.Delete(&crossdomain.UserAccount{}, dal.Where("1=1")) Review Comment: We shouldn't delete the existing relationship, but try to connect orphaned `accounts` to possible matched `users` ########## plugins/org/api/user_account_mapping.go: ########## @@ -0,0 +1,87 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package api + +import ( + "net/http" + + "github.com/apache/incubator-devlake/models/domainlayer/crossdomain" + "github.com/apache/incubator-devlake/plugins/core" + "github.com/gocarina/gocsv" +) + +// GetUserAccountMapping godoc +// @Summary Get user_account_mapping.csv.csv file +// @Description get user_account_mapping.csv.csv file +// @Tags plugins/org +// @Produce text/csv +// @Success 200 +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/org/accounts.csv [get] Review Comment: /plugins/org/user_account_mapping.csv ########## plugins/org/api/user_account_mapping.go: ########## @@ -0,0 +1,87 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package api + +import ( + "net/http" + + "github.com/apache/incubator-devlake/models/domainlayer/crossdomain" + "github.com/apache/incubator-devlake/plugins/core" + "github.com/gocarina/gocsv" +) + +// GetUserAccountMapping godoc +// @Summary Get user_account_mapping.csv.csv file +// @Description get user_account_mapping.csv.csv file +// @Tags plugins/org +// @Produce text/csv +// @Success 200 +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/org/accounts.csv [get] +func (h *Handlers) GetUserAccountMapping(input *core.ApiResourceInput) (*core.ApiResourceOutput, error) { + accounts, err := h.store.findAllAccounts() + if err != nil { + return nil, err + } + blob, err := gocsv.MarshalBytes(accounts) + if err != nil { + return nil, err + } + return &core.ApiResourceOutput{ + Body: nil, + Status: http.StatusOK, + File: &core.OutputFile{ + ContentType: "text/csv", + Data: blob, + }, + }, nil +} + +// CreateUserAccountMapping godoc +// @Summary Upload user_account_mapping.csv.csv file +// @Description upload user_account_mapping.csv.csv file +// @Tags plugins/org +// @Accept text/csv +// @Produce json +// @Success 200 +// @Failure 400 {object} shared.ApiBody "Bad Request" +// @Failure 500 {object} shared.ApiBody "Internal Error" +// @Router /plugins/org/accounts.csv [put] Review Comment: /plugins/org/user_account_mapping.csv -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
