Skip to content

Commit

Permalink
fixed rate limit not deleting for projects and endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mekilis committed Feb 21, 2025
1 parent d4db4e9 commit 8f38c73
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 27 deletions.
2 changes: 1 addition & 1 deletion api/models/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type RateLimitConfiguration struct {

func (rc *RateLimitConfiguration) Transform() *datastore.RateLimitConfiguration {
if rc == nil {
return nil
return &datastore.RateLimitConfiguration{}
}

return &datastore.RateLimitConfiguration{Count: rc.Count, Duration: rc.Duration}
Expand Down
4 changes: 2 additions & 2 deletions services/update_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func (a *UpdateEndpointService) updateEndpoint(endpoint *datastore.Endpoint, e m
endpoint.SlackWebhookURL = *e.SlackWebhookURL
}

if e.RateLimit != 0 {
if e.RateLimit >= 0 {
endpoint.RateLimit = e.RateLimit
}

if e.RateLimitDuration != 0 {
if e.RateLimitDuration >= 0 {
endpoint.RateLimitDuration = e.RateLimitDuration
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
position="top-right"
></convoy-tooltip>
</label>
<button convoy-permission="Endpoints|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('owner_id')">
<button convoy-permission="Endpoints|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('owner_id', true)">
<svg width="14" height="14" class="fill-transparent stroke-new.gray-400">
<use xlink:href="#delete-icon2"></use>
</svg>
Expand All @@ -53,7 +53,7 @@
<div class="border-l-2 border-new.primary-25 pl-16px mb-40px">
<div class="flex justify-between items-center mb-16px">
<p class="text-12 text-neutral-11 font-medium flex items-center">Rate Limit</p>
<button convoy-permission="Endpoints|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('rate_limit')">
<button convoy-permission="Endpoints|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('rate_limit', true)">
<svg width="14" height="14" class="fill-transparent stroke-neutral-10">
<use xlink:href="#delete-icon2"></use>
</svg>
Expand Down Expand Up @@ -90,7 +90,7 @@
Business
</div>
</div>
<button convoy-permission="Endpoints|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('alert_config')">
<button convoy-permission="Endpoints|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('alert_config', true)">
<svg width="14" height="14" class="fill-transparent stroke-neutral-10">
<use xlink:href="#delete-icon2"></use>
</svg>
Expand Down Expand Up @@ -120,7 +120,7 @@
Endpoint Authentication
<convoy-tooltip size="sm" position="top-right" class="ml-4px">You can set your provided endpoint authentication is any is required</convoy-tooltip>
</p>
<button convoy-permission="Endpoints|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('auth')">
<button convoy-permission="Endpoints|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('auth', true)">
<svg width="14" height="14" class="fill-transparent stroke-neutral-10">
<use xlink:href="#delete-icon2"></use>
</svg>
Expand Down Expand Up @@ -152,7 +152,7 @@
Signature Format
<convoy-tooltip size="sm" position="top-right" class="ml-4px">This specifies your signature format for your project.</convoy-tooltip>
</p>
<button convoy-permission="Endpoints|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('signature')">
<button convoy-permission="Endpoints|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('signature', true)">
<svg width="14" height="14" class="fill-transparent stroke-neutral-10">
<use xlink:href="#delete-icon2"></use>
</svg>
Expand Down Expand Up @@ -180,7 +180,7 @@
Business
</div>
</div>
<button convoy-permission="Endpoints|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('http_timeout')">
<button convoy-permission="Endpoints|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('http_timeout', true)">
<svg width="14" height="14" class="fill-transparent stroke-neutral-10">
<use xlink:href="#delete-icon2"></use>
</svg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class CreateEndpointComponent implements OnInit {
token: string = this.route.snapshot.params.token;
@Input('endpointId') endpointUid = this.route.snapshot.params.id;
enableMoreConfig = false;
configurations = [{ uid: 'http_timeout', name: 'Timeout ', show: false }];
configurations = [{ uid: 'http_timeout', name: 'Timeout ', show: false, deleted: false }];
endpointCreated: boolean = false;
endpointSecret?: SECRET;
currentRoute = window.location.pathname.split('/').reverse()[0];
Expand All @@ -98,11 +98,11 @@ export class CreateEndpointComponent implements OnInit {
async ngOnInit() {
if (this.type !== 'portal')
this.configurations.push(
{ uid: 'owner_id', name: 'Owner ID ', show: false },
{ uid: 'rate_limit', name: 'Rate Limit ', show: false },
{ uid: 'auth', name: 'Auth', show: false },
{ uid: 'alert_config', name: 'Notifications', show: false },
{ uid: 'signature', name: 'Signature Format', show: false }
{ uid: 'owner_id', name: 'Owner ID ', show: false, deleted: false },
{ uid: 'rate_limit', name: 'Rate Limit ', show: false, deleted: false },
{ uid: 'auth', name: 'Auth', show: false, deleted: false },
{ uid: 'alert_config', name: 'Notifications', show: false, deleted: false },
{ uid: 'signature', name: 'Signature Format', show: false, deleted: false },
);

if (!this.endpointUid) this.endpointUid = this.route.snapshot.params.id;
Expand Down Expand Up @@ -143,6 +143,18 @@ export class CreateEndpointComponent implements OnInit {
return this.addNewEndpointForm.markAllAsTouched();
}


let rateLimitDeleted = !this.showConfig('rate_limit') && this.configDeleted('rate_limit');
if (rateLimitDeleted) {
const configKeys = ['rate_limit', 'rate_limit_duration'];
configKeys.forEach((key) => {
this.addNewEndpointForm.value[key] = 0; // element type = number
this.addNewEndpointForm.get(`${key}`)?.patchValue(0);
});
this.setConfigFormDeleted('rate_limit', false);
}


this.savingEndpoint = true;
const endpointValue = structuredClone(this.addNewEndpointForm.value);

Expand Down Expand Up @@ -215,16 +227,31 @@ export class CreateEndpointComponent implements OnInit {
return totalSeconds;
}

toggleConfigForm(configValue: string) {
toggleConfigForm(configValue: string, deleted?: boolean) {
this.configurations.forEach(config => {
if (config.uid === configValue) config.show = !config.show;
if (config.uid === configValue) {
config.show = !config.show;
config.deleted = deleted ?? false;
}
});
}

setConfigFormDeleted(configValue: string, deleted: boolean) {
this.configurations.forEach(config => {
if (config.uid === configValue) {
config.deleted = deleted;
}
});
}

showConfig(configValue: string): boolean {
return this.configurations.find(config => config.uid === configValue)?.show || false;
}

configDeleted(configValue: string): boolean {
return this.configurations.find(config => config.uid === configValue)?.deleted || false;
}

get shouldShowBorder(): number {
return this.configurations.filter(config => config.show).length;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ <h3 class="mt-24px mb-16px font-medium text-14">Project type</h3>
Signature Details
<convoy-tooltip size="sm" position="top-right" class="ml-4px">This specifies your header and hash function for your project</convoy-tooltip>
</p>
<button convoy-permission="Project Settings|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('signature')">
<button convoy-permission="Project Settings|MANAGE" convoy-button type="button" size="xs" fill="soft-outline" color="neutral" (click)="toggleConfigForm('signature', true)">
<svg width="14" height="14" class="fill-transparent stroke-neutral-10">
<use xlink:href="#delete-icon2"></use>
</svg>
Expand Down Expand Up @@ -84,7 +84,7 @@ <h3 class="mt-24px mb-16px font-medium text-14">Project type</h3>
retry attempt.
</convoy-tooltip>
</p>
<button convoy-button type="button" size="xs" fill="soft-outline" color="neutral" convoy-permission="Project Settings|MANAGE" (click)="toggleConfigForm('strategy')">
<button convoy-button type="button" size="xs" fill="soft-outline" color="neutral" convoy-permission="Project Settings|MANAGE" (click)="toggleConfigForm('strategy', true)">
<svg width="14" height="14" class="fill-transparent stroke-neutral-10">
<use xlink:href="#delete-icon2"></use>
</svg>
Expand Down Expand Up @@ -122,7 +122,7 @@ <h3 class="mt-24px mb-16px font-medium text-14">Project type</h3>
Rate Limit Parameters
<convoy-tooltip size="sm" position="top-right" class="ml-4px">These are the specifications for how many events are to be sent to an endpoint per time</convoy-tooltip>
</p>
<button convoy-button type="button" size="xs" fill="soft-outline" color="neutral" convoy-permission="Project Settings|MANAGE" (click)="toggleConfigForm('ratelimit')">
<button convoy-button type="button" size="xs" fill="soft-outline" color="neutral" convoy-permission="Project Settings|MANAGE" (click)="toggleConfigForm('ratelimit', true)">
<svg width="14" height="14" class="fill-transparent stroke-neutral-10">
<use xlink:href="#delete-icon2"></use>
</svg>
Expand Down Expand Up @@ -160,7 +160,7 @@ <h3 class="mt-24px mb-16px font-medium text-14">Project type</h3>
Business
</div>
</div>
<button convoy-button type="button" size="xs" fill="soft-outline" color="neutral" convoy-permission="Project Settings|MANAGE" (click)="toggleConfigForm('search_policy')">
<button convoy-button type="button" size="xs" fill="soft-outline" color="neutral" convoy-permission="Project Settings|MANAGE" (click)="toggleConfigForm('search_policy', true)">
<svg width="14" height="14" class="fill-transparent stroke-neutral-10">
<use xlink:href="#delete-icon2"></use>
</svg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ export class CreateProjectComponent implements OnInit {
projectDetails!: PROJECT;
signatureVersions!: { date: string; content: VERSIONS[] }[];
configurations = [
{ uid: 'strategy', name: 'Retry Config', show: false },
{ uid: 'ratelimit', name: 'Rate Limit', show: false },
{ uid: 'search_policy', name: 'Search Policy', show: false },
{ uid: 'signature', name: 'Signature Format', show: false }
{ uid: 'strategy', name: 'Retry Config', show: false, deleted: false },
{ uid: 'ratelimit', name: 'Rate Limit', show: false, deleted: false },
{ uid: 'search_policy', name: 'Search Policy', show: false, deleted: false },
{ uid: 'signature', name: 'Signature Format', show: false, deleted: false },
];
public rbacService = inject(RbacService);
tabs: TAB[] = [
Expand All @@ -106,6 +106,7 @@ export class CreateProjectComponent implements OnInit {
events = ['endpoint.created', 'endpoint.deleted', 'endpoint.updated', 'eventdelivery.success', 'eventdelivery.failed', 'project.updated'];
eventTypes: EVENT_TYPE[] = [];
selectedEventType!: EVENT_TYPE;
rateLimitDeleted = false;

constructor(
private formBuilder: FormBuilder,
Expand Down Expand Up @@ -143,16 +144,30 @@ export class CreateProjectComponent implements OnInit {
this.versions.push(this.newVersion());
}

toggleConfigForm(configValue: string) {
toggleConfigForm(configValue: string, deleted?: boolean) {
this.configurations.forEach(config => {
if (config.uid === configValue) config.show = !config.show;
if (config.uid === configValue) {
config.show = !config.show;
config.deleted = deleted ?? false;
}
});
}
setConfigFormDeleted(configValue: string, deleted: boolean) {
this.configurations.forEach(config => {
if (config.uid === configValue) {
config.deleted = deleted;
}
});
}

showConfig(configValue: string): boolean {
return this.configurations.find(config => config.uid === configValue)?.show || false;
}

configDeleted(configValue: string): boolean {
return this.configurations.find(config => config.uid === configValue)?.deleted || false;
}

async getProjectDetails() {
try {
this.projectDetails = this.privateService.getProjectDetails;
Expand Down Expand Up @@ -235,6 +250,17 @@ export class CreateProjectComponent implements OnInit {
if (typeof this.projectForm.value.config.ratelimit.count === 'string') this.projectForm.value.config.ratelimit.count = parseInt(this.projectForm.value.config.ratelimit.count);
if (typeof this.projectForm.value.config.search_policy === 'number') this.projectForm.value.config.search_policy = `${this.projectForm.value.config.search_policy}h`;


if (!this.showConfig('ratelimit') && this.configDeleted('ratelimit')) {
this.projectForm.value.config.ratelimit.count = 0;
this.projectForm.value.config.ratelimit.duration = 0;
this.projectForm.value.config.ratelimit = null;

this.projectForm.get('config.ratelimit')?.patchValue({ count: 0, duration: 0 });

this.setConfigFormDeleted('ratelimit', false);
}

this.isCreatingProject = true;

try {
Expand Down

0 comments on commit 8f38c73

Please sign in to comment.