get5loader icon indicating copy to clipboard operation
get5loader copied to clipboard

権限の確認を行うドメインサービスを作成する

Open FlowingSPDG opened this issue 2 years ago • 0 comments

type CheckPermission interface{
	CheckMatchEditable(ctx context.Context, match *entity.Match) (bool, error)
}

type checkPermission struct{}

func (cp *checkPermission) CheckMatchEditable() (bool,error) {
	op, err := g5ctx.GetOperation(ctx)
	if err != nil {
		return false, err
	}
	switch op {
	case g5ctx.OperationTypeSystem:
		return true
	case g5ctx.OperationTypeUser:
		token, err := g5ctx.GetUserToken(ctx)
		if err != nil {
			return nil, err
		}
		if token.Admin {
			return true
		}
		if token.UserID == match.UserID {
			return true
		}
	}
	return false
}

FlowingSPDG avatar Aug 07 '23 20:08 FlowingSPDG