From 8417945db36dcea2c263f3df011bcb30b5a33eac Mon Sep 17 00:00:00 2001 From: Mazarin Date: Sat, 21 May 2022 21:29:45 -0400 Subject: [PATCH] feat: better contact feed (monicahq/chandler#102) --- app/Console/Commands/SetupDummyAccount.php | 51 ++++++++++----- app/Helpers/UserHelper.php | 30 +++++++++ app/Helpers/WallpaperHelper.php | 2 - app/Models/ContactFeedItem.php | 19 +++++- app/Models/ContactImportantDate.php | 8 +++ app/Models/Note.php | 1 - app/Models/User.php | 17 ++++- database/factories/ContactFeedItemFactory.php | 3 + database/factories/NoteFactory.php | 1 - ...020_04_25_133132_create_contacts_table.php | 4 +- ...10_19_022411_create_contact_feed_table.php | 3 + .../2021_10_21_013005_create_notes_table.php | 1 - .../ManageContact/Services/UpdateContact.php | 11 ++++ .../Web/ViewHelpers/ModuleFeedViewHelper.php | 52 +++++++++++----- .../Services/CreateContactImportantDate.php | 11 +++- .../Services/DestroyContactImportantDate.php | 13 ++++ .../Services/UpdateContactImportantDate.php | 11 +++- .../ContactImportantDatesController.php | 2 +- .../Services/UpdateJobInformation.php | 7 +++ .../ManageLabels/Services/AssignLabel.php | 12 ++++ .../ManageLabels/Services/RemoveLabel.php | 12 ++++ .../ManageNotes/Services/CreateNote.php | 5 +- .../ManageNotes/Services/DestroyNote.php | 14 +++-- .../ManageNotes/Services/UpdateNote.php | 14 +++++ .../Web/ViewHelpers/ModuleNotesViewHelper.php | 3 +- .../Services/CreateLabel.php | 16 +++-- .../Services/GrantVaultAccessToUser.php | 7 +++ .../Vault/Contact/ImportantDates/Index.vue | 2 +- resources/js/Shared/Form/PrettyButton.vue | 6 +- resources/js/Shared/Modules/Calls.vue | 4 +- resources/js/Shared/Modules/ContactName.vue | 4 -- resources/js/Shared/Modules/Feed.vue | 35 ++++++++--- resources/js/Shared/Modules/GenderPronoun.vue | 4 -- .../js/Shared/Modules/JobInformation.vue | 4 -- resources/js/Shared/Modules/Loans.vue | 4 -- resources/js/Shared/Modules/Notes.vue | 25 +++----- resources/js/Shared/Modules/Tasks.vue | 6 +- resources/lang/en/contact.php | 15 +++++ tests/TestCase.php | 6 +- .../ViewHelpers/ModuleFeedViewHelperTest.php | 2 +- .../ManageNotes/Services/CreateNoteTest.php | 1 - .../ManageNotes/Services/DestroyNoteTest.php | 5 -- .../ViewHelpers/ModuleNotesViewHelperTest.php | 2 +- .../ViewHelpers/NotesIndexViewHelperTest.php | 2 +- .../ManageUsers/Services/DestroyUserTest.php | 6 ++ .../ViewHelpers/VaultIndexViewHelperTest.php | 7 ++- .../Services/ChangeVaultAccessTest.php | 2 + .../Services/GrantVaultAccessToUserTest.php | 2 +- .../VaultSettingsIndexViewHelperTest.php | 3 +- tests/Unit/Helpers/UserHelperTest.php | 62 +++++++++++++++++++ tests/Unit/Helpers/VaultHelperTest.php | 2 + tests/Unit/Models/ContactFeedItemTest.php | 8 +++ tests/Unit/Models/UserTest.php | 10 ++- tests/Unit/Models/VaultTest.php | 5 +- 54 files changed, 444 insertions(+), 120 deletions(-) create mode 100644 app/Helpers/UserHelper.php create mode 100644 resources/lang/en/contact.php create mode 100644 tests/Unit/Helpers/UserHelperTest.php diff --git a/app/Console/Commands/SetupDummyAccount.php b/app/Console/Commands/SetupDummyAccount.php index 7eb554775..13c83e0f8 100644 --- a/app/Console/Commands/SetupDummyAccount.php +++ b/app/Console/Commands/SetupDummyAccount.php @@ -19,7 +19,8 @@ use Illuminate\Console\Command; class SetupDummyAccount extends Command { protected ?\Faker\Generator $faker; - protected User $user; + protected User $firstUser; + protected User $secondUser; /** * The name and signature of the console command. @@ -54,7 +55,7 @@ class SetupDummyAccount extends Command { $this->start(); $this->wipeAndMigrateDB(); - $this->createFirstUser(); + $this->createFirstUsers(); $this->createVaults(); $this->createContacts(); $this->createNotes(); @@ -91,8 +92,12 @@ class SetupDummyAccount extends Command $this->line('-----------------------------'); $this->info('| You can now sign in with one of these two accounts:'); $this->line('| An account with a lot of data:'); + $this->line('| First user >>>>>>>>>>>>>>>>>:'); $this->line('| username: admin@admin.com'); $this->line('| password: admin123'); + $this->line('| Second user >>>>>>>>>>>>>>>>>:'); + $this->line('| username: regis@regis.com'); + $this->line('| password: admin123'); $this->line('|------------------------–––-'); $this->line('|A blank account:'); $this->line('| username: blank@blank.com'); @@ -104,20 +109,32 @@ class SetupDummyAccount extends Command $this->info('Setup is done. Have fun.'); } - private function createFirstUser(): void + private function createFirstUsers(): void { $this->info('☐ Create first user of the account'); - $this->user = (new CreateAccount)->execute([ + $this->firstUser = (new CreateAccount)->execute([ 'email' => 'admin@admin.com', 'password' => 'admin123', 'first_name' => 'Michael', 'last_name' => 'Scott', ]); + $this->firstUser->email_verified_at = Carbon::now(); + $this->firstUser->save(); - $this->user = User::first(); - $this->user->email_verified_at = Carbon::now(); - $this->user->save(); + sleep(5); + + $this->info('☐ Create second user of the account'); + + $this->secondUser = (new CreateAccount)->execute([ + 'email' => 'regis@regis.com', + 'password' => 'admin123', + 'first_name' => 'Dwight', + 'last_name' => 'Schrutt', + ]); + $this->secondUser->account_id = $this->firstUser->account_id; + $this->secondUser->email_verified_at = Carbon::now(); + $this->secondUser->save(); sleep(5); } @@ -128,8 +145,8 @@ class SetupDummyAccount extends Command for ($i = 0; $i < rand(3, 5); $i++) { (new CreateVault)->execute([ - 'account_id' => $this->user->account_id, - 'author_id' => $this->user->id, + 'account_id' => $this->firstUser->account_id, + 'author_id' => $this->firstUser->id, 'type' => Vault::TYPE_PERSONAL, 'name' => $this->faker->firstName, 'description' => rand(1, 2) == 1 ? $this->faker->sentence() : null, @@ -147,8 +164,8 @@ class SetupDummyAccount extends Command $birthDate = Carbon::parse($date); $contact = (new CreateContact)->execute([ - 'account_id' => $this->user->account_id, - 'author_id' => $this->user->id, + 'account_id' => $this->firstUser->account_id, + 'author_id' => $this->firstUser->id, 'vault_id' => $vault->id, 'first_name' => $this->faker->firstName(), 'last_name' => $this->faker->lastName(), @@ -159,8 +176,8 @@ class SetupDummyAccount extends Command ]); (new CreateContactImportantDate)->execute([ - 'account_id' => $this->user->account_id, - 'author_id' => $this->user->id, + 'account_id' => $this->firstUser->account_id, + 'author_id' => $this->firstUser->id, 'vault_id' => $vault->id, 'contact_id' => $contact->id, 'label' => 'Birthdate', @@ -180,8 +197,8 @@ class SetupDummyAccount extends Command foreach (Contact::all() as $contact) { for ($i = 0; $i < 4; $i++) { (new CreateNote)->execute([ - 'account_id' => $this->user->account_id, - 'author_id' => $this->user->id, + 'account_id' => $this->firstUser->account_id, + 'author_id' => $this->firstUser->id, 'vault_id' => $contact->vault_id, 'contact_id' => $contact->id, 'title' => rand(1, 2) == 1 ? $this->faker->sentence(rand(3, 6)) : null, @@ -198,8 +215,8 @@ class SetupDummyAccount extends Command foreach (Contact::all() as $contact) { for ($i = 0; $i < 4; $i++) { (new CreateContactTask)->execute([ - 'account_id' => $this->user->account_id, - 'author_id' => $this->user->id, + 'account_id' => $this->firstUser->account_id, + 'author_id' => $this->firstUser->id, 'vault_id' => $contact->vault_id, 'contact_id' => $contact->id, 'label' => $this->faker->sentence(rand(3, 6)), diff --git a/app/Helpers/UserHelper.php b/app/Helpers/UserHelper.php new file mode 100644 index 000000000..abe6ef479 --- /dev/null +++ b/app/Helpers/UserHelper.php @@ -0,0 +1,30 @@ +getContactInVault($vault); + + if (! $contact) { + return null; + } + + return [ + 'id' => $contact->id, + 'name' => $contact->getName($user), + 'avatar' => AvatarHelper::getSVG($contact), + ]; + } +} diff --git a/app/Helpers/WallpaperHelper.php b/app/Helpers/WallpaperHelper.php index ab752c18e..6342ea969 100644 --- a/app/Helpers/WallpaperHelper.php +++ b/app/Helpers/WallpaperHelper.php @@ -2,8 +2,6 @@ namespace App\Helpers; -use App\Models\Wallpaper; - class WallpaperHelper { /** diff --git a/app/Models/ContactFeedItem.php b/app/Models/ContactFeedItem.php index 0ba5445dc..06f7bf0fa 100644 --- a/app/Models/ContactFeedItem.php +++ b/app/Models/ContactFeedItem.php @@ -16,11 +16,16 @@ class ContactFeedItem extends Model /** * Possible actions. */ + const ACTION_CONTACT_INFORMATION_UPDATED = 'contact_information_updated'; + const ACTION_JOB_INFORMATION_UPDATED = 'job_information_updated'; const ACTION_NOTE_CREATED = 'note_created'; const ACTION_NOTE_UPDATED = 'note_updated'; + const ACTION_NOTE_DESTROYED = 'note_destroyed'; const ACTION_IMPORTANT_DATE_CREATED = 'important_date_created'; const ACTION_IMPORTANT_DATE_UPDATED = 'important_date_updated'; - const ACTION_LABEL_ADDED = 'label_added'; + const ACTION_IMPORTANT_DATE_DESTROYED = 'important_date_destroyed'; + const ACTION_LABEL_ASSIGNED = 'label_assigned'; + const ACTION_LABEL_REMOVED = 'label_removed'; const ACTION_LOAN_CREATED = 'loan_created'; const ACTION_LOAN_UPDATED = 'loan_updated'; @@ -30,12 +35,24 @@ class ContactFeedItem extends Model * @var array */ protected $fillable = [ + 'author_id', 'contact_id', 'action', + 'description', 'feedable_id', 'feedable_type', ]; + /** + * Get the user associated with the contact feed item. + * + * @return BelongsTo + */ + public function author() + { + return $this->belongsTo(User::class, 'author_id'); + } + /** * Get the contact associated with the contact feed item. * diff --git a/app/Models/ContactImportantDate.php b/app/Models/ContactImportantDate.php index 57f69d8b8..0a702a5f8 100644 --- a/app/Models/ContactImportantDate.php +++ b/app/Models/ContactImportantDate.php @@ -58,4 +58,12 @@ class ContactImportantDate extends Model { return $this->belongsTo(ContactImportantDateType::class); } + + /** + * Get the important date's feed item. + */ + public function feedItem() + { + return $this->morphOne(ContactFeedItem::class, 'feedable'); + } } diff --git a/app/Models/Note.php b/app/Models/Note.php index 5ff2d5845..42c9ac980 100644 --- a/app/Models/Note.php +++ b/app/Models/Note.php @@ -20,7 +20,6 @@ class Note extends Model 'contact_id', 'author_id', 'emotion_id', - 'author_name', 'title', 'body', ]; diff --git a/app/Models/User.php b/app/Models/User.php index 32e66eeeb..7a900f478 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\HasMany; @@ -134,14 +135,24 @@ class User extends Authenticatable implements MustVerifyEmail * All users have a contact in the vaults. * * @param Vault $vault - * @return Contact + * @return null|Contact */ - public function getContactInVault(Vault $vault): Contact + public function getContactInVault(Vault $vault): ?Contact { $contact = DB::table('user_vault')->where('vault_id', $vault->id) ->where('user_id', $this->id) ->first(); - return Contact::findOrFail($contact->contact_id); + if (! $contact) { + return null; + } + + try { + $contact = Contact::findOrFail($contact->contact_id); + } catch (ModelNotFoundException) { + return null; + } + + return $contact; } } diff --git a/database/factories/ContactFeedItemFactory.php b/database/factories/ContactFeedItemFactory.php index 03e3c9848..b5ce66fe2 100644 --- a/database/factories/ContactFeedItemFactory.php +++ b/database/factories/ContactFeedItemFactory.php @@ -4,6 +4,7 @@ namespace Database\Factories; use App\Models\Contact; use App\Models\ContactFeedItem; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; class ContactFeedItemFactory extends Factory @@ -23,8 +24,10 @@ class ContactFeedItemFactory extends Factory public function definition() { return [ + 'author_id' => User::factory(), 'contact_id' => Contact::factory(), 'action' => ContactFeedItem::ACTION_NOTE_CREATED, + 'description' => $this->faker->word(), ]; } } diff --git a/database/factories/NoteFactory.php b/database/factories/NoteFactory.php index 73e8424da..4a04bf02c 100644 --- a/database/factories/NoteFactory.php +++ b/database/factories/NoteFactory.php @@ -26,7 +26,6 @@ class NoteFactory extends Factory return [ 'contact_id' => Contact::factory(), 'author_id' => User::factory(), - 'author_name' => $this->faker->name(), 'title' => $this->faker->title(), 'body' => $this->faker->sentence(), ]; diff --git a/database/migrations/2020_04_25_133132_create_contacts_table.php b/database/migrations/2020_04_25_133132_create_contacts_table.php index 8be839bb2..391ea51b9 100644 --- a/database/migrations/2020_04_25_133132_create_contacts_table.php +++ b/database/migrations/2020_04_25_133132_create_contacts_table.php @@ -41,12 +41,12 @@ class CreateContactsTable extends Migration Schema::create('user_vault', function (Blueprint $table) { $table->unsignedBigInteger('vault_id'); $table->unsignedBigInteger('user_id'); - $table->unsignedBigInteger('contact_id')->nullable(); + $table->unsignedBigInteger('contact_id'); $table->integer('permission'); $table->timestamps(); $table->foreign('vault_id')->references('id')->on('vaults')->onDelete('cascade'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); - $table->foreign('contact_id')->references('id')->on('contacts')->onDelete('set null'); + $table->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade'); }); Schema::create('contact_vault_user', function (Blueprint $table) { diff --git a/database/migrations/2021_10_19_022411_create_contact_feed_table.php b/database/migrations/2021_10_19_022411_create_contact_feed_table.php index 549f7b015..484883041 100644 --- a/database/migrations/2021_10_19_022411_create_contact_feed_table.php +++ b/database/migrations/2021_10_19_022411_create_contact_feed_table.php @@ -16,11 +16,14 @@ class CreateContactFeedTable extends Migration Schema::create('contact_feed_items', function (Blueprint $table) { $table->id(); + $table->unsignedBigInteger('author_id')->nullable(); $table->unsignedBigInteger('contact_id'); $table->string('action'); + $table->string('description')->nullable(); $table->unsignedBigInteger('feedable_id')->nullable(); $table->string('feedable_type')->nullable(); $table->timestamps(); + $table->foreign('author_id')->references('id')->on('users')->onDelete('set null'); $table->foreign('contact_id')->references('id')->on('contacts')->onDelete('cascade'); }); } diff --git a/database/migrations/2021_10_21_013005_create_notes_table.php b/database/migrations/2021_10_21_013005_create_notes_table.php index 09d5436be..a47f98484 100644 --- a/database/migrations/2021_10_21_013005_create_notes_table.php +++ b/database/migrations/2021_10_21_013005_create_notes_table.php @@ -19,7 +19,6 @@ class CreateNotesTable extends Migration $table->unsignedBigInteger('contact_id'); $table->unsignedBigInteger('author_id')->nullable(); $table->unsignedBigInteger('emotion_id')->nullable(); - $table->string('author_name'); $table->string('title')->nullable(); $table->text('body'); $table->timestamps(); diff --git a/domains/Contact/ManageContact/Services/UpdateContact.php b/domains/Contact/ManageContact/Services/UpdateContact.php index fa935bfe3..1e748c0bf 100644 --- a/domains/Contact/ManageContact/Services/UpdateContact.php +++ b/domains/Contact/ManageContact/Services/UpdateContact.php @@ -6,6 +6,7 @@ use App\Interfaces\ServiceInterface; use App\Jobs\CreateAuditLog; use App\Jobs\CreateContactLog; use App\Models\Contact; +use App\Models\ContactFeedItem; use App\Models\Gender; use App\Models\Pronoun; use App\Services\BaseService; @@ -84,6 +85,7 @@ class UpdateContact extends BaseService implements ServiceInterface $this->contact->save(); $this->log(); + $this->createFeedItem(); return $this->contact; } @@ -124,4 +126,13 @@ class UpdateContact extends BaseService implements ServiceInterface 'objects' => json_encode([]), ])->onQueue('low'); } + + private function createFeedItem(): void + { + ContactFeedItem::create([ + 'author_id' => $this->author->id, + 'contact_id' => $this->contact->id, + 'action' => ContactFeedItem::ACTION_CONTACT_INFORMATION_UPDATED, + ]); + } } diff --git a/domains/Contact/ManageContactFeed/Web/ViewHelpers/ModuleFeedViewHelper.php b/domains/Contact/ManageContactFeed/Web/ViewHelpers/ModuleFeedViewHelper.php index 9e388178d..c683664a9 100644 --- a/domains/Contact/ManageContactFeed/Web/ViewHelpers/ModuleFeedViewHelper.php +++ b/domains/Contact/ManageContactFeed/Web/ViewHelpers/ModuleFeedViewHelper.php @@ -2,7 +2,8 @@ namespace App\Contact\ManageContactFeed\Web\ViewHelpers; -use App\Contact\ManageNotes\Web\ViewHelpers\ModuleNotesViewHelper; +use App\Helpers\DateHelper; +use App\Helpers\UserHelper; use App\Models\Contact; use App\Models\ContactFeedItem; use App\Models\User; @@ -15,23 +16,14 @@ class ModuleFeedViewHelper ->orderBy('created_at', 'desc') ->get(); - $itemsCollection = $items->map(function ($item) use ($contact, $user) { - if ($item->action == ContactFeedItem::ACTION_NOTE_CREATED) { - $object = ModuleNotesViewHelper::dto($contact, $item->feedable, $user); - } - - if ($item->action == ContactFeedItem::ACTION_IMPORTANT_DATE_CREATED) { - $object = trans('feed.important_date_created'); - } - - if ($item->action == ContactFeedItem::ACTION_IMPORTANT_DATE_UPDATED) { - $object = trans('feed.important_date_updated'); - } - + $itemsCollection = $items->map(function ($item) use ($user) { return [ 'id' => $item->id, 'action' => $item->action, - 'object' => $object, + 'author' => self::getAuthor($item, $user), + 'sentence' => self::getSentence($item), + 'description' => $item->description, + 'created_at' => DateHelper::format($item->created_at, $user), ]; }); @@ -39,4 +31,34 @@ class ModuleFeedViewHelper 'items' => $itemsCollection, ]; } + + private static function getSentence(ContactFeedItem $item): mixed + { + return trans('contact.feed_item_'.$item->action); + } + + private static function getAuthor(ContactFeedItem $item, User $user): ?array + { + $author = $item->author; + if (! $author) { + $monicaSvg = ' + + + + + + + + + + '; + + return [ + 'name' => trans('contact.feed_item_author_deleted'), + 'avatar' => $monicaSvg, + ]; + } + + return UserHelper::getInformationAboutContact($author, $item->contact->vault); + } } diff --git a/domains/Contact/ManageContactImportantDates/Services/CreateContactImportantDate.php b/domains/Contact/ManageContactImportantDates/Services/CreateContactImportantDate.php index 3ca50f0bd..5715b4fd9 100644 --- a/domains/Contact/ManageContactImportantDates/Services/CreateContactImportantDate.php +++ b/domains/Contact/ManageContactImportantDates/Services/CreateContactImportantDate.php @@ -2,6 +2,7 @@ namespace App\Contact\ManageContactImportantDates\Services; +use App\Helpers\ImportantDateHelper; use App\Interfaces\ServiceInterface; use App\Jobs\CreateAuditLog; use App\Jobs\CreateContactLog; @@ -71,6 +72,7 @@ class CreateContactImportantDate extends BaseService implements ServiceInterface ]); $this->log(); + $this->createFeedItem(); return $this->date; } @@ -109,10 +111,17 @@ class CreateContactImportantDate extends BaseService implements ServiceInterface 'label' => $this->date->label, ]), ])->onQueue('low'); + } - ContactFeedItem::create([ + private function createFeedItem(): void + { + $feedItem = ContactFeedItem::create([ + 'author_id' => $this->author->id, 'contact_id' => $this->contact->id, 'action' => ContactFeedItem::ACTION_IMPORTANT_DATE_CREATED, + 'description' => $this->date->label.' '.ImportantDateHelper::formatDate($this->date, $this->author), ]); + + $this->date->feedItem()->save($feedItem); } } diff --git a/domains/Contact/ManageContactImportantDates/Services/DestroyContactImportantDate.php b/domains/Contact/ManageContactImportantDates/Services/DestroyContactImportantDate.php index f2fb5dc95..b3d742603 100644 --- a/domains/Contact/ManageContactImportantDates/Services/DestroyContactImportantDate.php +++ b/domains/Contact/ManageContactImportantDates/Services/DestroyContactImportantDate.php @@ -2,10 +2,12 @@ namespace App\Contact\ManageContactImportantDates\Services; +use App\Helpers\ImportantDateHelper; use App\Interfaces\ServiceInterface; use App\Jobs\CreateAuditLog; use App\Jobs\CreateContactLog; use App\Models\Address; +use App\Models\ContactFeedItem; use App\Models\ContactImportantDate; use App\Services\BaseService; use Carbon\Carbon; @@ -63,6 +65,7 @@ class DestroyContactImportantDate extends BaseService implements ServiceInterfac $this->contact->save(); $this->log(); + $this->createFeedItem(); } private function log(): void @@ -87,4 +90,14 @@ class DestroyContactImportantDate extends BaseService implements ServiceInterfac ]), ])->onQueue('low'); } + + private function createFeedItem(): void + { + ContactFeedItem::create([ + 'author_id' => $this->author->id, + 'contact_id' => $this->contact->id, + 'action' => ContactFeedItem::ACTION_IMPORTANT_DATE_DESTROYED, + 'description' => $this->date->label.' '.ImportantDateHelper::formatDate($this->date, $this->author), + ]); + } } diff --git a/domains/Contact/ManageContactImportantDates/Services/UpdateContactImportantDate.php b/domains/Contact/ManageContactImportantDates/Services/UpdateContactImportantDate.php index a32263930..524fde26f 100644 --- a/domains/Contact/ManageContactImportantDates/Services/UpdateContactImportantDate.php +++ b/domains/Contact/ManageContactImportantDates/Services/UpdateContactImportantDate.php @@ -2,6 +2,7 @@ namespace App\Contact\ManageContactImportantDates\Services; +use App\Helpers\ImportantDateHelper; use App\Interfaces\ServiceInterface; use App\Jobs\CreateAuditLog; use App\Jobs\CreateContactLog; @@ -64,6 +65,7 @@ class UpdateContactImportantDate extends BaseService implements ServiceInterface $this->validate(); $this->update(); $this->log(); + $this->createFeedItem(); return $this->date; } @@ -118,10 +120,17 @@ class UpdateContactImportantDate extends BaseService implements ServiceInterface 'label' => $this->date->label, ]), ])->onQueue('low'); + } - ContactFeedItem::create([ + private function createFeedItem(): void + { + $feedItem = ContactFeedItem::create([ + 'author_id' => $this->author->id, 'contact_id' => $this->contact->id, 'action' => ContactFeedItem::ACTION_IMPORTANT_DATE_UPDATED, + 'description' => $this->date->label.' '.ImportantDateHelper::formatDate($this->date, $this->author), ]); + + $this->date->feedItem()->save($feedItem); } } diff --git a/domains/Contact/ManageContactImportantDates/Web/Controllers/ContactImportantDatesController.php b/domains/Contact/ManageContactImportantDates/Web/Controllers/ContactImportantDatesController.php index 30b487355..b727e4280 100644 --- a/domains/Contact/ManageContactImportantDates/Web/Controllers/ContactImportantDatesController.php +++ b/domains/Contact/ManageContactImportantDates/Web/Controllers/ContactImportantDatesController.php @@ -110,7 +110,7 @@ class ContactImportantDatesController extends Controller 'vault_id' => $vaultId, 'contact_id' => $contactId, 'contact_important_date_id' => $dateId, - 'contact_important_date_type_id' => $request->input('contact_important_date_type_id'), + 'contact_important_date_type_id' => $request->input('contact_important_date_type_id') == 0 ? null : $request->input('contact_important_date_type_id'), 'label' => $request->input('label'), 'day' => $day, 'month' => $month, diff --git a/domains/Contact/ManageJobInformation/Services/UpdateJobInformation.php b/domains/Contact/ManageJobInformation/Services/UpdateJobInformation.php index 97c22f741..35e35e28f 100644 --- a/domains/Contact/ManageJobInformation/Services/UpdateJobInformation.php +++ b/domains/Contact/ManageJobInformation/Services/UpdateJobInformation.php @@ -5,6 +5,7 @@ namespace App\Contact\ManageJobInformation\Services; use App\Interfaces\ServiceInterface; use App\Models\Company; use App\Models\Contact; +use App\Models\ContactFeedItem; use App\Services\BaseService; class UpdateJobInformation extends BaseService implements ServiceInterface @@ -62,6 +63,12 @@ class UpdateJobInformation extends BaseService implements ServiceInterface $this->contact->job_position = $this->valueOrNull($data, 'job_position'); $this->contact->save(); + ContactFeedItem::create([ + 'author_id' => $this->author->id, + 'contact_id' => $this->contact->id, + 'action' => ContactFeedItem::ACTION_JOB_INFORMATION_UPDATED, + ]); + return $this->contact; } } diff --git a/domains/Contact/ManageLabels/Services/AssignLabel.php b/domains/Contact/ManageLabels/Services/AssignLabel.php index 2af0d27c1..e34a895f0 100644 --- a/domains/Contact/ManageLabels/Services/AssignLabel.php +++ b/domains/Contact/ManageLabels/Services/AssignLabel.php @@ -5,6 +5,7 @@ namespace App\Contact\ManageLabels\Services; use App\Interfaces\ServiceInterface; use App\Jobs\CreateAuditLog; use App\Jobs\CreateContactLog; +use App\Models\ContactFeedItem; use App\Models\Label; use App\Services\BaseService; use Carbon\Carbon; @@ -63,6 +64,7 @@ class AssignLabel extends BaseService implements ServiceInterface $this->contact->save(); $this->log(); + $this->createFeedItem(); return $this->label; } @@ -91,4 +93,14 @@ class AssignLabel extends BaseService implements ServiceInterface ]), ])->onQueue('low'); } + + private function createFeedItem(): void + { + ContactFeedItem::create([ + 'author_id' => $this->author->id, + 'contact_id' => $this->contact->id, + 'action' => ContactFeedItem::ACTION_LABEL_ASSIGNED, + 'description' => $this->label->name, + ]); + } } diff --git a/domains/Contact/ManageLabels/Services/RemoveLabel.php b/domains/Contact/ManageLabels/Services/RemoveLabel.php index 1128c978c..4a2cfd885 100644 --- a/domains/Contact/ManageLabels/Services/RemoveLabel.php +++ b/domains/Contact/ManageLabels/Services/RemoveLabel.php @@ -5,6 +5,7 @@ namespace App\Contact\ManageLabels\Services; use App\Interfaces\ServiceInterface; use App\Jobs\CreateAuditLog; use App\Jobs\CreateContactLog; +use App\Models\ContactFeedItem; use App\Models\Label; use App\Services\BaseService; use Carbon\Carbon; @@ -63,6 +64,7 @@ class RemoveLabel extends BaseService implements ServiceInterface $this->contact->save(); $this->log(); + $this->createFeedItem(); return $this->label; } @@ -91,4 +93,14 @@ class RemoveLabel extends BaseService implements ServiceInterface ]), ])->onQueue('low'); } + + private function createFeedItem(): void + { + ContactFeedItem::create([ + 'author_id' => $this->author->id, + 'contact_id' => $this->contact->id, + 'action' => ContactFeedItem::ACTION_LABEL_REMOVED, + 'description' => $this->label->name, + ]); + } } diff --git a/domains/Contact/ManageNotes/Services/CreateNote.php b/domains/Contact/ManageNotes/Services/CreateNote.php index 191847c35..19fff1679 100644 --- a/domains/Contact/ManageNotes/Services/CreateNote.php +++ b/domains/Contact/ManageNotes/Services/CreateNote.php @@ -10,6 +10,7 @@ use App\Models\Emotion; use App\Models\Note; use App\Services\BaseService; use Carbon\Carbon; +use Illuminate\Support\Str; class CreateNote extends BaseService implements ServiceInterface { @@ -67,7 +68,6 @@ class CreateNote extends BaseService implements ServiceInterface $this->note = Note::create([ 'contact_id' => $this->contact->id, 'author_id' => $this->author->id, - 'author_name' => $this->author->name, 'title' => $this->valueOrNull($data, 'title'), 'body' => $data['body'], 'emotion_id' => $this->valueOrNull($data, 'emotion_id'), @@ -77,7 +77,6 @@ class CreateNote extends BaseService implements ServiceInterface $this->contact->save(); $this->log(); - $this->createFeedItem(); return $this->note; @@ -111,8 +110,10 @@ class CreateNote extends BaseService implements ServiceInterface private function createFeedItem(): void { $feedItem = ContactFeedItem::create([ + 'author_id' => $this->author->id, 'contact_id' => $this->contact->id, 'action' => ContactFeedItem::ACTION_NOTE_CREATED, + 'description' => Str::words($this->note->body, 10, '…'), ]); $this->note->feedItem()->save($feedItem); } diff --git a/domains/Contact/ManageNotes/Services/DestroyNote.php b/domains/Contact/ManageNotes/Services/DestroyNote.php index 6f0f22fa1..a060a501f 100644 --- a/domains/Contact/ManageNotes/Services/DestroyNote.php +++ b/domains/Contact/ManageNotes/Services/DestroyNote.php @@ -5,9 +5,11 @@ namespace App\Contact\ManageNotes\Services; use App\Interfaces\ServiceInterface; use App\Jobs\CreateAuditLog; use App\Jobs\CreateContactLog; +use App\Models\ContactFeedItem; use App\Models\Note; use App\Services\BaseService; use Carbon\Carbon; +use Illuminate\Support\Str; class DestroyNote extends BaseService implements ServiceInterface { @@ -56,8 +58,7 @@ class DestroyNote extends BaseService implements ServiceInterface $this->note = Note::where('contact_id', $data['contact_id']) ->findOrFail($data['note_id']); - $this->removeContactFeedItem(); - + $this->createFeedItem(); $this->note->delete(); $this->contact->last_updated_at = Carbon::now(); @@ -88,8 +89,13 @@ class DestroyNote extends BaseService implements ServiceInterface ])->onQueue('low'); } - private function removeContactFeedItem(): void + private function createFeedItem(): void { - $this->note->feedItem->delete(); + ContactFeedItem::create([ + 'author_id' => $this->author->id, + 'contact_id' => $this->contact->id, + 'action' => ContactFeedItem::ACTION_NOTE_DESTROYED, + 'description' => Str::words($this->note->body, 10, '…'), + ]); } } diff --git a/domains/Contact/ManageNotes/Services/UpdateNote.php b/domains/Contact/ManageNotes/Services/UpdateNote.php index 01a1d4742..df96dc735 100644 --- a/domains/Contact/ManageNotes/Services/UpdateNote.php +++ b/domains/Contact/ManageNotes/Services/UpdateNote.php @@ -5,10 +5,12 @@ namespace App\Contact\ManageNotes\Services; use App\Interfaces\ServiceInterface; use App\Jobs\CreateAuditLog; use App\Jobs\CreateContactLog; +use App\Models\ContactFeedItem; use App\Models\Emotion; use App\Models\Note; use App\Services\BaseService; use Carbon\Carbon; +use Illuminate\Support\Str; class UpdateNote extends BaseService implements ServiceInterface { @@ -76,6 +78,7 @@ class UpdateNote extends BaseService implements ServiceInterface $this->contact->save(); $this->log(); + $this->createFeedItem(); return $this->note; } @@ -104,4 +107,15 @@ class UpdateNote extends BaseService implements ServiceInterface ]), ])->onQueue('low'); } + + private function createFeedItem(): void + { + $feedItem = ContactFeedItem::create([ + 'author_id' => $this->author->id, + 'contact_id' => $this->contact->id, + 'action' => ContactFeedItem::ACTION_NOTE_UPDATED, + 'description' => Str::words($this->note->body, 10, '…'), + ]); + $this->note->feedItem()->save($feedItem); + } } diff --git a/domains/Contact/ManageNotes/Web/ViewHelpers/ModuleNotesViewHelper.php b/domains/Contact/ManageNotes/Web/ViewHelpers/ModuleNotesViewHelper.php index 9d09647e7..26d50e756 100644 --- a/domains/Contact/ManageNotes/Web/ViewHelpers/ModuleNotesViewHelper.php +++ b/domains/Contact/ManageNotes/Web/ViewHelpers/ModuleNotesViewHelper.php @@ -3,6 +3,7 @@ namespace App\Contact\ManageNotes\Web\ViewHelpers; use App\Helpers\DateHelper; +use App\Helpers\UserHelper; use App\Models\Contact; use App\Models\Note; use App\Models\User; @@ -53,7 +54,7 @@ class ModuleNotesViewHelper 'id' => $note->emotion->id, 'name' => $note->emotion->name, ] : null, - 'author' => $note->author ? $note->author->name : $note->author_name, + 'author' => $note->author ? UserHelper::getInformationAboutContact($note->author, $contact->vault) : null, 'written_at' => DateHelper::format($note->created_at, $user), 'url' => [ 'update' => route('contact.note.update', [ diff --git a/domains/Vault/ManageVaultSettings/Services/CreateLabel.php b/domains/Vault/ManageVaultSettings/Services/CreateLabel.php index 79ed317ec..4a78c0dca 100644 --- a/domains/Vault/ManageVaultSettings/Services/CreateLabel.php +++ b/domains/Vault/ManageVaultSettings/Services/CreateLabel.php @@ -10,6 +10,9 @@ use Illuminate\Support\Str; class CreateLabel extends BaseService implements ServiceInterface { + private array $data; + private Label $label; + /** * Get the validation rules that apply to the service. * @@ -52,7 +55,7 @@ class CreateLabel extends BaseService implements ServiceInterface { $this->validateRules($data); - $label = Label::create([ + $this->label = Label::create([ 'vault_id' => $data['vault_id'], 'name' => $data['name'], 'description' => $this->valueOrNull($data, 'description'), @@ -61,16 +64,21 @@ class CreateLabel extends BaseService implements ServiceInterface 'text_color' => $data['text_color'], ]); + $this->log(); + + return $this->label; + } + + private function log(): void + { CreateAuditLog::dispatch([ 'account_id' => $this->author->account_id, 'author_id' => $this->author->id, 'author_name' => $this->author->name, 'action_name' => 'label_created', 'objects' => json_encode([ - 'label_name' => $label->name, + 'label_name' => $this->label->name, ]), ])->onQueue('low'); - - return $label; } } diff --git a/domains/Vault/ManageVaultSettings/Services/GrantVaultAccessToUser.php b/domains/Vault/ManageVaultSettings/Services/GrantVaultAccessToUser.php index 1281c2b20..0e00d5d6d 100644 --- a/domains/Vault/ManageVaultSettings/Services/GrantVaultAccessToUser.php +++ b/domains/Vault/ManageVaultSettings/Services/GrantVaultAccessToUser.php @@ -4,6 +4,7 @@ namespace App\Vault\ManageVaultSettings\Services; use App\Contact\ManageReminders\Services\ScheduleContactReminderForUser; use App\Exceptions\SameUserException; +use App\Helpers\AvatarHelper; use App\Helpers\VaultHelper; use App\Interfaces\ServiceInterface; use App\Jobs\CreateAuditLog; @@ -84,12 +85,18 @@ class GrantVaultAccessToUser extends BaseService implements ServiceInterface 'first_name' => $this->user->first_name, 'last_name' => $this->user->last_name, 'can_be_deleted' => false, + 'template_id' => $this->vault->default_template_id, ]); $this->vault->users()->save($this->user, [ 'permission' => $this->data['permission'], 'contact_id' => $contact->id, ]); + + $avatar = AvatarHelper::generateRandomAvatar($contact); + + $contact->avatar_id = $avatar->id; + $contact->save(); } /** diff --git a/resources/js/Pages/Vault/Contact/ImportantDates/Index.vue b/resources/js/Pages/Vault/Contact/ImportantDates/Index.vue index 09a960fac..16ebe4fb5 100644 --- a/resources/js/Pages/Vault/Contact/ImportantDates/Index.vue +++ b/resources/js/Pages/Vault/Contact/ImportantDates/Index.vue @@ -470,7 +470,7 @@ export default { label: '', date: '', age: '', - contact_important_date_type_id: 0, + contact_important_date_type_id: null, reminder: false, reminderChoice: '', errors: [], diff --git a/resources/js/Shared/Form/PrettyButton.vue b/resources/js/Shared/Form/PrettyButton.vue index 7607ff5af..67147dc71 100644 --- a/resources/js/Shared/Form/PrettyButton.vue +++ b/resources/js/Shared/Form/PrettyButton.vue @@ -49,7 +49,7 @@ button { @@ -60,7 +60,7 @@ button { @@ -75,7 +75,7 @@ button { diff --git a/resources/js/Shared/Modules/Calls.vue b/resources/js/Shared/Modules/Calls.vue index 1d972efe3..f92be5a32 100644 --- a/resources/js/Shared/Modules/Calls.vue +++ b/resources/js/Shared/Modules/Calls.vue @@ -43,7 +43,7 @@ Calls - + @@ -234,7 +234,7 @@
- +
diff --git a/resources/js/Shared/Modules/ContactName.vue b/resources/js/Shared/Modules/ContactName.vue index 09026811b..cc6d84572 100644 --- a/resources/js/Shared/Modules/ContactName.vue +++ b/resources/js/Shared/Modules/ContactName.vue @@ -2,10 +2,6 @@ .icon-sidebar { top: -2px; } - -.icon-note { - top: -1px; -}