From 6d65c1a174d05c8c40226ce242add6188e772739 Mon Sep 17 00:00:00 2001 From: Steve Harrigan Date: Mon, 20 Jan 2020 14:22:55 -0500 Subject: [PATCH 1/3] open config modal on enable for storage->file sharing->samba Add check to open the config modal if needed when enabling samba from the dedicated samba page. This now matches the other dedicated pages (such as Rock-Ons) to require the configuration the first time. --- .../static/storageadmin/js/views/samba.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/rockstor/storageadmin/static/storageadmin/js/views/samba.js b/src/rockstor/storageadmin/static/storageadmin/js/views/samba.js index 0313c2598..9bb26f891 100644 --- a/src/rockstor/storageadmin/static/storageadmin/js/views/samba.js +++ b/src/rockstor/storageadmin/static/storageadmin/js/views/samba.js @@ -104,10 +104,16 @@ SambaView = RockstorLayoutView.extend({ }, switchStatus: function(event, state) { - if (state) { - this.startService(); + if (!this.service.get('config')) { + app_router.navigate('services/smb/edit', { + trigger: true, + }); } else { - this.stopService(); + if (state) { + this.startService(); + } else { + this.stopService(); + } } }, @@ -214,4 +220,4 @@ SambaView = RockstorLayoutView.extend({ return new Handlebars.SafeString(html); }); } -}); \ No newline at end of file +}); From 91454586cd2edbfdc83340b508812c0c7da4b0fc Mon Sep 17 00:00:00 2001 From: Steve Harrigan Date: Tue, 21 Jan 2020 08:03:22 -0500 Subject: [PATCH 2/3] change default return value of get_global_config for samba When working with Samba, if you navigate to the dedicated page for it, we internally save the result of get_global_config in the model. This then causes subsequent checks to open the configuration modal to fail, since it's expecting null rather than an empty dictionary. This change simply uses the default of None, and then swaps to a dictionary as needed. --- src/rockstor/system/samba.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/rockstor/system/samba.py b/src/rockstor/system/samba.py index 362901573..884438759 100644 --- a/src/rockstor/system/samba.py +++ b/src/rockstor/system/samba.py @@ -74,7 +74,7 @@ def rockstor_smb_config(fo, exports): fo.write(' veto files = /.%s*/\n' % e.snapshot_prefix) for cco in SambaCustomConfig.objects.filter(smb_share=e): if (cco.custom_config.strip()): - fo.write(' %s\n' % cco.custom_config) + fo.write(' %s\n' % cco.custom_config) fo.write('%s\n' % RS_SHARES_FOOTER) @@ -180,7 +180,9 @@ def update_global_config(smb_config=None, ad_config=None): def get_global_config(): - config = {} + # start with config as None so it will return null elsewhere + # if no fields are added to it. + config = None with open(SMB_CONFIG) as sfo: global_section = False global_custom_section = False @@ -201,9 +203,9 @@ def get_global_config(): # we ignore lines outside [global], empty lines, or # commends(starting with # or ;) if ((not global_section or - not global_custom_section or - len(l.strip()) == 0 or - re.match('#', l) is not None or + not global_custom_section or + len(l.strip()) == 0 or + re.match('#', l) is not None or re.match(';', l) is not None)): continue if (global_section and re.match('\[', l) is not None): @@ -212,7 +214,13 @@ def get_global_config(): fields = l.strip().split(' = ') if len(fields) < 2: continue + # reset config to a usable dictionary since we're about to add + # something to it + if(config is None): + config = {} config[fields[0].strip()] = fields[1].strip() + # return our config variable, which is either None, or a dictionary with + # fields inside of it return config From ddb875a4f081824b75679edd407ce6b2d523fcb4 Mon Sep 17 00:00:00 2001 From: Steve Harrigan Date: Mon, 10 Feb 2020 06:42:17 -0500 Subject: [PATCH 3/3] skip conversion of config to json string when it is none to allow saving a proper null to the database If you use json.dumps() on None in python, it returns the string 'null'. Saving this to the database saves that actual string, instead of the type NULL. This change makes it easier to determine if a service is in its default unconfigured state. --- src/rockstor/smart_manager/views/base_service.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rockstor/smart_manager/views/base_service.py b/src/rockstor/smart_manager/views/base_service.py index cb899baaa..1c208ba99 100644 --- a/src/rockstor/smart_manager/views/base_service.py +++ b/src/rockstor/smart_manager/views/base_service.py @@ -33,7 +33,10 @@ class ServiceMixin(object): def _save_config(self, service, config): - service.config = json.dumps(config) + if config is not None: + service.config = json.dumps(config) + else: + service.config = None return service.save() def _get_config(self, service):