Skip to content

Commit

Permalink
ask user for permission instead of adding it to the manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
Serghei Paduret committed Aug 10, 2021
1 parent 9660ddf commit 10d5e8c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
35 changes: 24 additions & 11 deletions src/app/components/options/options.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {BitbucketService} from '../../services/bitbucket.service';
import {forkJoin, of, Subject, throwError} from 'rxjs';
import {catchError, tap} from 'rxjs/operators';
import {ChangeDetectorRef, Component, OnInit} from '@angular/core';
import {SlackClient} from '../../services/slackClient';
import {SLACK_API_URL, SlackClient} from '../../services/slackClient';
import {BackgroundService} from '../../services/background.service';
import {DisposableComponent} from '../../../core/disposable-component';
import {NotificationService} from '../../services/notification.service';
Expand Down Expand Up @@ -65,16 +65,25 @@ export class OptionsComponent extends DisposableComponent implements OnInit {

onSlackTest() {
let slackClient = new SlackClient(this.slackSettings.token);
slackClient
.postMessage({
'channel': this.slackSettings.memberId,
'text': 'hello'
})
.safeSubscribe(this, (data: any) => {
if (!data.ok) {
this.statusMessage$.next({type: 'error', message: data.error || 'wrong slack credentials'});

chrome.permissions.request(
{origins: [`${SLACK_API_URL}/*`]},
(granted) => {
if (granted) {
slackClient
.postMessage({
'channel': this.slackSettings.memberId,
'text': 'hello'
})
.safeSubscribe(this, (data: any) => {
if (!data.ok) {
this.statusMessage$.next({type: 'error', message: data.error || 'wrong slack credentials'});
} else {
this.statusMessage$.next({message: 'message sent'});
}
});
} else {
this.statusMessage$.next({message: 'message sent'});
this.statusMessage$.next({message: 'permissions not allowed', type: 'error'});
}
});
}
Expand Down Expand Up @@ -141,6 +150,10 @@ export class OptionsComponent extends DisposableComponent implements OnInit {
const bbHost = `${new URL(this.bitbucketSettings.url || '').origin}/*`;
origins.push(bbHost);

if (this.enableSlackNotifications) {
origins.push(`${SLACK_API_URL}/*`);
}

chrome.permissions.request({origins: origins}, (d) => callback(d));
}

Expand All @@ -163,7 +176,7 @@ export class OptionsComponent extends DisposableComponent implements OnInit {
}

onBrowserNotificationTest() {
this.notificationService.sendBrowserNotification('test', 'hello', 'https://www.mozilla.org')
this.notificationService.sendBrowserNotification('test', 'hello', 'https://www.mozilla.org');
}
}

8 changes: 3 additions & 5 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"manifest_version": 2,
"name": "Pull Request Notifications",
"version": "0.1.12",
"description": "Extension to send notifications for bitbucket pull-request events. Tested on bitbucket server.",
"version": "0.1.13",
"description": "Display notifications for Bitbucket pull requests.",
"icons": {
"64": "icon64.png",
"512": "icon512.png"
Expand All @@ -20,10 +20,8 @@
},
"permissions": [
"background",
"clipboardWrite",
"alarms",
"notifications",
"https://slack.com/api/*"
"notifications"
],
"optional_permissions": [
"https://*/*"
Expand Down

0 comments on commit 10d5e8c

Please sign in to comment.