Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: savannabits/saas
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.0.4
Choose a base ref
...
head repository: savannabits/saas
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Oct 19, 2023

  1. Update CHANGELOG

    coolsam726 authored and github-actions[bot] committed Oct 19, 2023
    Copy the full SHA
    ebbec70 View commit details
  2. Copy the full SHA
    4be5aa9 View commit details
  3. Copy the full SHA
    d8d8de0 View commit details
  4. Merge pull request #5 from savannabits/development

    Default Team Adjustment
    coolsam726 authored Oct 19, 2023
    Copy the full SHA
    70431ee View commit details
  5. Update CHANGELOG

    coolsam726 authored and github-actions[bot] committed Oct 19, 2023
    Copy the full SHA
    ee5088e View commit details

Commits on Oct 21, 2023

  1. Copy the full SHA
    42846f5 View commit details
  2. Merge pull request #6 from savannabits/development

    Improved the endpoints for fetching Staff by username, user Number an…
    coolsam726 authored Oct 21, 2023
    Copy the full SHA
    2b81699 View commit details
  3. Update CHANGELOG

    coolsam726 authored and github-actions[bot] committed Oct 21, 2023
    Copy the full SHA
    abb2676 View commit details
  4. Copy the full SHA
    628681a View commit details
  5. Merge pull request #7 from savannabits/development

    Added the getStaffByUsername form input in webservice settings
    coolsam726 authored Oct 21, 2023
    Copy the full SHA
    8701160 View commit details
  6. Update CHANGELOG

    coolsam726 authored and github-actions[bot] committed Oct 21, 2023
    Copy the full SHA
    c86a06c View commit details

Commits on Oct 22, 2023

  1. Copy the full SHA
    61983bd View commit details
  2. Merge pull request #8 from savannabits/development

    Bug Fix in HasTeam: referencing auth()->user()->team was causing null…
    coolsam726 authored Oct 22, 2023
    Copy the full SHA
    24fd387 View commit details
  3. Update CHANGELOG

    coolsam726 authored and github-actions[bot] committed Oct 22, 2023
    Copy the full SHA
    bd05355 View commit details

Commits on Oct 23, 2023

  1. Copy the full SHA
    c09f2ec View commit details
  2. Merge pull request #9 from savannabits/development

    Enhancement: Sync GUID for a user before sync
    coolsam726 authored Oct 23, 2023
    Copy the full SHA
    36f6ea2 View commit details
  3. Update CHANGELOG

    coolsam726 authored and github-actions[bot] committed Oct 23, 2023
    Copy the full SHA
    ddac0a8 View commit details

Commits on Oct 24, 2023

  1. Copy the full SHA
    5b407c9 View commit details
  2. Merge pull request #10 from savannabits/development

    New Feature: Loop in Substitution until all keys are substituted.
    coolsam726 authored Oct 24, 2023
    Copy the full SHA
    0a43d63 View commit details
  3. Copy the full SHA
    e1cc149 View commit details
  4. Merge pull request #11 from savannabits/development

    Do 3 Round substitution to avoid infinite loops
    coolsam726 authored Oct 24, 2023
    Copy the full SHA
    a9d0d1d View commit details
  5. Update CHANGELOG

    coolsam726 authored and github-actions[bot] committed Oct 24, 2023
    Copy the full SHA
    9c0d915 View commit details

Commits on Nov 27, 2023

  1. Remove Fallback Login

    coolsam726 committed Nov 27, 2023
    Copy the full SHA
    7903053 View commit details
  2. Merge pull request #12 from savannabits/development

    Remove Fallback Login
    coolsam726 authored Nov 27, 2023
    Copy the full SHA
    acff3ac View commit details
  3. Update CHANGELOG

    coolsam726 authored and github-actions[bot] committed Nov 27, 2023
    Copy the full SHA
    07ea349 View commit details

Commits on Jan 12, 2024

  1. Update composer.json

    Add support for spatie/laravel-permission v6
    coolsam726 authored Jan 12, 2024
    Copy the full SHA
    86d6714 View commit details
  2. Update CHANGELOG

    coolsam726 authored and github-actions[bot] committed Jan 12, 2024
    Copy the full SHA
    5625cfb View commit details
72 changes: 71 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,76 @@

All notable changes to `saas` will be documented in this file.

## v1.2.0 - 2024-01-12

Support for Laravel Permission v6
**Full Changelog**: https://github.com/savannabits/saas/compare/v1.1.5...v1.2.0

## v1.1.5 - 2023-11-27

### What's Changed

* Remove Fallback Login by @coolsam726 in https://github.com/savannabits/saas/pull/12

**Full Changelog**: https://github.com/savannabits/saas/compare/v1.1.4...v1.1.5

## v1.1.4 - 2023-10-24

### What's Changed

- New Feature: Loop in Substitution until all keys are substituted. by @coolsam726 in https://github.com/savannabits/saas/pull/10
- Do 3 Round substitution to avoid infinite loops by @coolsam726 in https://github.com/savannabits/saas/pull/11

**Full Changelog**: https://github.com/savannabits/saas/compare/v1.1.3...v1.1.4

## v1.1.3 - 2023-10-23

### What's Changed

- Enhancement: Sync GUID for a user before sync by @coolsam726 in https://github.com/savannabits/saas/pull/9

**Full Changelog**: https://github.com/savannabits/saas/compare/v1.1.2...v1.1.3

## v1.1.2 - 2023-10-22

### What's Changed

- Bug Fix in HasTeam: referencing auth()->user()->team was causing null… by @coolsam726 in https://github.com/savannabits/saas/pull/8

**Full Changelog**: https://github.com/savannabits/saas/compare/v1.1.1...v1.1.2

## v1.1.1 - 2023-10-21

### What's Changed

- Added the getStaffByUsername form input in webservice settings by @coolsam726 in https://github.com/savannabits/saas/pull/7

**Full Changelog**: https://github.com/savannabits/saas/compare/v1.1.0...v1.1.1

## v1.1.0 - 2023-10-21

### What's Changed

- Improved the endpoints for fetching Staff by username, user Number an… by @coolsam726 in https://github.com/savannabits/saas/pull/6

**Full Changelog**: https://github.com/savannabits/saas/compare/v1.0.5...v1.1.0

## v1.0.5 - 2023-10-19

### What's Changed

- Default Team Adjustment by @coolsam726 in https://github.com/savannabits/saas/pull/5

**Full Changelog**: https://github.com/savannabits/saas/compare/v1.0.4...v1.0.5

## v1.0.4 - 2023-10-19

### What's Changed

- Minor bug fix: getByCode was strictly typed to string for the $code p… by @coolsam726 in https://github.com/savannabits/saas/pull/4

**Full Changelog**: https://github.com/savannabits/saas/compare/v1.0.3...v1.0.4

## v1.0.3 - 2023-10-19

### What's Changed
@@ -18,7 +88,7 @@ All notable changes to `saas` will be documented in this file.

### What's Changed

- Removed the Department Resource Registration so that it can be overriden
- Removed the Department Resource Registration so that it can be overriden
**Full Changelog**: https://github.com/savannabits/saas/compare/v1.0.1...v1.0.2

## v1.0.1 - 2023-10-13
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@
"psr/simple-cache": "^2.0",
"pxlrbt/filament-excel": "^2.1",
"spatie/laravel-package-tools": "^1.15.0",
"spatie/laravel-permission": "^5.10.2",
"spatie/laravel-permission": "^5.10.2|^6.0",
"spatie/laravel-settings": "^3.2.0"
},
"require-dev": {
4 changes: 3 additions & 1 deletion database/migrations/add_webservice_settings.php.stub
Original file line number Diff line number Diff line change
@@ -14,7 +14,8 @@ return new class extends \Spatie\LaravelSettings\Migrations\SettingsMigration
public function up()
{
$this->migrator->add('webservice.base_url','https://juba.strathmore.edu/dataservice');
$this->migrator->add('webservice.staff_endpoint','staff/getStaffByUsername/{username}');
$this->migrator->add('webservice.staff_endpoint','staff/getStaff/{staff_number}');
$this->migrator->add('webservice.staff_by_username_endpoint','staff/getStaffByUsername/{username}');
$this->migrator->add('webservice.student_endpoint','student/getStudent/{studentNumber}');
$this->migrator->add('webservice.all_staff_endpoint','staff/getAllStaff');
$this->migrator->add('webservice.all_current_students_endpoint','student/getAllCurrentStudents');
@@ -31,6 +32,7 @@ return new class extends \Spatie\LaravelSettings\Migrations\SettingsMigration
{
$this->migrator->deleteIfExists('webservice.base_url');
$this->migrator->deleteIfExists('webservice.staff_endpoint');
$this->migrator->deleteIfExists('webservice.staff_by_username_endpoint');
$this->migrator->deleteIfExists('webservice.student_endpoint');
$this->migrator->deleteIfExists('webservice.all_staff_endpoint');
$this->migrator->deleteIfExists('webservice.all_current_students_endpoint');
11 changes: 9 additions & 2 deletions src/Concerns/Model/HasTeam.php
Original file line number Diff line number Diff line change
@@ -38,8 +38,15 @@ public static function bootHasTeam()
return;
}
if (Schema::hasColumn($query->getModel()->getTable(),'team_id')) {
$query->whereBelongsTo(auth()->user()->team)->orWhereNull('team_id')
->orWhere('team_id','=', default_team()?->id);
$user = auth()->user();
if ($user) {
$query->whereBelongsTo($user->team)
->orWhereNull('team_id')
->orWhere('team_id','=', default_team()?->id);
} else {
$query->whereNull('team_id')
->orWhere('team_id','=', default_team()?->id);
}
}
// $query->where('team_id', auth()->user()->team_id);
// or with a `team` relationship defined:
4 changes: 2 additions & 2 deletions src/Filament/Pages/Login.php
Original file line number Diff line number Diff line change
@@ -122,10 +122,10 @@ protected function getCredentialsFromFormData(array $data): array
return [
'samaccountname' => $data['username'],
'password' => $data['password'],
'fallback' => [
/*'fallback' => [
'username' => $data['username'],
'password' => $data['password']
]
]*/
];
}
protected function throwLoginValidationException(string $message): void
1 change: 1 addition & 0 deletions src/Filament/Pages/ManageWebserviceSettings.php
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ public function form(Form $form): Form
Forms\Components\Section::make([
Forms\Components\TextInput::make('base_url')->required()->columnSpanFull(),
Forms\Components\Fieldset::make('Webservice Endpoints')->schema([
Forms\Components\TextInput::make('staff_by_username_endpoint')->helperText('insert parameters as {param1}/{param2} where necessary'),
Forms\Components\TextInput::make('staff_endpoint')->helperText('insert parameters as {param1}/{param2} where necessary'),
Forms\Components\TextInput::make('student_endpoint')->helperText('insert parameters as {param1}/{param2} where necessary'),
Forms\Components\TextInput::make('all_staff_endpoint')->helperText('insert parameters as {param1}/{param2} where necessary'),
13 changes: 12 additions & 1 deletion src/Helpers/Framework.php
Original file line number Diff line number Diff line change
@@ -75,7 +75,18 @@ public function substitute(string $expression, array $substitutions = [], string
$keys = collect($substitutions)->keys()->map(fn ($key) => "{$substitutionIdentifier}{$key}");
$values = collect($substitutions)->values();

return Str::of($expression)->replace($keys->toArray(), $values->toArray())->toString();
$replacement = Str::of($expression)->replace($keys->toArray(), $values->toArray())->toString();
// ROUND 2
if (Str::of($replacement)->contains($keys)) {
$replacement = Str::of($replacement)->replace($keys->toArray(), $values->toArray())->toString();
}

// ROUND 3
if (Str::of($replacement)->contains($keys)) {
$replacement = Str::of($replacement)->replace($keys->toArray(), $values->toArray())->toString();
}

return $replacement;
}

public function getByCode(Model | string $model, string|array $code)
22 changes: 21 additions & 1 deletion src/Services/Users.php
Original file line number Diff line number Diff line change
@@ -7,6 +7,8 @@
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Str;
use LdapRecord\Laravel\Commands\ImportLdapUsers;
use Savannabits\Saas\Ldap\Staff;
use Savannabits\Saas\Ldap\Student;

class Users
{
@@ -21,6 +23,25 @@ public static function make(): static
*/
public function syncUser(string $username, string $provider, ?bool $skipLdapImport = false)
{
$user = \App\Models\User::whereUsername($username)->first();

if ($user) {
\Log::info("User exists. Setting GUID");
if ($provider ==='staff') {
$staff = Staff::query()->where('samaccountname','=', $user->username)->first();
if ($staff) {
\Log::info("AD User found. Updating");
$user->update(['guid' => $staff->getConvertedGuid()]);
}
} else {
$student = Student::query()->where('samaccountname','=', $user->username)->first();
if ($student) {
\Log::info("AD Student User found. Updating");
$user->update(['guid' => $student->getConvertedGuid()]);
}
}
}

if (! $skipLdapImport) {
$res = Artisan::call('ldap:import', [
'provider' => $provider,
@@ -35,7 +56,6 @@ public function syncUser(string $username, string $provider, ?bool $skipLdapImpo
throw new Exception('The options given could not be used for the import.');
}
}
$user = \App\Models\User::whereUsername($username)->first();
// Sync with DataService
if ($provider === 'staff') {
$staff = Webservice::make()->fetchStaff($username);
23 changes: 22 additions & 1 deletion src/Services/Webservice.php
Original file line number Diff line number Diff line change
@@ -22,12 +22,33 @@ public function fetchStudent(string | int $studentNo): Collection
return Http::withoutVerifying()->asJson()->acceptJson()->get(Ws::settings()->getStudentUrl($studentNo))->throw()->collect();
}

public function fetchStaffByNumber(string $staff_number): Collection
{
return Http::withoutVerifying()->asJson()->acceptJson()->get(Ws::settings()->getStaffByNumberUrl($staff_number))->throw()->collect();
}

/**
* @deprecated Use fetchStaffByUsername instead.
* @param string $username
* @return Collection
* @throws RequestException
*/
public function fetchStaff(string $username): Collection
{
return Http::withoutVerifying()->asJson()->acceptJson()->get(Ws::settings()->getStaffUrl($username))->throw()->collect();
return $this->fetchStaffByUsername($username);
}

public function fetchAllStaff(): Collection
{
return Http::withoutVerifying()->asJson()->acceptJson()->get(Ws::settings()->getAllStaffUrl())->throw()->collect();
}

/**
* @throws RequestException
*/
public function fetchStaffByUsername(string $username): Collection
{
return Http::withoutVerifying()->asJson()->acceptJson()->get(Ws::settings()->getStaffByUsernameUrl($username))->throw()->collect();
}

/**
11 changes: 9 additions & 2 deletions src/Settings/WebserviceSettings.php
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ class WebserviceSettings extends Settings

public ?string $staff_endpoint;

public ?string $staff_by_username_endpoint;

public ?string $student_endpoint;

public ?string $all_staff_endpoint;
@@ -37,11 +39,16 @@ public function makeUrl(string $endpoint, array $params = []): string
return \Str::of($this->base_url)->rtrim('/')->append('/')->append($path)->toString();
}

public function getStaffUrl($username): string
public function getStaffByUsernameUrl($username): string
{
return $this->makeUrl($this->staff_by_username_endpoint, ['username' => trim($username)]);
}
public function getStaffByNumberUrl(string $staff_number): string
{
return $this->makeUrl($this->staff_endpoint, ['username' => trim($username)]);
return $this->makeUrl($this->staff_endpoint, ['staff_number' => trim($staff_number)]);
}


public function getStudentUrl($studentNumber): string
{
return $this->makeUrl($this->student_endpoint, ['studentNo' => trim($studentNumber)]);
3 changes: 2 additions & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ function team(string $code): ?Team
if (!function_exists('Savannabits\Saas\current_team')) {
function current_team(): ?Team
{
return Auth::check() ? Auth::user()->team : null;
return Auth::check() ? Auth::user()->team : \Savannabits\Saas\team('DEFAULT');
}
}

@@ -35,6 +35,7 @@ function saas(): Saas
}
}


if (!function_exists('Savannabits\Saas\default_team')) {
function default_team(): Team
{