Skip to content

Commit

Permalink
Remove unnecessary fields from Register an App form BB2-2660 (#1203)
Browse files Browse the repository at this point in the history
* Remove unnecessary fields from Register an App form BB2-2660

* Assign the default values for hidden fields BB2-2660

* Cleaned up the code BB2-2660

* Cleaned up the code BB2-2660

* Fixed Unit test cases and cleaned  BB2-2660

* Fixed Unit test cases and cleaned  BB2-2660

* Removed Blank Lines BB2-2660

---------

Co-authored-by: Dulla <62860@icfx40cq046tf.hsd1.md.comcast.net>
Co-authored-by: MuraliKrishna Dulla <muralikrishna.dulla@icf.com>
  • Loading branch information
3 people authored Jun 20, 2024
1 parent f495561 commit 2b86b4f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 54 deletions.
27 changes: 4 additions & 23 deletions apps/dot_ext/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def __init__(self, user, *args, **kwargs):
self.fields["name"].label = "Name*"
self.fields["name"].required = True
self.fields["client_type"].label = "Client Type*"
self.fields["client_type"].required = False
self.fields["authorization_grant_type"].label = "Authorization Grant Type*"
self.fields["authorization_grant_type"].required = False
self.fields["redirect_uris"].label = "Redirect URIs*"
self.fields["logo_uri"].disabled = True

Expand All @@ -86,29 +88,6 @@ class Meta:
required_css_class = "required"

def clean(self):
client_type = self.cleaned_data.get("client_type")
authorization_grant_type = self.cleaned_data.get("authorization_grant_type")

msg = ""
validate_error = False

# Validate choices
if not (
client_type == "confidential"
and authorization_grant_type == "authorization-code"
):
validate_error = True
msg += (
"Only a confidential client and "
"authorization-code grant type are allowed at this time."
)

if validate_error:
msg_output = _(msg)
raise forms.ValidationError(msg_output)
else:
pass

return self.cleaned_data

def clean_name(self):
Expand Down Expand Up @@ -176,6 +155,8 @@ def clean_require_demographic_scopes(self):
return require_demographic_scopes

def save(self, *args, **kwargs):
self.instance.client_type = "confidential"
self.instance.authorization_grant_type = "authorization-code"
app = self.instance
# Only log agreement from a Register form
if app.agree and type(self) == CustomRegisterApplicationForm:
Expand Down
27 changes: 0 additions & 27 deletions apps/dot_ext/tests/test_form_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,33 +258,6 @@ def test_update_form_edit(self):
form = CustomRegisterApplicationForm(user, passing_app_fields)
self.assertTrue(form.is_valid())

# Test client_type = 'confidential' and authorization_grant_type = 'implicit' not allowed.
data = passing_app_fields
data['client_type'] = 'confidential'
data['authorization_grant_type'] = 'implicit'
form = CustomRegisterApplicationForm(user, data)
self.assertFalse(form.is_valid())
self.assertIn('Only a confidential client and authorization-code grant type are allowed at this time.',
str(form.errors.get('__all__')))

# Test client_type = 'public' and grant_type = 'authorization-code' not allowed.
data = passing_app_fields
data['client_type'] = 'public'
data['authorization_grant_type'] = 'authorization-code'
form = CustomRegisterApplicationForm(user, data)
self.assertFalse(form.is_valid())
self.assertIn('Only a confidential client and authorization-code grant type are allowed at this time.',
str(form.errors.get('__all__')))

# Test client_type = 'public' and grant_type = 'implicit' not allowed.
data = passing_app_fields
data['client_type'] = 'public'
data['authorization_grant_type'] = 'implicit'
form = CustomRegisterApplicationForm(user, data)
self.assertFalse(form.is_valid())
self.assertIn('Only a confidential client and authorization-code grant type are allowed at this time.',
str(form.errors.get('__all__')))

def test_create_applications_with_logo(self):
"""
regression test: BB2-66: Fix-logo-display-in-Published-Applications-API
Expand Down
8 changes: 4 additions & 4 deletions templates/include/app-form-required-info.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ <h2>App Details - Required Info</h2>
<input type="text" name="name" maxlength="255" required="" id="id_name" value="{{ application.name }}" autocomplete="turn_autocomplete_off">

<!-- App Client Type -->
<label for="id_client_type">OAuth - Client Type</label>
<!-- <label for="id_client_type">OAuth - Client Type</label>
<select name="client_type" required="" id="id_client_type">
<option value="confidential" {% if application.client_type != "public" %} selected {% endif %}>Confidential</option>
</select>
</select> -->

<!-- App Grant Type -->
<label for="id_authorization_grant_type">Authorization Grant Type*</label>
<!-- <label for="id_authorization_grant_type">Authorization Grant Type*</label>
<select name="authorization_grant_type" id="id_authorization_grant_type">
<option value="authorization-code" {% if application.authorization_grant_type != "implicit" %} selected {% endif %}>Authorization code</option>
</select>
</select> -->

<!-- App Redirect URIs -->
<label for="id_redirect_uris">Callback URLs / Redirect URIs</label>
Expand Down

0 comments on commit 2b86b4f

Please sign in to comment.