Skip to content

Commit

Permalink
Merge branch '4.x' into change-tags-in-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Nov 1, 2023
2 parents 4c5e169 + 4612bb1 commit b3132f7
Show file tree
Hide file tree
Showing 16 changed files with 191 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ jobs:

# Test
- name: Upgrade Chrome Driver
run: php artisan dusk:chrome-driver $(google-chrome -version | awk '{ print $3 }' | cut -d . -f 1)
run: php artisan dusk:chrome-driver --detect
- name: Start Chrome Driver
run: |
chmod -R 0755 vendor/laravel/dusk/bin/
Expand Down
134 changes: 134 additions & 0 deletions app/Console/Commands/ImportAccounts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

namespace App\Console\Commands;

use App\Models\Account\Account;
use Illuminate\Console\Command;

class ImportAccounts extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'account:import_ldap
{--ldap_uri= : LDAP URI.}
{--ldap_user= : LDAP Bind DN.}
{--ldap_pass= : LDAP Bind Password.}
{--ldap_base= : LDAP base DN for searching.}
{--ldap_filter= : Filter to search for user accounts.}
{--ldap_attr_mail= : LDAP attribute to map to email (default: mail).}
{--ldap_attr_firstname= : LDAP attribute to map to firstname (default: gn).}
{--ldap_attr_lastname= : LDAP attribute to map to lastname (default: sn).}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Import user accounts from LDAP';

/**
* Missing argument errors. Exposed for testing.
*/
const ERROR_MISSING_LDAP_FILTER = '! You must specify an LDAP Filter';
const ERROR_MISSING_LDAP_BASE = '! You must specify an LDAP Base';
const ERROR_MISSING_LDAP_USER = '! You must specify an LDAP User';
const ERROR_MISSING_LDAP_PASS = '! You must specify an LDAP Password';

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$ldap_uri = $this->option('ldap_uri') ?? '127.0.0.1';
$ldap_attr_mail = $this->option('ldap_attr_mail') ?? 'mail';
$ldap_attr_firstname = $this->option('ldap_attr_firstname') ?? 'givenName';
$ldap_attr_lastname = $this->option('ldap_attr_lastname') ?? 'sn';

$ldap_user = $this->option('ldap_user');
if (empty($ldap_user)) {
$this->error($this::ERROR_MISSING_LDAP_USER);
}

$ldap_pass = $this->option('ldap_pass');
if (empty($ldap_pass)) {
$this->error($this::ERROR_MISSING_LDAP_PASS);
}

$ldap_base = $this->option('ldap_base');
if (empty($ldap_base)) {
$this->error($this::ERROR_MISSING_LDAP_BASE);
}

$ldap_filter = $this->option('ldap_filter');
if (empty($ldap_filter)) {
$this->error($this::ERROR_MISSING_LDAP_FILTER);
}

if (empty($ldap_user) || empty($ldap_pass) || empty($ldap_base) || empty($ldap_filter)) {
return;
}

$ldap_conn = ldap_connect($ldap_uri);
if (! $ldap_conn) {
$this->error('Could not connect to LDAP URI');

return;
}
if (! ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3)) {
$this->error('Could not set LDAP protocol v3');

return false;
}

try {
$bind = ldap_bind($ldap_conn, $ldap_user, $ldap_pass);
if (! $bind) {
$this->error('Could not bind with given LDAP credentials');

return;
}
} catch (\Exception $e) {
$this->error($e->getMessage());

return;
}

$ldap_res = [];
try {
$ldap_res = ldap_search($ldap_conn, $ldap_base, $ldap_filter, [$ldap_attr_mail, $ldap_attr_firstname, $ldap_attr_lastname]);
} catch (\Exception $e) {
$this->error($e->getMessage());

return;
}

$ldap_data = ldap_get_entries($ldap_conn, $ldap_res);

for ($i = 0; $i < $ldap_data['count']; $i++) {
if (! (isset($ldap_data[$i][$ldap_attr_mail]) && $ldap_data[$i][$ldap_attr_mail]['count'] > 0)) {
continue;
}
$user_mail = $ldap_data[$i][$ldap_attr_mail][0];
$user_firstname = 'John';
$user_lastname = 'Doe';
$user_password = bin2hex(random_bytes(64));
if (isset($ldap_data[$i][$ldap_attr_firstname]) && $ldap_data[$i][$ldap_attr_firstname]['count'] > 0) {
$user_firstname = $ldap_data[$i][$ldap_attr_firstname][0];
}
if (isset($ldap_data[$i][$ldap_attr_lastname]) && $ldap_data[$i][$ldap_attr_lastname]['count'] > 0) {
$user_lastname = $ldap_data[$i][$ldap_attr_lastname][0];
}
$this->info('Importing user "'.$user_mail.'"');
try {
Account::createDefault($user_firstname, $user_lastname, $user_mail, $user_password);
} catch (\Exception $import_error) {
$this->warn('Could not import user "'.$user_mail.'": '.$import_error->getMessage());
}
}
}
}
2 changes: 1 addition & 1 deletion app/Helpers/CountriesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,6 @@ public static function getDefaultTimezone($country): string
break;
}

return $timezone;
return $timezone ?? config('app.timezone');
}
}
5 changes: 4 additions & 1 deletion app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ private function contacts(Request $request, bool $active)
}

$tagsCount = Tag::contactsCount();
$contactsWithoutTagsCount = (clone $contacts)->doesntHave('tags')->count();

$tags = null;
$url = null;
$count = 1;
Expand Down Expand Up @@ -134,7 +136,8 @@ private function contacts(Request $request, bool $active)
->withTagsCount($tagsCount)
->withUrl($url)
->withTagCount($count)
->withTagLess($request->input('no_tag') ?? false);
->withTagLess($request->input('no_tag') ?? false)
->with('contactsWithoutTagsCount', $contactsWithoutTagsCount);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public function index()
if (auth()->user()->me_contact_id) {
$meContact = Contact::where('account_id', auth()->user()->account_id)
->find(auth()->user()->me_contact_id);
$existingContacts->prepend($meContact);
if ($meContact) {
$existingContacts->prepend($meContact);
}
}

$accountHasLimitations = AccountHelper::hasLimitations(auth()->user()->account);
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"barryvdh/laravel-debugbar": "^3",
"fakerphp/faker": "^1.10",
"khanamiryan/qrcode-detector-decoder": "^2.0",
"laravel/dusk": "^7.0",
"laravel/dusk": "^7.11",
"laravel/legacy-factories": "^1.0",
"laravel/tinker": "^2.6",
"matthiasnoback/live-code-coverage": "^1",
Expand Down
21 changes: 12 additions & 9 deletions composer.lock

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

3 changes: 2 additions & 1 deletion config/mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'verify_peer' => env('MAIL_VERIFY_PEER', true),
],

'ses' => [
Expand All @@ -57,7 +58,7 @@

'sendmail' => [
'transport' => 'sendmail',
'path' => '/usr/sbin/sendmail -bs',
'path' => env('MAIL_SENDMAIL_PATH', '/usr/sbin/sendmail -bs -i'),
],

'log' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class RemoveViewedAtFromContacts extends Migration
*/
public function up()
{
Schema::table('contacts', function (Blueprint $table) {
$table->dropColumn(
'viewed_at'
);
});
if (Schema::hasColumn('contacts', 'viewed_at')) {
Schema::table('contacts', function (Blueprint $table) {
$table->dropColumn('viewed_at');
});
}
}

/**
Expand All @@ -27,8 +27,10 @@ public function up()
*/
public function down()
{
Schema::table('contacts', function (Blueprint $table) {
$table->dateTime('viewed_at')->nullable();
});
if (! Schema::hasColumn('contacts', 'viewed_at')) {
Schema::table('contacts', function (Blueprint $table) {
$table->dateTime('viewed_at')->nullable();
});
}
}
}
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,5 @@ parameters:
- */Http/Resources/**/*.php
- */ExportResources/**/*.php
- */ExportResources/*.php
- */Console/Commands/ImportAccounts.php

10 changes: 6 additions & 4 deletions resources/js/components/dashboard/DashboardLog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@
<a :href="'people/' + note.contact.id">
{{ note.name }}
</a>
<p>
{{ note.body }}
</p>
<p v-html="compiledMarkdown(note.body)"></p>
</div>
</div>
</template>
Expand Down Expand Up @@ -449,7 +447,11 @@ export default {
.then(response => {
this.tasks.splice(this.tasks.indexOf(task), 1);
});
}
},
compiledMarkdown (text) {
return text !== undefined && text !== null ? marked(text, { sanitize: true }) : '';
},
}
};
</script>
14 changes: 7 additions & 7 deletions resources/lang/he/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,10 @@
'relationship_type_lovedby_female_with_name' => 'מאהבת סודית של :name',
'relationship_type_lovedby_male_with_name' => 'מאהב סודי של :name',

'relationship_type_ex' => 'ex-partner',
'relationship_type_ex' => 'שותף לשעבר לחיים',
'relationship_type_ex_female' => 'חברה לשעבר',
'relationship_type_ex_male' => 'חבר לשעבר',
'relationship_type_ex_with_name' => ':name’s ex-partner',
'relationship_type_ex_with_name' => 'שותף לחיים לשעבר של :name',
'relationship_type_ex_female_with_name' => 'חברה לשעבר של :name',
'relationship_type_ex_male_with_name' => 'חבר לשעבר של :name',

Expand Down Expand Up @@ -222,17 +222,17 @@
'relationship_type_sibling_female_with_name' => 'אחות של :name',
'relationship_type_sibling_male_with_name' => 'אח של :name',

'relationship_type_grandparent' => 'grandparent',
'relationship_type_grandparent' => 'סב',
'relationship_type_grandparent_female' => 'סבתא',
'relationship_type_grandparent_male' => 'סבא',
'relationship_type_grandparent_with_name' => ':name’s grandparent',
'relationship_type_grandparent_with_name' => 'הסבא או הסבתא של :name',
'relationship_type_grandparent_female_with_name' => 'סבתא של :name',
'relationship_type_grandparent_male_with_name' => 'סבא של :name',

'relationship_type_grandchild' => 'נכד/ה',
'relationship_type_grandchild_female' => 'נכדה',
'relationship_type_grandchild_male' => 'נכד',
'relationship_type_grandchild_with_name' => ':name’s grandchild',
'relationship_type_grandchild_with_name' => 'הנכד או הנכדה של :name',
'relationship_type_grandchild_female_with_name' => 'נכדה של :name',
'relationship_type_grandchild_male_with_name' => 'נכד של :name',

Expand All @@ -257,10 +257,10 @@
'relationship_type_cousin_female_with_name' => 'בת דודה של :name',
'relationship_type_cousin_male_with_name' => 'בן דוד של :name',

'relationship_type_godfather' => 'godparent',
'relationship_type_godfather' => 'אפוטרופוס',
'relationship_type_godfather_female' => 'סנדקית',
'relationship_type_godfather_male' => 'סנדק',
'relationship_type_godfather_with_name' => ':name’s godparent',
'relationship_type_godfather_with_name' => 'האפוטרופוס/ית של :name',
'relationship_type_godfather_female_with_name' => 'הסנדקית של :name',
'relationship_type_godfather_male_with_name' => 'הסנדק של :name',

Expand Down
2 changes: 1 addition & 1 deletion resources/lang/he/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'export_title_json' => 'ייצוא ל־Json',
'export_submitted' => 'הייצוא שלך הוגש, הוא יהיה זמין בעוד מספר רגעים…',
'export_json_explanation' => 'הנתונים שלך מיוצאים בתצורת Json למטרות גיבוי.',
'export_json_beta' => 'Json export is in preview mode. Tell us what you think about it:',
'export_json_beta' => 'ייצוא Json הוא במצב תצוגה מקדימה. נא לספר לנו מה דעתך עליו:',
'export_json_cta' => 'ייצוא ל־Json',
'export_header_type' => 'סוג',
'export_header_timestamp' => 'מועד יצירה',
Expand Down
Loading

0 comments on commit b3132f7

Please sign in to comment.