view src/nabble/view/naml/rest_group_control.naml @ 0:7ecd1a4ef557

add content
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 21 Mar 2019 19:15:52 -0600
parents
children
line wrap: on
line source

<!--
Add/Remove users to/from groups.
http://<site-domain>/template/NamlServlet.jtp?macro=rest_group_control&owner=owner@example.com&password=123456&user=user@example.com&action=add&group=Members
http://<site-domain>/template/NamlServlet.jtp?macro=rest_group_control&owner=owner@example.com&password=123456&user=user@example.com&action=remove&group=Members
Sample URLs
-->
<macro name="rest_group_control" requires="servlet">
	<n.check_not_null value="[n.rest_owner_email/]" error_msg="Invalid owner email."/>
	<n.check_not_null value="[n.rest_owner_password_hash/]" error_msg="Invalid password hash."/>
	<n.check_not_null value="[n.rest_user_email/]" error_msg="Invalid user email."/>
	<n.check_not_null value="[n.rest_action/]" error_msg="Missing action."/>
	<n.check_not_null value="[n.rest_group/]" error_msg="Missing group name."/>

	<n.catch_exception. id="save-block">
		<n.if.check_registered_user email="[n.rest_owner_email/]" password_hash="[n.rest_owner_password_hash/]">
			<then>
				<n.if.regex_matches text="[n.rest_action/]" pattern="add|remove">
					<then>
						<n.get_or_create_user. email="[n.rest_owner_email/]">
							<n.as_user_page.>
								<n.edit_page_user.>
									<n.if.equal value1="[n.rest_action/]" value2="add">
										<then><n.add_to_group.rest_group/></then>
										<else><n.remove_from_group.rest_group/></else>
									</n.if.equal>
								</n.edit_page_user.>
								Success.
							</n.as_user_page.>
						</n.get_or_create_user.>
					</then>
					<else>
						Actions should be "add" or "remove".
					</else>
				</n.if.regex_matches>
			</then>
			<else>Invalid owner email and password.</else>
		</n.if.check_registered_user>
	</n.catch_exception.>
</macro>

<macro name="check_not_null" parameters="value,error_msg">
	<n.if.is_null.value>
		<then>
			<n.error_msg/>
			<n.exit/>
		</then>
	</n.if.is_null.value>
</macro>

<macro name="rest_owner_email">
	<n.get_parameter name="owner"/>
</macro>

<macro name="rest_owner_password_hash">
	<n.get_parameter name="password"/>
</macro>

<macro name="rest_action">
	<n.get_parameter name="action"/>
</macro>

<macro name="rest_group">
	<n.get_parameter name="group"/>
</macro>

<macro name="rest_user_email">
	<n.get_parameter name="user"/>
</macro>