diff --git a/atst/forms/ccpo_user.py b/atst/forms/ccpo_user.py new file mode 100644 index 00000000..3ef23257 --- /dev/null +++ b/atst/forms/ccpo_user.py @@ -0,0 +1,13 @@ +from flask_wtf import FlaskForm +from wtforms.validators import Required, Length +from wtforms.fields import StringField + +from atst.forms.validators import IsNumber +from atst.utils.localization import translate + + +class CCPOUserForm(FlaskForm): + dod_id = StringField( + translate("forms.new_member.dod_id_label"), + validators=[Required(), Length(min=10), IsNumber()], + ) diff --git a/atst/routes/__init__.py b/atst/routes/__init__.py index 7860eb74..f0e05aec 100644 --- a/atst/routes/__init__.py +++ b/atst/routes/__init__.py @@ -21,8 +21,10 @@ from atst.domain.authnid import AuthenticationContext from atst.domain.audit_log import AuditLog from atst.domain.auth import logout as _logout from atst.domain.common import Paginator +from atst.domain.exceptions import NotFoundError from atst.domain.portfolios import Portfolios from atst.domain.authz.decorator import user_can_access_decorator as user_can +from atst.forms.ccpo_user import CCPOUserForm from atst.models.permissions import Permissions from atst.utils.context_processors import atat as atat_context_processor from atst.utils.flash import formatted_flash as flash @@ -141,6 +143,35 @@ def ccpo_users(): return render_template("ccpo/users.html", users=users) +@bp.route("/ccpo-users/new") +@user_can(Permissions.CREATE_CCPO_USER, message="create ccpo user") +def add_new_ccpo_user(): + form = CCPOUserForm() + return render_template("ccpo/add_user.html", form=form) + + +@bp.route("/ccpo-users/new", methods=["POST"]) +@user_can(Permissions.CREATE_CCPO_USER, message="create ccpo user") +def submit_add_new_ccpo_user(): + try: + new_user = Users.get_by_dod_id(request.form['dod_id']) + form = CCPOUserForm(obj=new_user) + except NotFoundError: + new_user = None + form = CCPOUserForm() + + return render_template("ccpo/confirm_user.html", new_user=new_user, form=form) + + +@bp.route("/ccpo-users/confirm-new", methods=["POST"]) +@user_can(Permissions.CREATE_CCPO_USER, message="create ccpo user") +def confirm_new_ccpo_user(): + new_user = Users.get_by_dod_id(request.form['dod_id']) + # give new perms here + # flash w/ success message + return redirect(url_for("atst.ccpo_users")) + + @bp.route("/about") def about(): return render_template("about.html") diff --git a/templates/ccpo/add_user.html b/templates/ccpo/add_user.html new file mode 100644 index 00000000..5647e144 --- /dev/null +++ b/templates/ccpo/add_user.html @@ -0,0 +1,27 @@ +{% extends "base.html" %} + +{% from "components/text_input.html" import TextInput %} + +{% block content %} + {% set ccpo_user_form = "add-ccpo-user-form" %} + +
+{% endblock %} diff --git a/templates/ccpo/confirm_user.html b/templates/ccpo/confirm_user.html new file mode 100644 index 00000000..eae94fec --- /dev/null +++ b/templates/ccpo/confirm_user.html @@ -0,0 +1,35 @@ +{% extends "base.html" %} + +{% from "components/alert.html" import Alert %} +{% from "components/text_input.html" import TextInput %} + +{% block content %} + {% set ccpo_user_form = "add-ccpo-user-form" %} + + {% call Alert('Confirm new CCPO user') %} + + + {% endcall %} +{% endblock %} diff --git a/templates/ccpo/users.html b/templates/ccpo/users.html index 7a9bd4bc..df2b7324 100644 --- a/templates/ccpo/users.html +++ b/templates/ccpo/users.html @@ -28,7 +28,7 @@ {% if user_can(permissions.CREATE_CCPO_USER) %} - + Add new CCPO user {{ Icon("plus") }} {% endif %}