Skip to content

Commit 8815fab

Browse files
author
Simon Emms
committed
[licensor]: add seats param to the enabled method
1 parent 17ad797 commit 8815fab

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

components/licensor/ee/pkg/licensor/licensor.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func (e *Evaluator) Validate() (msg string, valid bool) {
156156
}
157157

158158
// Enabled determines if a feature is enabled by the license
159-
func (e *Evaluator) Enabled(feature Feature) bool {
159+
func (e *Evaluator) Enabled(feature Feature, seats int) bool {
160160
if e.invalid != "" {
161161
return false
162162
}
@@ -167,11 +167,8 @@ func (e *Evaluator) Enabled(feature Feature) bool {
167167

168168
// HasEnoughSeats returns true if the license supports at least the give amount of seats
169169
func (e *Evaluator) HasEnoughSeats(seats int) bool {
170-
if e.invalid != "" {
171-
return false
172-
}
173-
174-
return e.lic.Seats == 0 || seats <= e.lic.Seats
170+
// Always return true - Enabled decides if we're on community or free/professional license
171+
return true
175172
}
176173

177174
// Inspect returns the license information this evaluator holds.

components/licensor/typescript/ee/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ func Validate(id int) (msg *C.char, valid bool) {
4949

5050
// Enabled returns true if a license enables a feature
5151
//export Enabled
52-
func Enabled(id int, feature *C.char) (enabled, ok bool) {
52+
func Enabled(id int, feature *C.char, seats int) (enabled, ok bool) {
5353
e, ok := instances[id]
5454
if !ok {
5555
return
5656
}
5757

58-
return e.Enabled(licensor.Feature(C.GoString(feature))), true
58+
return e.Enabled(licensor.Feature(C.GoString(feature)), seats), true
5959
}
6060

6161
// HasEnoughSeats returns true if the license supports at least the given number of seats.

components/licensor/typescript/ee/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ export class LicenseEvaluator {
4949
return { msg: v.msg, valid: false };
5050
}
5151

52-
public isEnabled(feature: Feature): boolean {
53-
return isEnabled(this.instanceID, feature);
52+
public isEnabled(feature: Feature, seats: number): boolean {
53+
return isEnabled(this.instanceID, feature, seats);
5454
}
5555

5656
public hasEnoughSeats(seats: number): boolean {

components/licensor/typescript/ee/src/module.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void EnabledM(const FunctionCallbackInfo<Value> &args) {
9595
Isolate *isolate = args.GetIsolate();
9696
Local<Context> context = isolate->GetCurrentContext();
9797

98-
if (args.Length() < 2) {
98+
if (args.Length() < 3) {
9999
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "wrong number of arguments").ToLocalChecked()));
100100
return;
101101
}
@@ -108,6 +108,10 @@ void EnabledM(const FunctionCallbackInfo<Value> &args) {
108108
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "argument 1 must be a string").ToLocalChecked()));
109109
return;
110110
}
111+
if (!args[2]->IsNumber() || args[2]->IsUndefined()) {
112+
isolate->ThrowException(Exception::TypeError(String::NewFromUtf8(isolate, "argument 2 must be a number").ToLocalChecked()));
113+
return;
114+
}
111115

112116
double rid = args[0]->NumberValue(context).FromMaybe(0);
113117
int id = static_cast<int>(rid);
@@ -116,8 +120,15 @@ void EnabledM(const FunctionCallbackInfo<Value> &args) {
116120
const char* cstr = ToCString(str);
117121
char* featurestr = const_cast<char *>(cstr);
118122

123+
double rseats = args[2]->NumberValue(context).FromMaybe(-1);
124+
int seats = static_cast<int>(rseats);
125+
if (seats < 0) {
126+
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "cannot convert number of seats").ToLocalChecked()));
127+
return;
128+
}
129+
119130
// Call exported Go function, which returns a C string
120-
Enabled_return r = Enabled(id, featurestr);
131+
Enabled_return r = Enabled(id, featurestr, seats);
121132

122133
if (!r.r1) {
123134
isolate->ThrowException(Exception::Error(String::NewFromUtf8(isolate, "invalid instance ID").ToLocalChecked()));

components/licensor/typescript/ee/src/nativemodule.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type Instance = number;
99

1010
export function init(key: string, domain: string): Instance;
1111
export function validate(id: Instance): { msg: string, valid: boolean };
12-
export function isEnabled(id: Instance, feature: Feature): boolean;
12+
export function isEnabled(id: Instance, feature: Feature, seats: int): boolean;
1313
export function hasEnoughSeats(id: Instance, seats: int): boolean;
1414
export function inspect(id: Instance): string;
1515
export function dispose(id: Instance);

0 commit comments

Comments
 (0)