Repository: fossasia/open-event-server

Issue:
Add client_key for Stripe in public schema & Make AdminSchema inherit Non Admin Schema
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->
Right now the Stripe client_key requires admin access. Moreover there is a lot of common code between the NonAdmin and Admin Schema. 

**To Reproduce**
Steps to reproduce the behavior:
1. Check in the docs.

**Expected behavior**
It shouldn't require admin access. Also the AdminSchema should inherit from the Non-Admin schema.

**Parent issue**
#4796 

Working!


Discussion:

Resolving patch:
diff --git a/app/api/schema/settings.py b/app/api/schema/settings.py
--- a/app/api/schema/settings.py
+++ b/app/api/schema/settings.py
@@ -6,8 +6,72 @@
 from utils.common import use_defaults
 
 
+class SettingSchemaPublic(Schema):
+    """
+    Public Api schema for settings Model
+    """
+    class Meta:
+        """
+        Meta class for setting Api Schema
+        """
+        type_ = 'setting'
+        self_view = 'v1.setting_detail'
+        self_view_kwargs = {'id': '<id>'}
+        inflect = dasherize
+
+    id = fields.Str(dump_only=True)
+
+    # Name of the application. (Eg. Event Yay!, Open Event)
+    app_name = fields.Str(allow_none=True)
+
+    # Tagline for the application. (Eg. Event Management and Ticketing, Home)
+    tagline = fields.Str(allow_none=True)
+
+    # Google Analytics
+    analytics_key = fields.Str(allow_none=True)
+
+    #
+    # Social links
+    #
+    google_url = fields.Str(allow_none=True)
+    github_url = fields.Str(allow_none=True)
+    twitter_url = fields.Str(allow_none=True)
+    support_url = fields.Str(allow_none=True)
+    facebook_url = fields.Str(allow_none=True)
+    youtube_url = fields.Str(allow_none=True)
+
+    # Url of Frontend
+    frontend_url = fields.Url(allow_none=True)
+
+
+class SettingSchemaNonAdmin(SettingSchemaPublic):
+    """
+    Non Admin Api schema for settings Model
+    """
+    class Meta:
+        """
+        Meta class for setting Api Schema
+        """
+        type_ = 'setting'
+        self_view = 'v1.setting_detail'
+        self_view_kwargs = {'id': '<id>'}
+        inflect = dasherize
+
+    id = fields.Str(dump_only=True)
+
+    # Stripe Keys
+    stripe_client_id = fields.Str(allow_none=True)
+    stripe_publishable_key = fields.Str(allow_none=True)
+
+    #
+    # Generators
+    #
+    android_app_url = fields.Str(allow_none=True)
+    web_app_url = fields.Str(allow_none=True)
+
+
 @use_defaults()
-class SettingSchemaAdmin(Schema):
+class SettingSchemaAdmin(SettingSchemaNonAdmin):
     """
     Admin Api schema for settings Model
     """
@@ -26,10 +90,7 @@ class Meta:
     #
 
     app_environment = fields.Str(default=Environment.PRODUCTION)
-    # Name of the application. (Eg. Event Yay!, Open Event)
-    app_name = fields.Str(allow_none=True)
-    # Tagline for the application. (Eg. Event Management and Ticketing, Home)
-    tagline = fields.Str(allow_none=True)
+
     # App secret
     secret = fields.Str(allow_none=True)
     # Static domain
@@ -72,10 +133,9 @@ class Meta:
     # Payment Gateway
     #
 
-    # Stripe Keys
-    stripe_client_id = fields.Str(allow_none=True)
+    # Stripe secret key
     stripe_secret_key = fields.Str(allow_none=True)
-    stripe_publishable_key = fields.Str(allow_none=True)
+
     # PayPal Credentials
     paypal_mode = fields.Str(allow_none=True)
     paypal_sandbox_username = fields.Str(allow_none=True)
@@ -101,68 +161,3 @@ class Meta:
     smtp_password = fields.Str(allow_none=True)
     smtp_port = fields.Integer(allow_none=True)
     smtp_encryption = fields.Str(allow_none=True)  # Can be tls, ssl, none
-    # Google Analytics
-    analytics_key = fields.Str(allow_none=True)
-
-    #
-    # Social links
-    #
-    google_url = fields.Str(allow_none=True)
-    github_url = fields.Str(allow_none=True)
-    twitter_url = fields.Str(allow_none=True)
-    support_url = fields.Str(allow_none=True)
-    facebook_url = fields.Str(allow_none=True)
-    youtube_url = fields.Str(allow_none=True)
-
-    #
-    # Generators
-    #
-    android_app_url = fields.Str(allow_none=True)
-    web_app_url = fields.Str(allow_none=True)
-
-    # Url of Frontend
-    frontend_url = fields.Url(allow_none=True)
-
-
-class SettingSchemaNonAdmin(Schema):
-    """
-    Non Admin Api schema for settings Model
-    """
-    class Meta:
-        """
-        Meta class for setting Api Schema
-        """
-        type_ = 'setting'
-        self_view = 'v1.setting_detail'
-        self_view_kwargs = {'id': '<id>'}
-        inflect = dasherize
-
-    id = fields.Str(dump_only=True)
-
-    # Name of the application. (Eg. Event Yay!, Open Event)
-    app_name = fields.Str(allow_none=True)
-    # Tagline for the application. (Eg. Event Management and Ticketing, Home)
-    tagline = fields.Str(allow_none=True)
-    # Google Analytics
-    analytics_key = fields.Str(allow_none=True)
-
-    stripe_publishable_key = fields.Str(allow_none=True)
-
-    #
-    # Social links
-    #
-    google_url = fields.Str(allow_none=True)
-    github_url = fields.Str(allow_none=True)
-    twitter_url = fields.Str(allow_none=True)
-    support_url = fields.Str(allow_none=True)
-    facebook_url = fields.Str(allow_none=True)
-    youtube_url = fields.Str(allow_none=True)
-
-    #
-    # Generators
-    #
-    android_app_url = fields.Str(allow_none=True)
-    web_app_url = fields.Str(allow_none=True)
-
-    # Url of Frontend
-    frontend_url = fields.Url(allow_none=True)
diff --git a/app/api/settings.py b/app/api/settings.py
--- a/app/api/settings.py
+++ b/app/api/settings.py
@@ -4,7 +4,7 @@
 from flask_rest_jsonapi import ResourceDetail
 
 from app.api.bootstrap import api
-from app.api.schema.settings import SettingSchemaAdmin, SettingSchemaNonAdmin
+from app.api.schema.settings import SettingSchemaAdmin, SettingSchemaNonAdmin, SettingSchemaPublic
 from app.models import db
 from app.models.setting import Setting
 
@@ -36,7 +36,7 @@ def before_get(self, args, kwargs):
             else:
                 self.schema = SettingSchemaNonAdmin
         else:
-            self.schema = SettingSchemaNonAdmin
+            self.schema = SettingSchemaPublic
 
     decorators = (api.has_permission('is_admin', methods="PATCH", id="1"),)
     methods = ['GET', 'PATCH']


Test patch: