Просмотр исходного кода

Add Default group option in Settings

Bubka 4 лет назад
Родитель
Сommit
a8e5535d6b

+ 13 - 0
app/Http/Controllers/TwoFAccountController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 
+use App\Group;
 use App\TwoFAccount;
 use App\Classes\OTP;
 use App\Classes\Options;
@@ -47,6 +48,18 @@ class TwoFAccountController extends Controller
             'icon' => $request->icon
         ]);
 
+        // Possible group association
+        $groupId = Options::get('defaultGroup') === '-1' ? (int) Options::get('activeGroup') : (int) Options::get('defaultGroup');
+        
+        // 0 is the pseudo group 'All', only groups with id > 0 are true user groups
+        if( $groupId > 0 ) {
+            $group = Group::find($groupId);
+
+            if($group) {
+                $group->twofaccounts()->save($twofaccount);
+            }
+        }
+
         return response()->json($twofaccount, 201);
     }
 

+ 1 - 0
config/app.php

@@ -40,6 +40,7 @@ return [
         'showAccountsIcons' => true,
         'kickUserAfter' => '15',
         'activeGroup' => 0,
+        'defaultGroup' => 0,
         'useEncryption' => false,
     ],
 

+ 26 - 0
resources/js/views/settings/Options.vue

@@ -8,6 +8,8 @@
             <form-select :options="layouts" :form="form" fieldName="displayMode" :label="$t('settings.forms.display_mode.label')" :help="$t('settings.forms.display_mode.help')" />
             <!-- show icon -->
             <form-checkbox :form="form" fieldName="showAccountsIcons" :label="$t('settings.forms.show_accounts_icons.label')" :help="$t('settings.forms.show_accounts_icons.help')" />
+            <!-- default group -->
+            <form-select :options="groups" :form="form" fieldName="defaultGroup" :label="$t('settings.forms.default_group.label')" :help="$t('settings.forms.default_group.help')" />
 
             <h4 class="title is-4">{{ $t('settings.security') }}</h4>
             <!-- auto lock -->
@@ -42,6 +44,7 @@
                     displayMode: this.$root.appSettings.displayMode,
                     kickUserAfter: this.$root.appSettings.kickUserAfter,
                     useEncryption: this.$root.appSettings.useEncryption,
+                    defaultGroup: this.$root.appSettings.defaultGroup,
                 }),
                 langs: [
                     { text: this.$t('languages.en'), value: 'en' },
@@ -61,10 +64,18 @@
                     { text: this.$t('settings.forms.30_minutes'), value: '30' },
                     { text: this.$t('settings.forms.1_hour'), value: '60' },
                     { text: this.$t('settings.forms.1_day'), value: '1440' }, 
+                ],
+                groups: [
+                    { text: this.$t('groups.no_group'), value: 0 },
+                    { text: this.$t('groups.active_group'), value: -1 },
                 ]
             }
         },
 
+        mounted() {
+            this.fetchGroups()
+        },
+
         methods : {
             handleSubmit(e) {
                 e.preventDefault()
@@ -86,6 +97,21 @@
                     this.$notify({ type: 'is-danger', text: error.response.data.message })
                 });
             },
+
+            fetchGroups() {
+
+                this.axios.get('api/groups').then(response => {
+                    response.data.forEach((data) => {
+                        if( data.id >0 ) {
+                                this.groups.push({
+                                text: data.name,
+                                value: data.id
+                            })
+                        }
+                    })
+                })
+            },
+
         },
     }
 </script>

+ 1 - 0
resources/lang/en/groups.php

@@ -16,6 +16,7 @@ return [
     'groups' => 'Groups',
     'select_accounts_to_show' => 'Select accounts to show',
     'manage_groups' => 'Manage groups',
+    'active_group' => 'Active group',
     'manage_groups_legend' => 'You can create groups to organize your accounts the way you want. All accounts remain visible in the pseudo group named \'All\', regardless of the group they belong to.',
     'deleting_group_does_not_delete_accounts' => 'Deleting a group does not delete accounts',
     'no_group' => 'No group',

+ 4 - 0
resources/lang/en/settings.php

@@ -60,6 +60,10 @@ return [
             'label' => 'Protect sensible data',
             'help' => 'Sensitive data, the 2FA secrets and emails, are stored encrypted in database. Be sure to backup the APP_KEY value of your .env file (or the whole file) as it serves as key encryption. There is no way to decypher encrypted data without this key.',
         ],
+        'default_group' => [
+            'label' => 'Default group',
+            'help' => 'The group to which the newly created accounts are associated',
+        ],
         'never' => 'Never',
         'on_token_copy' => 'On security code copy',
         '1_minutes' => 'After 1 minute',