Skip to content

Commit 04ee5e3

Browse files
add ai ase review to license claims. Control license before feature usage. Rewrite HasAiCaseReviewEnabled
1 parent 96fa3c6 commit 04ee5e3

File tree

11 files changed

+73
-18
lines changed

11 files changed

+73
-18
lines changed

dto/license_dto.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type LicenseEntitlements struct {
2121
TestRun bool `json:"test_run"`
2222
Sanctions bool `json:"sanctions"`
2323
CaseAutoAssign bool `json:"auto_assignment"` //nolint:tagliatelle
24+
CaseAiAssist bool `json:"case_ai_assist"`
2425
}
2526

2627
func AdaptLicenseEntitlements(licenseEntitlements models.LicenseEntitlements) LicenseEntitlements {
@@ -35,6 +36,7 @@ func AdaptLicenseEntitlements(licenseEntitlements models.LicenseEntitlements) Li
3536
TestRun: licenseEntitlements.TestRun,
3637
Sanctions: licenseEntitlements.Sanctions,
3738
CaseAutoAssign: licenseEntitlements.CaseAutoAssign,
39+
CaseAiAssist: licenseEntitlements.CaseAiAssist,
3840
}
3941
}
4042

dto/organization_feature_access_dto.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ type APIOrganizationFeatureAccess struct {
1616
NameRecognition string `json:"name_recognition"`
1717
CaseAutoAssign string `json:"case_auto_assign"`
1818

19-
// user-scoped - temporarly at least
19+
// user-scoped
20+
// Currently only used to control display of the AI assist button in the UI - DO NOT use for anything else as it will be removed
2021
AiAssist string `json:"ai_assist"`
2122
}
2223

models/license.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ type LicenseEntitlements struct {
6161
TestRun bool
6262
Sanctions bool
6363
CaseAutoAssign bool
64+
CaseAiAssist bool
6465
}
6566

6667
type LicenseValidation struct {
@@ -83,6 +84,7 @@ func NewFullLicense() LicenseValidation {
8384
TestRun: true,
8485
Sanctions: true,
8586
CaseAutoAssign: true,
87+
CaseAiAssist: true,
8688
},
8789
}
8890
}

models/organization_feature_access.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ type OrganizationFeatureAccess struct {
1616
Sanctions FeatureAccess
1717
NameRecognition FeatureAccess
1818
CaseAutoAssign FeatureAccess
19+
CaseAiAssist FeatureAccess
1920
CreatedAt time.Time
2021
UpdatedAt time.Time
2122

22-
// user-scoped, temporarily at least
23+
// user-scoped
24+
// Currently only used to control display of the AI assist button in the UI - DO NOT use for anything else as it will be removed
2325
AiAssist FeatureAccess
2426
}
2527

@@ -29,6 +31,7 @@ type DbStoredOrganizationFeatureAccess struct {
2931
TestRun FeatureAccess
3032
Sanctions FeatureAccess
3133
CaseAutoAssign FeatureAccess
34+
CaseAiAssist FeatureAccess
3235
CreatedAt time.Time
3336
UpdatedAt time.Time
3437
}
@@ -37,6 +40,8 @@ type UpdateOrganizationFeatureAccessInput struct {
3740
OrganizationId string
3841
TestRun *FeatureAccess
3942
Sanctions *FeatureAccess
43+
CaseAiAssist *FeatureAccess
44+
CaseAutoAssign *FeatureAccess
4045
}
4146

4247
type FeaturesConfiguration struct {
@@ -58,6 +63,7 @@ func (f DbStoredOrganizationFeatureAccess) MergeWithLicenseEntitlement(
5863
Sanctions: f.Sanctions,
5964
NameRecognition: f.Sanctions,
6065
CaseAutoAssign: f.CaseAutoAssign,
66+
CaseAiAssist: f.CaseAiAssist,
6167
CreatedAt: f.CreatedAt,
6268
UpdatedAt: f.UpdatedAt,
6369
}
@@ -90,6 +96,9 @@ func (f DbStoredOrganizationFeatureAccess) MergeWithLicenseEntitlement(
9096
if !l.CaseAutoAssign {
9197
o.CaseAutoAssign = Restricted
9298
}
99+
if !l.CaseAiAssist {
100+
o.CaseAiAssist = Restricted
101+
}
93102

94103
// remove the feature accesses that are not allowed by the configuration
95104
if o.Analytics.IsAllowed() && !c.Analytics {

models/user.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ import "time"
55
type UserId string
66

77
type User struct {
8-
UserId UserId
9-
Email string
10-
Role Role
11-
OrganizationId string
12-
PartnerId *string
13-
FirstName string
14-
LastName string
15-
DeletedAt *time.Time
8+
UserId UserId
9+
Email string
10+
Role Role
11+
OrganizationId string
12+
PartnerId *string
13+
FirstName string
14+
LastName string
15+
DeletedAt *time.Time
16+
17+
// Currently only used to control display of the AI assist button in the UI - DO NOT use for anything else as it will be removed
1618
AiAssistEnabled bool
1719
Picture string
1820
}

repositories/dbmodels/db_license.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type DBLicense struct {
2727
TestRun bool `db:"test_run"`
2828
Sanctions bool `db:"sanctions"`
2929
AutoAssignment bool `db:"auto_assignment"`
30+
CaseAiAssist bool `db:"case_ai_assist"`
3031
}
3132

3233
const TABLE_LICENSES = "licenses"
@@ -53,6 +54,7 @@ func AdaptLicense(db DBLicense) (models.License, error) {
5354
TestRun: db.TestRun,
5455
Sanctions: db.Sanctions,
5556
CaseAutoAssign: db.AutoAssignment,
57+
CaseAiAssist: db.CaseAiAssist,
5658
},
5759
}, nil
5860
}

repositories/license_repository.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func (repo *MarbleDbRepository) CreateLicense(ctx context.Context, exec Executor
7979
"test_run",
8080
"sanctions",
8181
"auto_assignment",
82+
"case_ai_assist",
8283
).
8384
Values(
8485
license.Id,
@@ -96,6 +97,7 @@ func (repo *MarbleDbRepository) CreateLicense(ctx context.Context, exec Executor
9697
license.LicenseEntitlements.TestRun,
9798
license.LicenseEntitlements.Sanctions,
9899
license.LicenseEntitlements.CaseAutoAssign,
100+
license.LicenseEntitlements.CaseAiAssist,
99101
),
100102
)
101103
return err
@@ -136,6 +138,7 @@ func (repo *MarbleDbRepository) UpdateLicense(ctx context.Context, exec Executor
136138
query = query.Set("test_run", licenseEntitlements.TestRun)
137139
query = query.Set("sanctions", licenseEntitlements.Sanctions)
138140
query = query.Set("auto_assignment", licenseEntitlements.CaseAutoAssign)
141+
query = query.Set("case_ai_assist", licenseEntitlements.CaseAiAssist)
139142
}
140143

141144
err := ExecBuilder(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- +goose Up
2+
-- +goose StatementBegin
3+
ALTER TABLE licenses
4+
ADD COLUMN case_ai_assist BOOL NOT NULL DEFAULT FALSE;
5+
6+
ALTER TABLE organization_feature_access
7+
ADD COLUMN case_ai_assist text NOT NULL DEFAULT 'allowed';
8+
9+
UPDATE organization_feature_access
10+
SET
11+
case_ai_assist = 'allowed'
12+
WHERE
13+
org_id IN (
14+
SELECT
15+
id
16+
FROM
17+
organizations
18+
WHERE
19+
ai_case_review_enabled = true
20+
);
21+
22+
-- +goose StatementEnd
23+
-- +goose Down
24+
ALTER TABLE organization_feature_access
25+
DROP COLUMN case_ai_assist;
26+
27+
ALTER TABLE licenses
28+
DROP COLUMN case_ai_assist;
29+
30+
-- +goose StatementBegin
31+
-- +goose StatementEnd

usecases/ai_agent/ai_agent_usecase.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ type caseReviewTaskEnqueuer interface {
137137
) error
138138
}
139139

140+
type featureAccessReader interface {
141+
GetOrganizationFeatureAccess(ctx context.Context, organizationId string, userId *models.UserId) (
142+
models.OrganizationFeatureAccess, error)
143+
}
144+
140145
type AiAgentUsecase struct {
141146
enforceSecurityCase security.EnforceSecurityCase
142147
enforceSecurityOrganization security.EnforceSecurityOrganization
@@ -153,6 +158,7 @@ type AiAgentUsecase struct {
153158
caseReviewFileRepository caseReviewWorkerRepository
154159
blobRepository repositories.BlobRepository
155160
caseReviewTaskEnqueuer caseReviewTaskEnqueuer
161+
featureAccessReader featureAccessReader
156162
config infra.AIAgentConfiguration
157163
caseManagerBucketUrl string
158164

@@ -177,6 +183,7 @@ func NewAiAgentUsecase(
177183
blobRepository repositories.BlobRepository,
178184
caseReviewTaskEnqueuer caseReviewTaskEnqueuer,
179185
transactionFactory executor_factory.TransactionFactory,
186+
featureAccessReader featureAccessReader,
180187
config infra.AIAgentConfiguration,
181188
caseManagerBucketUrl string,
182189
) AiAgentUsecase {
@@ -196,6 +203,7 @@ func NewAiAgentUsecase(
196203
blobRepository: blobRepository,
197204
caseReviewTaskEnqueuer: caseReviewTaskEnqueuer,
198205
transactionFactory: transactionFactory,
206+
featureAccessReader: featureAccessReader,
199207
config: config,
200208
caseManagerBucketUrl: caseManagerBucketUrl,
201209
}

usecases/ai_agent/ai_case_review.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,17 +1051,11 @@ func (uc *AiAgentUsecase) UpdateAiCaseReviewFeedback(
10511051
}
10521052

10531053
func (uc *AiAgentUsecase) HasAiCaseReviewEnabled(ctx context.Context, orgId string) (bool, error) {
1054-
// Add check on license here (is not yet handled in license)
1055-
1056-
// Check if the organization has AI case review enabled, fetch the organization and check the flag
1057-
org, err := uc.repository.GetOrganizationById(ctx, uc.executorFactory.NewExecutor(), orgId)
1054+
featureAccess, err := uc.featureAccessReader.GetOrganizationFeatureAccess(ctx, orgId, nil)
10581055
if err != nil {
10591056
return false, err
10601057
}
1061-
if !org.AiCaseReviewEnabled {
1062-
return false, nil
1063-
}
1064-
return true, nil
1058+
return featureAccess.CaseAiAssist.IsAllowed(), nil
10651059
}
10661060

10671061
var templateFuncMap = template.FuncMap{

0 commit comments

Comments
 (0)