2020-05-11 10:16:29 +00:00
|
|
|
package eventstore
|
2020-04-07 11:23:04 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-06-25 09:25:38 +00:00
|
|
|
"strings"
|
|
|
|
|
2020-06-30 05:54:39 +00:00
|
|
|
"github.com/caos/logging"
|
2020-07-08 11:56:37 +00:00
|
|
|
|
|
|
|
"github.com/caos/zitadel/internal/api/authz"
|
2020-06-19 13:32:03 +00:00
|
|
|
caos_errs "github.com/caos/zitadel/internal/errors"
|
|
|
|
es_int "github.com/caos/zitadel/internal/eventstore"
|
|
|
|
"github.com/caos/zitadel/internal/eventstore/models"
|
|
|
|
es_models "github.com/caos/zitadel/internal/eventstore/models"
|
|
|
|
es_sdk "github.com/caos/zitadel/internal/eventstore/sdk"
|
2020-09-01 14:38:34 +00:00
|
|
|
iam_event "github.com/caos/zitadel/internal/iam/repository/eventsourcing"
|
2020-07-08 11:56:37 +00:00
|
|
|
"github.com/caos/zitadel/internal/management/repository/eventsourcing/view"
|
|
|
|
global_model "github.com/caos/zitadel/internal/model"
|
|
|
|
proj_model "github.com/caos/zitadel/internal/project/model"
|
|
|
|
proj_event "github.com/caos/zitadel/internal/project/repository/eventsourcing"
|
2020-06-19 13:32:03 +00:00
|
|
|
es_proj_model "github.com/caos/zitadel/internal/project/repository/eventsourcing/model"
|
2020-07-08 11:56:37 +00:00
|
|
|
"github.com/caos/zitadel/internal/project/repository/view/model"
|
2020-06-29 07:37:10 +00:00
|
|
|
usr_event "github.com/caos/zitadel/internal/user/repository/eventsourcing"
|
2020-06-19 13:32:03 +00:00
|
|
|
usr_grant_model "github.com/caos/zitadel/internal/usergrant/model"
|
|
|
|
usr_grant_event "github.com/caos/zitadel/internal/usergrant/repository/eventsourcing"
|
2020-04-07 11:23:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ProjectRepo struct {
|
2020-06-19 13:32:03 +00:00
|
|
|
es_int.Eventstore
|
|
|
|
SearchLimit uint64
|
|
|
|
ProjectEvents *proj_event.ProjectEventstore
|
|
|
|
UserGrantEvents *usr_grant_event.UserGrantEventStore
|
2020-06-29 07:37:10 +00:00
|
|
|
UserEvents *usr_event.UserEventstore
|
2020-09-01 14:38:34 +00:00
|
|
|
IAMEvents *iam_event.IAMEventstore
|
2020-06-19 13:32:03 +00:00
|
|
|
View *view.View
|
|
|
|
Roles []string
|
2020-09-01 14:38:34 +00:00
|
|
|
IAMID string
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 05:06:07 +00:00
|
|
|
func (repo *ProjectRepo) ProjectByID(ctx context.Context, id string) (*proj_model.ProjectView, error) {
|
2020-07-08 12:26:35 +00:00
|
|
|
project, viewErr := repo.View.ProjectByID(id)
|
|
|
|
if viewErr != nil && !caos_errs.IsNotFound(viewErr) {
|
|
|
|
return nil, viewErr
|
2020-06-23 05:06:07 +00:00
|
|
|
}
|
2020-07-08 12:26:35 +00:00
|
|
|
if caos_errs.IsNotFound(viewErr) {
|
2020-07-07 17:28:19 +00:00
|
|
|
project = new(model.ProjectView)
|
|
|
|
}
|
2020-06-30 05:54:39 +00:00
|
|
|
|
2020-07-08 12:26:35 +00:00
|
|
|
events, esErr := repo.ProjectEvents.ProjectEventsByID(ctx, id, project.Sequence)
|
|
|
|
if caos_errs.IsNotFound(viewErr) && len(events) == 0 {
|
|
|
|
return nil, caos_errs.ThrowNotFound(nil, "EVENT-8yfKu", "Errors.Project.NotFound")
|
|
|
|
}
|
|
|
|
|
|
|
|
if esErr != nil {
|
|
|
|
logging.Log("EVENT-V9x1V").WithError(viewErr).Debug("error retrieving new events")
|
2020-06-30 05:54:39 +00:00
|
|
|
return model.ProjectToModel(project), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
viewProject := *project
|
|
|
|
for _, event := range events {
|
|
|
|
err := project.AppendEvent(event)
|
|
|
|
if err != nil {
|
|
|
|
return model.ProjectToModel(&viewProject), nil
|
|
|
|
}
|
|
|
|
}
|
2020-10-07 06:16:42 +00:00
|
|
|
if viewProject.State == int32(proj_model.ProjectStateRemoved) {
|
|
|
|
return nil, caos_errs.ThrowNotFound(nil, "EVENT-3Mo0s", "Errors.Project.NotFound")
|
|
|
|
}
|
2020-06-23 05:06:07 +00:00
|
|
|
return model.ProjectToModel(project), nil
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
2020-10-16 05:49:38 +00:00
|
|
|
func (repo *ProjectRepo) CreateProject(ctx context.Context, project *proj_model.Project) (*proj_model.Project, error) {
|
2020-09-01 14:38:34 +00:00
|
|
|
ctxData := authz.GetCtxData(ctx)
|
|
|
|
iam, err := repo.IAMEvents.IAMByID(ctx, repo.IAMID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return repo.ProjectEvents.CreateProject(ctx, project, iam.GlobalOrgID == ctxData.OrgID)
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) UpdateProject(ctx context.Context, project *proj_model.Project) (*proj_model.Project, error) {
|
2020-04-15 15:11:42 +00:00
|
|
|
return repo.ProjectEvents.UpdateProject(ctx, project)
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) DeactivateProject(ctx context.Context, id string) (*proj_model.Project, error) {
|
2020-04-15 15:11:42 +00:00
|
|
|
return repo.ProjectEvents.DeactivateProject(ctx, id)
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) ReactivateProject(ctx context.Context, id string) (*proj_model.Project, error) {
|
2020-04-15 15:11:42 +00:00
|
|
|
return repo.ProjectEvents.ReactivateProject(ctx, id)
|
|
|
|
}
|
|
|
|
|
2020-08-05 16:32:25 +00:00
|
|
|
func (repo *ProjectRepo) RemoveProject(ctx context.Context, projectID string) error {
|
|
|
|
proj := proj_model.NewProject(projectID)
|
|
|
|
aggregates := make([]*es_models.Aggregate, 0)
|
|
|
|
project, agg, err := repo.ProjectEvents.PrepareRemoveProject(ctx, proj)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
aggregates = append(aggregates, agg)
|
|
|
|
|
|
|
|
// remove user_grants
|
|
|
|
usergrants, err := repo.View.UserGrantsByProjectID(projectID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, grant := range usergrants {
|
|
|
|
_, aggs, err := repo.UserGrantEvents.PrepareRemoveUserGrant(ctx, grant.ID, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, agg := range aggs {
|
|
|
|
aggregates = append(aggregates, agg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return es_sdk.PushAggregates(ctx, repo.Eventstore.PushAggregates, project.AppendEvents, aggregates...)
|
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func (repo *ProjectRepo) SearchProjects(ctx context.Context, request *proj_model.ProjectViewSearchRequest) (*proj_model.ProjectViewSearchResponse, error) {
|
2020-05-11 10:16:29 +00:00
|
|
|
request.EnsureLimit(repo.SearchLimit)
|
2020-08-26 07:56:23 +00:00
|
|
|
sequence, sequenceErr := repo.View.GetLatestProjectSequence()
|
|
|
|
logging.Log("EVENT-Edc56").OnError(sequenceErr).Warn("could not read latest project sequence")
|
2020-06-05 05:50:04 +00:00
|
|
|
|
2020-07-22 12:00:29 +00:00
|
|
|
permissions := authz.GetRequestPermissionsFromCtx(ctx)
|
2020-07-08 11:56:37 +00:00
|
|
|
if !authz.HasGlobalPermission(permissions) {
|
2020-07-22 12:00:29 +00:00
|
|
|
ids := authz.GetAllPermissionCtxIDs(permissions)
|
|
|
|
if _, q := request.GetSearchQuery(proj_model.ProjectViewSearchKeyProjectID); q != nil {
|
|
|
|
containsID := false
|
|
|
|
for _, id := range ids {
|
|
|
|
if id == q.Value {
|
|
|
|
containsID = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !containsID {
|
|
|
|
result := &proj_model.ProjectViewSearchResponse{
|
|
|
|
Offset: request.Offset,
|
|
|
|
Limit: request.Limit,
|
|
|
|
TotalResult: uint64(0),
|
|
|
|
Result: []*proj_model.ProjectView{},
|
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
if sequenceErr == nil {
|
2020-07-22 12:00:29 +00:00
|
|
|
result.Sequence = sequence.CurrentSequence
|
|
|
|
result.Timestamp = sequence.CurrentTimestamp
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
request.Queries = append(request.Queries, &proj_model.ProjectViewSearchQuery{Key: proj_model.ProjectViewSearchKeyProjectID, Method: global_model.SearchMethodIsOneOf, Value: ids})
|
|
|
|
}
|
2020-06-05 05:50:04 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
projects, count, err := repo.View.SearchProjects(request)
|
2020-05-11 10:16:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-15 11:24:36 +00:00
|
|
|
result := &proj_model.ProjectViewSearchResponse{
|
2020-05-11 10:16:29 +00:00
|
|
|
Offset: request.Offset,
|
|
|
|
Limit: request.Limit,
|
|
|
|
TotalResult: uint64(count),
|
2020-06-15 12:50:39 +00:00
|
|
|
Result: model.ProjectsToModel(projects),
|
2020-07-15 11:24:36 +00:00
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
if sequenceErr == nil {
|
2020-07-15 11:24:36 +00:00
|
|
|
result.Sequence = sequence.CurrentSequence
|
|
|
|
result.Timestamp = sequence.CurrentTimestamp
|
|
|
|
}
|
|
|
|
return result, nil
|
2020-05-11 10:16:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func (repo *ProjectRepo) ProjectGrantViewByID(ctx context.Context, grantID string) (project *proj_model.ProjectGrantView, err error) {
|
|
|
|
p, err := repo.View.ProjectGrantByID(grantID)
|
2020-06-10 12:28:15 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-15 12:50:39 +00:00
|
|
|
return model.ProjectGrantToModel(p), nil
|
2020-06-10 12:28:15 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 05:06:07 +00:00
|
|
|
func (repo *ProjectRepo) ProjectMemberByID(ctx context.Context, projectID, userID string) (*proj_model.ProjectMemberView, error) {
|
|
|
|
member, err := repo.View.ProjectMemberByIDs(projectID, userID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return model.ProjectMemberToModel(member), nil
|
2020-04-15 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) AddProjectMember(ctx context.Context, member *proj_model.ProjectMember) (*proj_model.ProjectMember, error) {
|
|
|
|
return repo.ProjectEvents.AddProjectMember(ctx, member)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) ChangeProjectMember(ctx context.Context, member *proj_model.ProjectMember) (*proj_model.ProjectMember, error) {
|
|
|
|
return repo.ProjectEvents.ChangeProjectMember(ctx, member)
|
|
|
|
}
|
2020-04-07 11:23:04 +00:00
|
|
|
|
2020-04-15 15:11:42 +00:00
|
|
|
func (repo *ProjectRepo) RemoveProjectMember(ctx context.Context, projectID, userID string) error {
|
|
|
|
member := proj_model.NewProjectMember(projectID, userID)
|
|
|
|
return repo.ProjectEvents.RemoveProjectMember(ctx, member)
|
2020-04-07 11:23:04 +00:00
|
|
|
}
|
2020-04-21 15:00:32 +00:00
|
|
|
|
2020-05-11 10:16:29 +00:00
|
|
|
func (repo *ProjectRepo) SearchProjectMembers(ctx context.Context, request *proj_model.ProjectMemberSearchRequest) (*proj_model.ProjectMemberSearchResponse, error) {
|
|
|
|
request.EnsureLimit(repo.SearchLimit)
|
2020-08-26 07:56:23 +00:00
|
|
|
sequence, sequenceErr := repo.View.GetLatestProjectMemberSequence()
|
|
|
|
logging.Log("EVENT-3dgt6").OnError(sequenceErr).Warn("could not read latest project member sequence")
|
2020-05-11 10:16:29 +00:00
|
|
|
members, count, err := repo.View.SearchProjectMembers(request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-15 11:24:36 +00:00
|
|
|
result := &proj_model.ProjectMemberSearchResponse{
|
2020-05-11 10:16:29 +00:00
|
|
|
Offset: request.Offset,
|
|
|
|
Limit: request.Limit,
|
|
|
|
TotalResult: uint64(count),
|
|
|
|
Result: model.ProjectMembersToModel(members),
|
2020-07-15 11:24:36 +00:00
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
if sequenceErr == nil {
|
2020-07-15 11:24:36 +00:00
|
|
|
result.Sequence = sequence.CurrentSequence
|
|
|
|
result.Timestamp = sequence.CurrentTimestamp
|
|
|
|
}
|
|
|
|
return result, nil
|
2020-05-11 10:16:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 13:32:03 +00:00
|
|
|
func (repo *ProjectRepo) AddProjectRole(ctx context.Context, role *proj_model.ProjectRole) (*proj_model.ProjectRole, error) {
|
|
|
|
return repo.ProjectEvents.AddProjectRoles(ctx, role)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) BulkAddProjectRole(ctx context.Context, roles []*proj_model.ProjectRole) error {
|
|
|
|
_, err := repo.ProjectEvents.AddProjectRoles(ctx, roles...)
|
|
|
|
return err
|
2020-04-21 15:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) ChangeProjectRole(ctx context.Context, member *proj_model.ProjectRole) (*proj_model.ProjectRole, error) {
|
|
|
|
return repo.ProjectEvents.ChangeProjectRole(ctx, member)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) RemoveProjectRole(ctx context.Context, projectID, key string) error {
|
2020-06-19 13:32:03 +00:00
|
|
|
role := proj_model.NewProjectRole(projectID, key)
|
|
|
|
aggregates := make([]*es_models.Aggregate, 0)
|
|
|
|
project, agg, err := repo.ProjectEvents.PrepareRemoveProjectRole(ctx, role)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
aggregates = append(aggregates, agg)
|
|
|
|
|
|
|
|
usergrants, err := repo.View.UserGrantsByProjectIDAndRoleKey(projectID, key)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, grant := range usergrants {
|
|
|
|
changed := &usr_grant_model.UserGrant{
|
|
|
|
ObjectRoot: models.ObjectRoot{AggregateID: grant.ID, Sequence: grant.Sequence, ResourceOwner: grant.ResourceOwner},
|
|
|
|
RoleKeys: grant.RoleKeys,
|
|
|
|
ProjectID: grant.ProjectID,
|
|
|
|
UserID: grant.UserID,
|
|
|
|
}
|
|
|
|
changed.RemoveRoleKeyIfExisting(key)
|
|
|
|
_, agg, err := repo.UserGrantEvents.PrepareChangeUserGrant(ctx, changed, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
aggregates = append(aggregates, agg)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = es_sdk.PushAggregates(ctx, repo.Eventstore.PushAggregates, project.AppendEvents, aggregates...)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2020-04-21 15:00:32 +00:00
|
|
|
}
|
|
|
|
|
2020-07-15 11:24:36 +00:00
|
|
|
func (repo *ProjectRepo) SearchProjectRoles(ctx context.Context, projectID string, request *proj_model.ProjectRoleSearchRequest) (*proj_model.ProjectRoleSearchResponse, error) {
|
2020-05-11 10:16:29 +00:00
|
|
|
request.EnsureLimit(repo.SearchLimit)
|
2020-07-15 11:24:36 +00:00
|
|
|
request.AppendProjectQuery(projectID)
|
2020-08-26 07:56:23 +00:00
|
|
|
sequence, sequenceErr := repo.View.GetLatestProjectRoleSequence()
|
|
|
|
logging.Log("LSp0d-47suf").OnError(sequenceErr).Warn("could not read latest project role sequence")
|
2020-05-11 10:16:29 +00:00
|
|
|
roles, count, err := repo.View.SearchProjectRoles(request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-15 11:24:36 +00:00
|
|
|
|
|
|
|
result := &proj_model.ProjectRoleSearchResponse{
|
2020-05-11 10:16:29 +00:00
|
|
|
Offset: request.Offset,
|
|
|
|
Limit: request.Limit,
|
2020-08-26 07:56:23 +00:00
|
|
|
TotalResult: count,
|
2020-05-11 10:16:29 +00:00
|
|
|
Result: model.ProjectRolesToModel(roles),
|
2020-07-15 11:24:36 +00:00
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
if sequenceErr == nil {
|
2020-07-15 11:24:36 +00:00
|
|
|
result.Sequence = sequence.CurrentSequence
|
|
|
|
result.Timestamp = sequence.CurrentTimestamp
|
|
|
|
}
|
|
|
|
return result, nil
|
2020-05-11 10:16:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 09:25:38 +00:00
|
|
|
func (repo *ProjectRepo) ProjectChanges(ctx context.Context, id string, lastSequence uint64, limit uint64, sortAscending bool) (*proj_model.ProjectChanges, error) {
|
|
|
|
changes, err := repo.ProjectEvents.ProjectChanges(ctx, id, lastSequence, limit, sortAscending)
|
2020-06-15 14:50:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-29 07:37:10 +00:00
|
|
|
for _, change := range changes.Changes {
|
|
|
|
change.ModifierName = change.ModifierId
|
|
|
|
user, _ := repo.UserEvents.UserByID(ctx, change.ModifierId)
|
|
|
|
if user != nil {
|
2020-11-12 16:01:30 +00:00
|
|
|
if user.Human != nil {
|
|
|
|
change.ModifierName = user.DisplayName
|
|
|
|
}
|
|
|
|
if user.Machine != nil {
|
|
|
|
change.ModifierName = user.Machine.Name
|
|
|
|
}
|
2020-06-29 07:37:10 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-15 14:50:09 +00:00
|
|
|
return changes, nil
|
|
|
|
}
|
|
|
|
|
2020-08-10 07:34:56 +00:00
|
|
|
func (repo *ProjectRepo) ApplicationByID(ctx context.Context, projectID, appID string) (*proj_model.ApplicationView, error) {
|
2020-08-13 06:28:18 +00:00
|
|
|
app, viewErr := repo.View.ApplicationByID(projectID, appID)
|
2020-08-10 07:34:56 +00:00
|
|
|
if viewErr != nil && !caos_errs.IsNotFound(viewErr) {
|
|
|
|
return nil, viewErr
|
|
|
|
}
|
|
|
|
if caos_errs.IsNotFound(viewErr) {
|
|
|
|
app = new(model.ApplicationView)
|
2020-08-13 06:28:18 +00:00
|
|
|
app.ID = appID
|
2020-08-10 07:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
events, esErr := repo.ProjectEvents.ProjectEventsByID(ctx, projectID, app.Sequence)
|
|
|
|
if caos_errs.IsNotFound(viewErr) && len(events) == 0 {
|
|
|
|
return nil, caos_errs.ThrowNotFound(nil, "EVENT-Fshu8", "Errors.Application.NotFound")
|
|
|
|
}
|
|
|
|
|
|
|
|
if esErr != nil {
|
|
|
|
logging.Log("EVENT-SLCo9").WithError(viewErr).Debug("error retrieving new events")
|
|
|
|
return model.ApplicationViewToModel(app), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
viewApp := *app
|
|
|
|
for _, event := range events {
|
2020-08-13 06:28:18 +00:00
|
|
|
err := app.AppendEventIfMyApp(event)
|
2020-08-10 07:34:56 +00:00
|
|
|
if err != nil {
|
|
|
|
return model.ApplicationViewToModel(&viewApp), nil
|
|
|
|
}
|
2020-08-13 06:28:18 +00:00
|
|
|
if app.State == int32(proj_model.AppStateRemoved) {
|
|
|
|
return nil, caos_errs.ThrowNotFound(nil, "EVENT-Msl96", "Errors.Application.NotFound")
|
|
|
|
}
|
2020-06-23 05:06:07 +00:00
|
|
|
}
|
|
|
|
return model.ApplicationViewToModel(app), nil
|
2020-04-21 15:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) AddApplication(ctx context.Context, app *proj_model.Application) (*proj_model.Application, error) {
|
|
|
|
return repo.ProjectEvents.AddApplication(ctx, app)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) ChangeApplication(ctx context.Context, app *proj_model.Application) (*proj_model.Application, error) {
|
|
|
|
return repo.ProjectEvents.ChangeApplication(ctx, app)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) DeactivateApplication(ctx context.Context, projectID, appID string) (*proj_model.Application, error) {
|
|
|
|
return repo.ProjectEvents.DeactivateApplication(ctx, projectID, appID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) ReactivateApplication(ctx context.Context, projectID, appID string) (*proj_model.Application, error) {
|
|
|
|
return repo.ProjectEvents.ReactivateApplication(ctx, projectID, appID)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) RemoveApplication(ctx context.Context, projectID, appID string) error {
|
|
|
|
app := proj_model.NewApplication(projectID, appID)
|
|
|
|
return repo.ProjectEvents.RemoveApplication(ctx, app)
|
|
|
|
}
|
|
|
|
|
2020-05-11 10:16:29 +00:00
|
|
|
func (repo *ProjectRepo) SearchApplications(ctx context.Context, request *proj_model.ApplicationSearchRequest) (*proj_model.ApplicationSearchResponse, error) {
|
|
|
|
request.EnsureLimit(repo.SearchLimit)
|
2020-08-26 07:56:23 +00:00
|
|
|
sequence, sequenceErr := repo.View.GetLatestApplicationSequence()
|
|
|
|
logging.Log("EVENT-SKe8s").OnError(sequenceErr).Warn("could not read latest application sequence")
|
2020-05-11 10:16:29 +00:00
|
|
|
apps, count, err := repo.View.SearchApplications(request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-15 11:24:36 +00:00
|
|
|
result := &proj_model.ApplicationSearchResponse{
|
2020-05-11 10:16:29 +00:00
|
|
|
Offset: request.Offset,
|
|
|
|
Limit: request.Limit,
|
2020-08-26 07:56:23 +00:00
|
|
|
TotalResult: count,
|
2020-05-11 10:16:29 +00:00
|
|
|
Result: model.ApplicationViewsToModel(apps),
|
2020-07-15 11:24:36 +00:00
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
if sequenceErr == nil {
|
2020-07-15 11:24:36 +00:00
|
|
|
result.Sequence = sequence.CurrentSequence
|
|
|
|
result.Timestamp = sequence.CurrentTimestamp
|
|
|
|
}
|
|
|
|
return result, nil
|
2020-05-11 10:16:29 +00:00
|
|
|
}
|
|
|
|
|
2020-06-25 09:25:38 +00:00
|
|
|
func (repo *ProjectRepo) ApplicationChanges(ctx context.Context, id string, appId string, lastSequence uint64, limit uint64, sortAscending bool) (*proj_model.ApplicationChanges, error) {
|
|
|
|
changes, err := repo.ProjectEvents.ApplicationChanges(ctx, id, appId, lastSequence, limit, sortAscending)
|
2020-06-15 14:50:09 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-06-29 07:37:10 +00:00
|
|
|
for _, change := range changes.Changes {
|
|
|
|
change.ModifierName = change.ModifierId
|
|
|
|
user, _ := repo.UserEvents.UserByID(ctx, change.ModifierId)
|
|
|
|
if user != nil {
|
2020-11-12 16:01:30 +00:00
|
|
|
if user.Human != nil {
|
|
|
|
change.ModifierName = user.DisplayName
|
|
|
|
}
|
|
|
|
if user.Machine != nil {
|
|
|
|
change.ModifierName = user.Machine.Name
|
|
|
|
}
|
2020-06-29 07:37:10 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-15 14:50:09 +00:00
|
|
|
return changes, nil
|
|
|
|
}
|
|
|
|
|
2020-04-21 15:00:32 +00:00
|
|
|
func (repo *ProjectRepo) ChangeOIDCConfig(ctx context.Context, config *proj_model.OIDCConfig) (*proj_model.OIDCConfig, error) {
|
|
|
|
return repo.ProjectEvents.ChangeOIDCConfig(ctx, config)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) ChangeOIDConfigSecret(ctx context.Context, projectID, appID string) (*proj_model.OIDCConfig, error) {
|
|
|
|
return repo.ProjectEvents.ChangeOIDCConfigSecret(ctx, projectID, appID)
|
|
|
|
}
|
2020-04-23 05:54:40 +00:00
|
|
|
|
2020-06-23 05:06:07 +00:00
|
|
|
func (repo *ProjectRepo) ProjectGrantByID(ctx context.Context, grantID string) (*proj_model.ProjectGrantView, error) {
|
|
|
|
grant, err := repo.View.ProjectGrantByID(grantID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return model.ProjectGrantToModel(grant), nil
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 12:50:39 +00:00
|
|
|
func (repo *ProjectRepo) SearchProjectGrants(ctx context.Context, request *proj_model.ProjectGrantViewSearchRequest) (*proj_model.ProjectGrantViewSearchResponse, error) {
|
|
|
|
request.EnsureLimit(repo.SearchLimit)
|
2020-08-26 07:56:23 +00:00
|
|
|
sequence, sequenceErr := repo.View.GetLatestProjectGrantSequence()
|
|
|
|
logging.Log("EVENT-Skw9f").OnError(sequenceErr).Warn("could not read latest project grant sequence")
|
2020-06-15 12:50:39 +00:00
|
|
|
projects, count, err := repo.View.SearchProjectGrants(request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-15 11:24:36 +00:00
|
|
|
result := &proj_model.ProjectGrantViewSearchResponse{
|
2020-06-15 12:50:39 +00:00
|
|
|
Offset: request.Offset,
|
|
|
|
Limit: request.Limit,
|
2020-08-26 07:56:23 +00:00
|
|
|
TotalResult: count,
|
2020-06-15 12:50:39 +00:00
|
|
|
Result: model.ProjectGrantsToModel(projects),
|
2020-07-15 11:24:36 +00:00
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
if sequenceErr == nil {
|
2020-07-15 11:24:36 +00:00
|
|
|
result.Sequence = sequence.CurrentSequence
|
|
|
|
result.Timestamp = sequence.CurrentTimestamp
|
|
|
|
}
|
|
|
|
return result, nil
|
2020-06-15 12:50:39 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 12:00:29 +00:00
|
|
|
func (repo *ProjectRepo) SearchGrantedProjects(ctx context.Context, request *proj_model.ProjectGrantViewSearchRequest) (*proj_model.ProjectGrantViewSearchResponse, error) {
|
|
|
|
request.EnsureLimit(repo.SearchLimit)
|
2020-08-26 07:56:23 +00:00
|
|
|
sequence, sequenceErr := repo.View.GetLatestProjectGrantSequence()
|
|
|
|
logging.Log("EVENT-Skw9f").OnError(sequenceErr).Warn("could not read latest project grant sequence")
|
2020-07-22 12:00:29 +00:00
|
|
|
|
|
|
|
permissions := authz.GetRequestPermissionsFromCtx(ctx)
|
|
|
|
if !authz.HasGlobalPermission(permissions) {
|
|
|
|
ids := authz.GetAllPermissionCtxIDs(permissions)
|
|
|
|
if _, q := request.GetSearchQuery(proj_model.GrantedProjectSearchKeyGrantID); q != nil {
|
|
|
|
containsID := false
|
|
|
|
for _, id := range ids {
|
|
|
|
if id == q.Value {
|
|
|
|
containsID = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !containsID {
|
|
|
|
result := &proj_model.ProjectGrantViewSearchResponse{
|
|
|
|
Offset: request.Offset,
|
|
|
|
Limit: request.Limit,
|
|
|
|
TotalResult: uint64(0),
|
|
|
|
Result: []*proj_model.ProjectGrantView{},
|
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
if sequenceErr == nil {
|
2020-07-22 12:00:29 +00:00
|
|
|
result.Sequence = sequence.CurrentSequence
|
|
|
|
result.Timestamp = sequence.CurrentTimestamp
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
request.Queries = append(request.Queries, &proj_model.ProjectGrantViewSearchQuery{Key: proj_model.GrantedProjectSearchKeyGrantID, Method: global_model.SearchMethodIsOneOf, Value: ids})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
projects, count, err := repo.View.SearchProjectGrants(request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
result := &proj_model.ProjectGrantViewSearchResponse{
|
|
|
|
Offset: request.Offset,
|
|
|
|
Limit: request.Limit,
|
2020-08-26 07:56:23 +00:00
|
|
|
TotalResult: count,
|
2020-07-22 12:00:29 +00:00
|
|
|
Result: model.ProjectGrantsToModel(projects),
|
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
if sequenceErr == nil {
|
2020-07-22 12:00:29 +00:00
|
|
|
result.Sequence = sequence.CurrentSequence
|
|
|
|
result.Timestamp = sequence.CurrentTimestamp
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2020-06-19 13:32:03 +00:00
|
|
|
func (repo *ProjectRepo) AddProjectGrant(ctx context.Context, grant *proj_model.ProjectGrant) (*proj_model.ProjectGrant, error) {
|
|
|
|
return repo.ProjectEvents.AddProjectGrant(ctx, grant)
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 13:32:03 +00:00
|
|
|
func (repo *ProjectRepo) ChangeProjectGrant(ctx context.Context, grant *proj_model.ProjectGrant) (*proj_model.ProjectGrant, error) {
|
|
|
|
project, aggFunc, removedRoles, err := repo.ProjectEvents.PrepareChangeProjectGrant(ctx, grant)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
agg, err := aggFunc(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
aggregates := make([]*es_models.Aggregate, 0)
|
|
|
|
aggregates = append(aggregates, agg)
|
|
|
|
|
|
|
|
usergrants, err := repo.View.UserGrantsByProjectID(grant.AggregateID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for _, grant := range usergrants {
|
|
|
|
changed := &usr_grant_model.UserGrant{
|
|
|
|
ObjectRoot: models.ObjectRoot{AggregateID: grant.ID, Sequence: grant.Sequence, ResourceOwner: grant.ResourceOwner},
|
|
|
|
RoleKeys: grant.RoleKeys,
|
|
|
|
ProjectID: grant.ProjectID,
|
|
|
|
UserID: grant.UserID,
|
|
|
|
}
|
feat: split users into human and machine (#470)
* feat(management): service accounts
* chore: current go version
* init
* refactor: apis
* feat(internal): start impl of service account
* chore: start impl of machine/human users
* code compiles
* fix: tests
* fix: tests
* fix: add new event types to switches
* chore: add cases to event types
* fix(management): definitive proto messages
* fix: machine/human
* fix: add missing tables as todos
* fix: remove unused permissions
* fix: refactoring
* fix: refactor
* fix: human registered
* fix: user id
* fix: logid
* fix: proto remove //equal
* chore(management): remove no comment
* fix: human mfas
* fix: user subobjects
* chore: rename existing to better name
* fix: username in user (#634)
* fix: username in user
* fix: username
* fix remove unused code
* fix add validations
* fix: use new user in all apis
* fix: regexp for username in api
* fix: fill user data for human and machine (#638)
* fix: fill Display name grant/member handlers
fix: add description to grant/member objects in api
fix: check if user is human in login
* fix: remove description from member and grant
* chore: remove todos
* feat: machine keys
* fix: implement missing parts
* feat: machine key management view
* fix: remove keys from machine view
* fix: set default expiration date
* fix: get key by ids
* feat: add machine keys in proto
* feat: machine keys
* fix: add migration
* fix: mig
* fix: correct method name
* feat: user search
* feat: user search
* fix: log ids
* fix partial authconfig prompt, domain c perm
* membership read check
* contributor refresh trigger, observe org write
* fix: migrations
* fix(console): machine build (#660)
* frontend 1
* fix html bindings
* trailing comma
* user permissions, project deactivate
* fix(console): human view (#661)
* fix search user view, user detail form
* rm log
* feat(console): user services list and create (#663)
* fix search user view, user detail form
* rm log
* machine list
* generic table component
* create user service
* proove table for undefined values
* tmp disable user link if machine
* lint
* lint styles
* user table lint
* Update console/src/assets/i18n/de.json
Co-authored-by: Florian Forster <florian@caos.ch>
* feat(console): service user detail view, keys cr_d, fix search user autocomplete (#664)
* service users for sidenav, routing
* i18n
* back routes
* machine detail form
* update machine detail, fix svc user grants
* keys table
* add key dialog, timestamp creation
* check permission on create, delete, fix selection
* lint ts, scss
* Update console/src/assets/i18n/de.json
* Apply suggestions from code review
Co-authored-by: Florian Forster <florian@caos.ch>
* allow user grants for project.write
* management service
* fix mgmt service
* feat: Machine keys (#655)
* fix: memberships (#633)
* feat: add iam members to memberships
* fix: search project grants
* fix: rename
* feat: idp and login policy configurations (#619)
* feat: oidc config
* fix: oidc configurations
* feat: oidc idp config
* feat: add oidc config test
* fix: tests
* fix: tests
* feat: translate new events
* feat: idp eventstore
* feat: idp eventstore
* fix: tests
* feat: command side idp
* feat: query side idp
* feat: idp config on org
* fix: tests
* feat: authz idp on org
* feat: org idps
* feat: login policy
* feat: login policy
* feat: login policy
* feat: add idp func on login policy
* feat: add validation to loginpolicy and idp provider
* feat: add default login policy
* feat: login policy on org
* feat: login policy on org
* fix: id config handlers
* fix: id config handlers
* fix: create idp on org
* fix: create idp on org
* fix: not existing idp config
* fix: default login policy
* fix: add login policy on org
* fix: idp provider search on org
* fix: test
* fix: remove idp on org
* fix: test
* fix: test
* fix: remove admin idp
* fix: logo src as byte
* fix: migration
* fix: tests
* Update internal/iam/repository/eventsourcing/iam.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/iam/repository/eventsourcing/iam_test.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/iam/repository/eventsourcing/iam_test.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/iam/repository/eventsourcing/model/login_policy.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/iam/repository/eventsourcing/model/login_policy.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/org/repository/eventsourcing/org_test.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/iam/repository/eventsourcing/model/login_policy_test.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* Update internal/iam/repository/eventsourcing/model/login_policy_test.go
Co-authored-by: Silvan <silvan.reusser@gmail.com>
* fix: pr comments
* fix: tests
* Update types.go
* fix: merge request changes
* fix: reduce optimization
Co-authored-by: Silvan <silvan.reusser@gmail.com>
Co-authored-by: Livio Amstutz <livio.a@gmail.com>
* fix: reread user mfas, preferred loginname as otp account name (#636)
* fix: reread user mfas
* fix: use preferred login name as otp account name
* fix: tests
* fix: reduce (#635)
* fix: management reduce optimization
* fix: reduce optimization
* fix: reduce optimization
* fix: merge master
* chore(deps): bump github.com/gorilla/schema from 1.1.0 to 1.2.0 (#627)
Bumps [github.com/gorilla/schema](https://github.com/gorilla/schema) from 1.1.0 to 1.2.0.
- [Release notes](https://github.com/gorilla/schema/releases)
- [Commits](https://github.com/gorilla/schema/compare/v1.1.0...v1.2.0)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore(deps): bump github.com/gorilla/mux from 1.7.4 to 1.8.0 (#624)
Bumps [github.com/gorilla/mux](https://github.com/gorilla/mux) from 1.7.4 to 1.8.0.
- [Release notes](https://github.com/gorilla/mux/releases)
- [Commits](https://github.com/gorilla/mux/compare/v1.7.4...v1.8.0)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore(deps): bump github.com/DATA-DOG/go-sqlmock from 1.4.1 to 1.5.0 (#591)
Bumps [github.com/DATA-DOG/go-sqlmock](https://github.com/DATA-DOG/go-sqlmock) from 1.4.1 to 1.5.0.
- [Release notes](https://github.com/DATA-DOG/go-sqlmock/releases)
- [Commits](https://github.com/DATA-DOG/go-sqlmock/compare/v1.4.1...v1.5.0)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore: auto assign issues and PR to ZTIADEL project board (#643)
* Create main.yml
* Update main.yml
Co-authored-by: Livio Amstutz <livio.a@gmail.com>
* fix(console): project grant members, update deps (#645)
* fix: searchprojectgrantmembers
* chore(deps-dev): bump @angular/cli from 10.0.6 to 10.0.7 in /console (#622)
Bumps [@angular/cli](https://github.com/angular/angular-cli) from 10.0.6 to 10.0.7.
- [Release notes](https://github.com/angular/angular-cli/releases)
- [Commits](https://github.com/angular/angular-cli/compare/v10.0.6...v10.0.7)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore(deps-dev): bump @angular-devkit/build-angular in /console (#626)
Bumps [@angular-devkit/build-angular](https://github.com/angular/angular-cli) from 0.1000.6 to 0.1000.7.
- [Release notes](https://github.com/angular/angular-cli/releases)
- [Commits](https://github.com/angular/angular-cli/commits)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Peintner <max@caos.ch>
* chore(deps-dev): bump @types/jasmine from 3.5.12 to 3.5.13 in /console (#623)
Bumps [@types/jasmine](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jasmine) from 3.5.12 to 3.5.13.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jasmine)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore(deps-dev): bump ts-node from 8.10.2 to 9.0.0 in /console (#629)
Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 8.10.2 to 9.0.0.
- [Release notes](https://github.com/TypeStrong/ts-node/releases)
- [Commits](https://github.com/TypeStrong/ts-node/compare/v8.10.2...v9.0.0)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* update packlock
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* chore: delete main.yml (#648)
* fix: usergrant (#650)
* fix(console): mfa refresh after verification, member eventemitter (#651)
* refresh mfa
* fix: detail link from contributors
* lint
* feat: add domain verification notification (#649)
* fix: dont (re)generate client secret with auth type none
* fix(cors): allow Origin from request
* feat: add origin allow list and fix some core issues
* rename migration
* fix UserIDsByDomain
* feat: send email to users after domain claim
* username
* check origin on userinfo
* update oidc pkg
* fix: add migration 1.6
* change username
* change username
* remove unique email aggregate
* change username in mgmt
* search global user by login name
* fix test
* change user search in angular
* fix tests
* merge
* userview in angular
* fix merge
* Update pkg/grpc/management/proto/management.proto
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
* Update internal/notification/static/i18n/de.yaml
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
* fix
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
* fix: translation (#647)
* fix: translation
* fix: translation
* fix: translation
* fix: remove unused code
* fix: log err
* fix: migration numbers (#652)
* chore: issue / feature templates (#642)
* feat: machine keys
* fix: implement missing parts
* feat: machine key management view
* fix: remove keys from machine view
* feat: global org read (#657)
* fix: set default expiration date
* fix: get key by ids
* feat: add machine keys in proto
* feat: machine keys
* fix: add migration
* fix: mig
* fix: correct method name
* feat: user search
* feat: user search
* fix: log ids
* fix: migrations
* fix(console): machine build (#660)
* frontend 1
* fix html bindings
* trailing comma
* fix(console): human view (#661)
* fix search user view, user detail form
* rm log
* feat(console): user services list and create (#663)
* fix search user view, user detail form
* rm log
* machine list
* generic table component
* create user service
* proove table for undefined values
* tmp disable user link if machine
* lint
* lint styles
* user table lint
* Update console/src/assets/i18n/de.json
Co-authored-by: Florian Forster <florian@caos.ch>
* feat(console): service user detail view, keys cr_d, fix search user autocomplete (#664)
* service users for sidenav, routing
* i18n
* back routes
* machine detail form
* update machine detail, fix svc user grants
* keys table
* add key dialog, timestamp creation
* check permission on create, delete, fix selection
* lint ts, scss
* Update console/src/assets/i18n/de.json
* Apply suggestions from code review
Co-authored-by: Florian Forster <florian@caos.ch>
* refactor: protos
* fix(management): key expiration date
* fix: check if user is human
* fix: marshal key details
* fix: correct generate login names
* fix: logid
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
Co-authored-by: Livio Amstutz <livio.a@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com>
Co-authored-by: Florian Forster <florian@caos.ch>
* fix: naming
* refactor: findings
* fix: username
* fix: mfa upper case
* fix: tests
* fix: add translations
* reactivatemyorg req typeö
* fix: projectType for console
* fix: user changes
* fix: translate events
* fix: event type translation
* fix: remove unused types
Co-authored-by: Fabiennne <fabienne.gerschwiler@gmail.com>
Co-authored-by: Max Peintner <max@caos.ch>
Co-authored-by: Florian Forster <florian@caos.ch>
Co-authored-by: Fabi <38692350+fgerschwiler@users.noreply.github.com>
Co-authored-by: Livio Amstutz <livio.a@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-08-31 15:48:01 +00:00
|
|
|
roleDeleted := changed.RemoveRoleKeysIfExisting(removedRoles)
|
|
|
|
if roleDeleted {
|
2020-06-19 13:32:03 +00:00
|
|
|
_, agg, err := repo.UserGrantEvents.PrepareChangeUserGrant(ctx, changed, true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
aggregates = append(aggregates, agg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
err = es_sdk.PushAggregates(ctx, repo.Eventstore.PushAggregates, project.AppendEvents, aggregates...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if _, g := es_proj_model.GetProjectGrant(project.Grants, grant.GrantID); g != nil {
|
|
|
|
return es_proj_model.GrantToModel(g), nil
|
|
|
|
}
|
|
|
|
return nil, caos_errs.ThrowInternal(nil, "EVENT-dksi8", "Could not find app in list")
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 13:32:03 +00:00
|
|
|
func (repo *ProjectRepo) DeactivateProjectGrant(ctx context.Context, projectID, grantID string) (*proj_model.ProjectGrant, error) {
|
|
|
|
return repo.ProjectEvents.DeactivateProjectGrant(ctx, projectID, grantID)
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 13:32:03 +00:00
|
|
|
func (repo *ProjectRepo) ReactivateProjectGrant(ctx context.Context, projectID, grantID string) (*proj_model.ProjectGrant, error) {
|
|
|
|
return repo.ProjectEvents.ReactivateProjectGrant(ctx, projectID, grantID)
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-19 13:32:03 +00:00
|
|
|
func (repo *ProjectRepo) RemoveProjectGrant(ctx context.Context, projectID, grantID string) error {
|
|
|
|
grant, err := repo.ProjectEvents.ProjectGrantByIDs(ctx, projectID, grantID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
aggregates := make([]*es_models.Aggregate, 0)
|
|
|
|
project, aggFunc, err := repo.ProjectEvents.PrepareRemoveProjectGrant(ctx, grant)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
agg, err := aggFunc(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
aggregates = append(aggregates, agg)
|
|
|
|
|
|
|
|
usergrants, err := repo.View.UserGrantsByOrgIDAndProjectID(grant.GrantedOrgID, projectID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, grant := range usergrants {
|
|
|
|
_, grantAggregates, err := repo.UserGrantEvents.PrepareRemoveUserGrant(ctx, grant.ID, true)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, agg := range grantAggregates {
|
|
|
|
aggregates = append(aggregates, agg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
err = es_sdk.PushAggregates(ctx, repo.Eventstore.PushAggregates, project.AppendEvents, aggregates...)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-23 05:06:07 +00:00
|
|
|
func (repo *ProjectRepo) ProjectGrantMemberByID(ctx context.Context, projectID, userID string) (*proj_model.ProjectGrantMemberView, error) {
|
|
|
|
member, err := repo.View.ProjectGrantMemberByIDs(projectID, userID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return model.ProjectGrantMemberToModel(member), nil
|
2020-04-23 05:54:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) AddProjectGrantMember(ctx context.Context, member *proj_model.ProjectGrantMember) (*proj_model.ProjectGrantMember, error) {
|
|
|
|
return repo.ProjectEvents.AddProjectGrantMember(ctx, member)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) ChangeProjectGrantMember(ctx context.Context, member *proj_model.ProjectGrantMember) (*proj_model.ProjectGrantMember, error) {
|
|
|
|
return repo.ProjectEvents.ChangeProjectGrantMember(ctx, member)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) RemoveProjectGrantMember(ctx context.Context, projectID, grantID, userID string) error {
|
|
|
|
member := proj_model.NewProjectGrantMember(projectID, grantID, userID)
|
|
|
|
return repo.ProjectEvents.RemoveProjectGrantMember(ctx, member)
|
|
|
|
}
|
2020-05-11 10:16:29 +00:00
|
|
|
|
|
|
|
func (repo *ProjectRepo) SearchProjectGrantMembers(ctx context.Context, request *proj_model.ProjectGrantMemberSearchRequest) (*proj_model.ProjectGrantMemberSearchResponse, error) {
|
|
|
|
request.EnsureLimit(repo.SearchLimit)
|
2020-08-26 07:56:23 +00:00
|
|
|
sequence, sequenceErr := repo.View.GetLatestProjectGrantMemberSequence()
|
|
|
|
logging.Log("EVENT-Du8sk").OnError(sequenceErr).Warn("could not read latest project grant sequence")
|
2020-05-11 10:16:29 +00:00
|
|
|
members, count, err := repo.View.SearchProjectGrantMembers(request)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-07-15 11:24:36 +00:00
|
|
|
result := &proj_model.ProjectGrantMemberSearchResponse{
|
2020-05-11 10:16:29 +00:00
|
|
|
Offset: request.Offset,
|
|
|
|
Limit: request.Limit,
|
|
|
|
TotalResult: uint64(count),
|
|
|
|
Result: model.ProjectGrantMembersToModel(members),
|
2020-07-15 11:24:36 +00:00
|
|
|
}
|
2020-08-26 07:56:23 +00:00
|
|
|
if sequenceErr == nil {
|
2020-07-15 11:24:36 +00:00
|
|
|
result.Sequence = sequence.CurrentSequence
|
|
|
|
result.Timestamp = sequence.CurrentTimestamp
|
|
|
|
}
|
|
|
|
return result, nil
|
2020-05-11 10:16:29 +00:00
|
|
|
}
|
2020-05-26 14:46:16 +00:00
|
|
|
|
2020-09-01 14:38:34 +00:00
|
|
|
func (repo *ProjectRepo) GetProjectMemberRoles(ctx context.Context) ([]string, error) {
|
|
|
|
iam, err := repo.IAMEvents.IAMByID(ctx, repo.IAMID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-05-26 14:46:16 +00:00
|
|
|
roles := make([]string, 0)
|
2020-09-01 14:38:34 +00:00
|
|
|
global := authz.GetCtxData(ctx).OrgID == iam.GlobalOrgID
|
2020-05-26 14:46:16 +00:00
|
|
|
for _, roleMap := range repo.Roles {
|
|
|
|
if strings.HasPrefix(roleMap, "PROJECT") && !strings.HasPrefix(roleMap, "PROJECT_GRANT") {
|
2020-09-01 14:38:34 +00:00
|
|
|
if global && !strings.HasSuffix(roleMap, "GLOBAL") {
|
|
|
|
continue
|
|
|
|
}
|
2020-05-26 14:46:16 +00:00
|
|
|
roles = append(roles, roleMap)
|
|
|
|
}
|
|
|
|
}
|
2020-09-01 14:38:34 +00:00
|
|
|
return roles, nil
|
2020-05-26 14:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (repo *ProjectRepo) GetProjectGrantMemberRoles() []string {
|
|
|
|
roles := make([]string, 0)
|
|
|
|
for _, roleMap := range repo.Roles {
|
|
|
|
if strings.HasPrefix(roleMap, "PROJECT_GRANT") {
|
|
|
|
roles = append(roles, roleMap)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return roles
|
|
|
|
}
|