Skip to content

Commit

Permalink
Added google meet integration
Browse files Browse the repository at this point in the history
  • Loading branch information
jitendra-webkul committed Nov 19, 2021
1 parent d07e994 commit 1676e8b
Show file tree
Hide file tree
Showing 22 changed files with 582 additions and 138 deletions.
39 changes: 36 additions & 3 deletions CHANGELOG for v1.x.x.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
## **v1.0.0 (20th of August 2021)** - *First Release*
## **v1.0.0 (19th of November 2021)** - *First Release*

* [feature]Admin user can connect to their google account.
* [feature] Admin user can connect to their google account.

* [feature] User can fetch all events from selected calendars

* [feature] Support two-way synchronization for events

* [feature] Support real time event synchronization
* [feature] Support real time event synchronization

* [feature] Create google meet directly from activity events


* #1 [fixed] - When Admin/User Login to their panel After setup google integration on their project. Then google calendar Icon should be show in sidebar

* #3 [fixed] - When we are trying to connect with the google calendar. then it should not be redirecting to the dashboard.

* #4 [fixed] - There should not be an exception when the user trying to edit activity that is created by google calendar

* #6 [fixed] - Spelling of calendar should not be calender.

* #7 [fixed] - The blank option should not be present there in Calendar dropdown.

* #8 [fixed] - The name of google calendar should not be show wrong in side bar.

* #9 [fixed] - There should be a confirm box before remove google account

* #10 [fixed] - The task should be visible on admin panel

* #11 [fixed] - The Activity should be deleted from the admin panel if we are deleting the same activity from google calendar.

* #12 [fixed] - There should be an option to differentiate activities of google calendar and admin panel

* #13 [fixed] - The participant's name should be visible on the Activity.

* #18 [fixed] - There should not be an exception when the user clicking on Save and Sync button without selecting any canendar.

* #20 [fixed] - The activities should not be repat when the user re-syncing the google calendar.

* #24 [fixed] - The user should not be able to access google calendar if the user has no permission.

* #25 [fixed] - There should not be any warning if the user is trying to delete any activity.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ It packs in lots of demanding features that allows your business to scale in no
* User can fetch all events from selected calendars
* Support two-way synchronization for events
* Support real time event synchronization
* User can create google meet link directly from activity form


### 2. Requirements:

* **Krayin**: v1.0.1 or higher.
* **Krayin**: v1.2.2 or higher.


### 3. Installation:
Expand Down
2 changes: 1 addition & 1 deletion publishable/assets/css/admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added publishable/assets/images/google-meet-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions publishable/assets/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"/css/admin.css": "/css/admin.css?id=3c9d81644bdce8af07d0",
"/css/admin.css": "/css/admin.css?id=62d249c405dee7b0cda1",
"/images/google-active-icon.svg": "/images/google-active-icon.svg?id=3ad25e75f220357c2c90",
"/images/google-calendar-icon.png": "/images/google-calendar-icon.png?id=f87f54e121dfb7cf8b39",
"/images/google-icon.svg": "/images/google-icon.svg?id=1aca2f0da9adb1442c53"
"/images/google-icon.svg": "/images/google-icon.svg?id=1aca2f0da9adb1442c53",
"/images/google-meet-icon.png": "/images/google-meet-icon.png?id=b2daf7c604b448ab620e"
}
8 changes: 4 additions & 4 deletions src/Config/menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

return [
[
'key' => 'google',
'name' => 'google::app.google',
'route' => 'admin.google.index',
'sort' => 2,
'key' => 'google',
'name' => 'google::app.google',
'route' => 'admin.google.index',
'sort' => 2,
'icon-class' => 'google-icon',
]
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddScopesColumnInGoogleAccountsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('google_accounts', function (Blueprint $table) {
$table->json('scopes')->nullable();
});

DB::table('google_accounts')
->update([
'google_accounts.scopes' => ['calendar'],
]);
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('google_accounts', function (Blueprint $table) {
$table->dropColumn('scopes');
});
}
}
97 changes: 51 additions & 46 deletions src/Http/Controllers/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ public function __construct(
*/
public function index()
{
if (! request('route')) {
return redirect()->route('admin.google.index', ['route' => 'calendar']);
}

$account = $this->accountRepository->findOneByField('user_id', auth()->user()->id);

return view('google::calendar.index', compact('account'));
return view('google::' . request('route') . '.index', compact('account'));
}

/**
Expand All @@ -82,54 +86,43 @@ public function index()
*/
public function store()
{
if (! request()->has('code')) {
return redirect($this->google->createAuthUrl());
}

$this->google->authenticate(request()->get('code'));

$account = $this->google->service('Oauth2')->userinfo->get();

$this->userRepository->find(auth()->user()->id)->accounts()->updateOrCreate(
[
'google_id' => $account->id,
],
[
'name' => $account->email,
'token' => $this->google->getAccessToken(),
]
);

return redirect()->route('admin.google.index');
}

/**
* Synchronize
*
* @param integer $id
* @return \Illuminate\Http\Response
*/
public function sync($id)
{
$account = $this->accountRepository->findOrFail($id);

$primaryCalendar = null;
$account = $this->accountRepository->findOneByField('user_id', auth()->user()->id);

foreach ($account->calendars as $calendar) {
if ($calendar->id == request('calendar_id')) {
$calendar->update(['is_primary' => 1]);
if ($account) {
$this->accountRepository->update([
'scopes' => array_merge($account->scopes ?? [], [request('route')]),
], $account->id);

$primaryCalendar = $calendar;
} else {
$calendar->update(['is_primary' => 0]);
if (request('route') == 'calendar') {
$account->synchronization->ping();
$account->synchronization->startListeningForChanges();
}
}

$primaryCalendar->synchronization->ping();
session()->put('route', request('route'));
} else {
if (! request()->has('code')) {
session()->put('route', request('route'));

session()->flash('success', trans('google::app.sync-success'));
return redirect($this->google->createAuthUrl());
}

return redirect()->back();
$this->google->authenticate(request()->get('code'));

$account = $this->google->service('Oauth2')->userinfo->get();

$this->userRepository->find(auth()->user()->id)->accounts()->updateOrCreate(
[
'google_id' => $account->id,
],
[
'name' => $account->email,
'token' => $this->google->getAccessToken(),
'scopes' => [session()->get('route', 'calendar')],
]
);
}

return redirect()->route('admin.google.index', ['route' => session()->get('route', 'calendar')]);
}

/**
Expand All @@ -142,11 +135,23 @@ public function destroy($id)
{
$account = $this->accountRepository->findOrFail($id);

$account->calendars->each->delete();
if (count($account->scopes) > 1) {
$scopes = $account->scopes;

if (($key = array_search(request('route'), $scopes)) !== false) {
unset($scopes[$key]);
}

$this->accountRepository->destroy($id);
$this->accountRepository->update([
'scopes' => array_values($scopes),
], $account->id);
} else {
$account->calendars->each->delete();

$this->google->revokeToken($account->token);
$this->accountRepository->destroy($id);

$this->google->revokeToken($account->token);
}

session()->flash('success', trans('google::app.destroy-success'));

Expand Down
56 changes: 56 additions & 0 deletions src/Http/Controllers/CalendarController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Webkul\Google\Http\Controllers;

use Webkul\Google\Repositories\AccountRepository;

class CalendarController extends Controller
{
/**
* AccountRepository object
*
* @var \Webkul\Repositories\Services\AccountRepository
*/
protected $accountRepository;

/**
* Create a new controller instance.
*
* @param \Webkul\Google\Repositories\AccountRepository $accountRepository
*
* @return void
*/
public function __construct(AccountRepository $accountRepository)
{
$this->accountRepository = $accountRepository;
}

/**
* Synchronize
*
* @param integer $id
* @return \Illuminate\Http\Response
*/
public function sync($id)
{
$account = $this->accountRepository->findOrFail($id);

$primaryCalendar = null;

foreach ($account->calendars as $calendar) {
if ($calendar->id == request('calendar_id')) {
$calendar->update(['is_primary' => 1]);

$primaryCalendar = $calendar;
} else {
$calendar->update(['is_primary' => 0]);
}
}

$primaryCalendar->synchronization->ping();

session()->flash('success', trans('google::app.sync-success'));

return redirect()->back();
}
}
85 changes: 85 additions & 0 deletions src/Http/Controllers/MeetController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Webkul\Google\Http\Controllers;

use Carbon\Carbon;
use Webkul\Google\Repositories\AccountRepository;

class MeetController extends Controller
{
/**
* AccountRepository object
*
* @var \Webkul\Repositories\Services\AccountRepository
*/
protected $accountRepository;

/**
* Create a new controller instance.
*
* @param \Webkul\Google\Repositories\AccountRepository $accountRepository
*
* @return void
*/
public function __construct(AccountRepository $accountRepository)
{
$this->accountRepository = $accountRepository;
}

/**
* Create google meet link
*
* @return \Illuminate\Http\Response
*/
public function createLink()
{
$account = $this->accountRepository->first();

$service = $account->getGoogleService('Calendar');

$start = request('schedule_from')
? Carbon::createFromFormat('Y-m-d H:i:s', request('schedule_from'))
: Carbon::now();

$end = request('schedule_ro')
? Carbon::createFromFormat('Y-m-d H:i:s', request('schedule_ro'))
: Carbon::now()->addMinutes(30);

$googleEvent = $service->events->insert(
'primary',

new \Google_Service_Calendar_Event([
'summary' => 'Google Meet Link',

'start' => [
'dateTime' => $start->toAtomString(),
'timeZone' => $start->timezone->getName(),
],

'end' => [
'dateTime' => $end->toAtomString(),
'timeZone' => $end->timezone->getName(),
],

'conferenceData' => [
'createRequest' => [
'conferenceSolutionKey' => [
'type' => 'hangoutsMeet',
],

'requestId' => 'meet_' . time(),
],
],
]),

['conferenceDataVersion' => 1]
);

$service->events->delete('primary', $googleEvent->id);

return response()->json([
'link' => $googleEvent->hangoutLink,
'comment' => '──────────<br/><br/>You are invited to join Google Meet meeting.<br/><br/>Join the Google Meet meeting: <a href="' . $googleEvent->hangoutLink . '" target="_blank">' . $googleEvent->hangoutLink . '</a><br/><br/>──────────'
]);
}
}
Loading

0 comments on commit 1676e8b

Please sign in to comment.