Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imprv: Allow registering without GROWI email settings for ID/Password authentication's restricted registration #7591

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
70d566a
delete need complete mail setting warning
Apr 11, 2023
e7681cb
create register limitation please enable mailer
Apr 11, 2023
37ba018
Merge branch 'imprv/119788-mail-setting-and-id-password-login-specifi…
Apr 13, 2023
198d4d9
update position and add next link
Apr 13, 2023
cad70dc
clean code
Apr 13, 2023
00be311
is password reset enalbed default value to false
Apr 13, 2023
67943c8
add disabled attr
Apr 13, 2023
c9e3d2c
update for fb
Apr 14, 2023
97bec6c
Merge branch 'imprv/119788-mail-setting-and-id-password-login-specifi…
Apr 14, 2023
8c1ad2a
Merge branch 'imprv/119788-mail-setting-and-id-password-login-specifi…
Apr 16, 2023
da14de9
get server side props is mailer setup
Apr 16, 2023
deda755
Merge pull request #7561 from weseek/imprv/119788-119796-delete-id-pa…
Apr 16, 2023
74c5ab5
fix i18n
Apr 18, 2023
de70456
add activity
Apr 18, 2023
4051093
update login js for allow registration request without mail setting
Apr 18, 2023
da64dfd
create component for user model notification
Apr 18, 2023
5df2d80
Merge branch 'master' into imprv/119788-mail-setting-and-id-password-…
Apr 18, 2023
81bed99
Merge branch 'imprv/119788-mail-setting-and-id-password-login-specifi…
Apr 18, 2023
4b0e837
avoid lint error by use any type
Apr 19, 2023
33452f6
use supported targe model
Apr 19, 2023
37809e6
Merge branch 'master' into imprv/119788-mail-setting-and-id-password-…
Apr 20, 2023
c3a5202
Merge branch 'imprv/119788-mail-setting-and-id-password-login-specifi…
Apr 20, 2023
3284c1f
Merge pull request #7581 from weseek/imprv/119788-120045-can-use-sing…
yuki-takei Apr 20, 2023
898725b
Merge branch 'master' into imprv/119788-mail-setting-and-id-password-…
Apr 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/app/public/static/locales/en_US/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@
"password_reset_desc": "when forgot password, users are able to reset it by themselves.",
"email_authentication": "Email authentication on user registration",
"enable_email_authentication": "Enable email authentication",
"enable_email_authentication_desc": "Email authentication is going to be performed for user registration.",
"need_complete_mail_setting_warning": "To use the following functions, please complete the mail settings."
"enable_email_authentication_desc": "Email authentication is going to be performed for user registration."
},
"ldap": {
"enable_ldap": "Enable LDAP",
Expand Down
3 changes: 2 additions & 1 deletion apps/app/public/static/locales/en_US/commons.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
},
"alert": {
"siteUrl_is_not_set": "'Site URL' is NOT set. Set it from the {{link}}",
"please_enable_mailer": "Please setup mailer first."
"please_enable_mailer": "Please setup mailer first.",
"password_reset_please_enable_mailer": "Please setup mailer first."
},
"headers": {
"app_settings": "App Settings"
Expand Down
5 changes: 3 additions & 2 deletions apps/app/public/static/locales/en_US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@
"login": {
"title": "Login",
"sign_in_error": "Login error",
"registration_successful": "registration_successful. Please wait for administrator approval.",
"registration_successful": "Registration successful. Please wait for administrator approval.",
"Setup": "Setup",
"enabled_ldap_has_configuration_problem":"LDAP is enabled but the configuration has something wrong.",
"set_env_var_for_logs": "(Please set the environment variables <code>DEBUG=crowi:service:PassportService</code> to get the logs)"
Expand Down Expand Up @@ -659,7 +659,8 @@
"success_to_send_email": "Success to send email",
"feature_is_unavailable": "This feature is unavailable.",
"incorrect_token_or_expired_url": "The token is incorrect or the URL has expired. Please resend a password reset request via the link below.",
"password_and_confirm_password_does_not_match": "Password and confirm password does not match"
"password_and_confirm_password_does_not_match": "Password and confirm password does not match",
"please_enable_mailer_alert": "The password reset feature is disabled because email setup has not been completed. Please ask administrator to complete the email setup."
},
"emoji" :{
"title": "Pick an Emoji",
Expand Down
3 changes: 1 addition & 2 deletions apps/app/public/static/locales/ja_JP/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@
"password_reset_desc": "ログイン時のパスワードを忘れた際に、ユーザー自身がパスワードを再設定できます。",
"email_authentication": "ユーザー登録時のメール認証",
"enable_email_authentication": "メール認証を有効にする",
"enable_email_authentication_desc": "ユーザー登録時にメール認証を行います。",
"need_complete_mail_setting_warning": "以下の機能を使えるようにするには、メール設定を完了させてください。"
"enable_email_authentication_desc": "ユーザー登録時にメール認証を行います。"
},
"ldap": {
"enable_ldap": "LDAP を有効にする",
Expand Down
3 changes: 2 additions & 1 deletion apps/app/public/static/locales/ja_JP/commons.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
},
"alert": {
"siteUrl_is_not_set": "'サイトURL' が設定されていません。{{link}} から設定してください。",
"please_enable_mailer": "メール認証を有効にするには、メール設定を完了させてください。"
"please_enable_mailer": "メール認証を有効にするには、メール設定を完了させてください。",
"password_reset_please_enable_mailer": "パスワード再設定を有効にするには、メール設定を完了させてください。"
},
"headers": {
"app_settings": "アプリ設定"
Expand Down
3 changes: 2 additions & 1 deletion apps/app/public/static/locales/ja_JP/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,8 @@
"success_to_send_email": "メールを送信しました",
"feature_is_unavailable": "この機能を利用することはできません。",
"incorrect_token_or_expired_url":"トークンが正しくないか、URLの有効期限が切れています。 以下のリンクからパスワードリセットリクエストを再送信してください。",
"password_and_confirm_password_does_not_match": "パスワードと確認パスワードが一致しません"
"password_and_confirm_password_does_not_match": "パスワードと確認パスワードが一致しません",
"please_enable_mailer_alert": "メール設定が完了していないため、パスワード再設定機能が無効になっています。メール設定を完了させるよう管理者に依頼してください。"
},
"emoji" :{
"title": "絵文字を選択",
Expand Down
3 changes: 1 addition & 2 deletions apps/app/public/static/locales/zh_CN/admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@
"password_reset_desc": "忘记密码时,用户可以自行重置",
"email_authentication": "用户注册时的电子邮件身份验证",
"enable_email_authentication": "启用电子邮件身份验证",
"enable_email_authentication_desc": "用户注册将执行电子邮件身份验证。",
"need_complete_mail_setting_warning": "要使用以下功能,请完成邮件设置。"
"enable_email_authentication_desc": "用户注册将执行电子邮件身份验证。"
},
"ldap": {
"enable_ldap": "Enable LDAP",
Expand Down
3 changes: 2 additions & 1 deletion apps/app/public/static/locales/zh_CN/commons.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
},
"alert": {
"siteUrl_is_not_set": "主页URL未设置,通过 {{link}} 设置",
"please_enable_mailer": "请先设置邮件程序。"
"please_enable_mailer": "请先设置邮件程序。",
"password_reset_please_enable_mailer": "请先设置邮件程序。"
},
"headers": {
"app_settings": "系统设置"
Expand Down
3 changes: 2 additions & 1 deletion apps/app/public/static/locales/zh_CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,8 @@
"success_to_send_email": "我发了一封电子邮件",
"feature_is_unavailable": "此功能不可用",
"incorrect_token_or_expired_url":"令牌不正确或 URL 已过期。 请通过以下链接重新发送密码重置请求",
"password_and_confirm_password_does_not_match": "密码和确认密码不匹配"
"password_and_confirm_password_does_not_match": "密码和确认密码不匹配",
"please_enable_mailer_alert": "密码重置功能被禁用,因为电子邮件设置尚未完成。请要求管理员完成电子邮件的设置。"
},
"emoji" :{
"title": "选择一个表情符号",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';

import { useTranslation } from 'next-i18next';
import Link from 'next/link';
import PropTypes from 'prop-types';


import AdminGeneralSecurityContainer from '~/client/services/AdminGeneralSecurityContainer';
import AdminLocalSecurityContainer from '~/client/services/AdminLocalSecurityContainer';
import { toastSuccess, toastError } from '~/client/util/toastr';
Expand Down Expand Up @@ -52,17 +52,6 @@ class LocalSecuritySettingContents extends React.Component {
)}
<h2 className="alert-anchor border-bottom">{t('security_settings.Local.name')}</h2>

{!isMailerSetup && (
<div className="row">
<div className="col-12">
<div className="alert alert-danger">
<span>{t('security_settings.Local.need_complete_mail_setting_warning')}</span>
<a href="/admin/app#mail-settings"> <i className="fa fa-link"></i> {t('admin:app_setting.mail_settings')}</a>
</div>
</div>
</div>
)}

{adminLocalSecurityContainer.state.useOnlyEnvVars && (
<p
className="alert alert-info"
Expand Down Expand Up @@ -146,7 +135,6 @@ class LocalSecuritySettingContents extends React.Component {
</button>
</div>
</div>

<p className="form-text text-muted small">{t('security_settings.register_limitation_desc')}</p>
</div>
</div>
Expand Down Expand Up @@ -189,6 +177,14 @@ class LocalSecuritySettingContents extends React.Component {
{t('security_settings.Local.enable_password_reset_by_users')}
</label>
</div>
{!isMailerSetup && (
<div className="alert alert-warning p-1 my-1 small d-inline-block">
<span>{t('commons:alert.password_reset_please_enable_mailer')}</span>
<Link href="/admin/app#mail-settings">
<i className="fa fa-link"></i> {t('app_setting.mail_settings')}
</Link>
</div>
)}
<p className="form-text text-muted small">
{t('security_settings.Local.password_reset_desc')}
</p>
Expand All @@ -213,7 +209,9 @@ class LocalSecuritySettingContents extends React.Component {
{!isMailerSetup && (
<div className="alert alert-warning p-1 my-1 small d-inline-block">
<span>{t('commons:alert.please_enable_mailer')}</span>
<a href="/admin/app#mail-settings"> <i className="fa fa-link"></i> {t('app_setting.mail_settings')}</a>
<Link href="/admin/app#mail-settings">
<i className="fa fa-link"></i> {t('app_setting.mail_settings')}
</Link>
</div>
)}
<p className="form-text text-muted small">
Expand Down
23 changes: 20 additions & 3 deletions apps/app/src/components/InAppNotification/InAppNotificationElm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import { DropdownItem } from 'reactstrap';

import { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
import { apiv3Post } from '~/client/util/apiv3-client';
import { SupportedTargetModel } from '~/interfaces/activity';
import { IInAppNotification, InAppNotificationStatuses } from '~/interfaces/in-app-notification';

// Change the display for each targetmodel
import PageModelNotification from './PageNotification/PageModelNotification';

import UserModelNotification from './PageNotification/UserModelNotification';

interface Props {
notification: IInAppNotification & HasObjectId
Expand Down Expand Up @@ -40,6 +41,10 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
};

const getActionUsers = () => {
if (notification.targetModel === SupportedTargetModel.MODEL_USER) {
return notification.target.username;
}

const latestActionUsers = notification.actionUsers.slice(0, 3);
const latestUsers = latestActionUsers.map((user) => {
return `@${user.name}`;
Expand Down Expand Up @@ -75,7 +80,6 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
<div className="position-absolute" style={{ top: 10, left: 10 }}>
<UserPicture user={actionUsers[1]} size="md" noTooltip />
</div>

</div>
);
};
Expand Down Expand Up @@ -139,6 +143,10 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
actionMsg = 'commented on';
actionIcon = 'icon-bubble';
break;
case 'USER_REGISTRATION_APPROVAL_REQUEST':
actionMsg = 'requested registration approval';
actionIcon = 'icon-bubble';
break;
default:
actionMsg = '';
actionIcon = '';
Expand All @@ -163,7 +171,7 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
>
</span>
{renderActionUserPictures()}
{notification.targetModel === 'Page' && (
{notification.targetModel === SupportedTargetModel.MODEL_PAGE && (
<PageModelNotification
ref={notificationRef}
notification={notification}
Expand All @@ -172,6 +180,15 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
actionUsers={actionUsers}
/>
)}
{notification.targetModel === SupportedTargetModel.MODEL_USER && (
<UserModelNotification
ref={notificationRef}
notification={notification}
actionMsg={actionMsg}
actionIcon={actionIcon}
actionUsers={actionUsers}
/>
)}
</div>
</TagElem>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, {
forwardRef, ForwardRefRenderFunction, useImperativeHandle,
} from 'react';

import { HasObjectId } from '@growi/core';
import { useRouter } from 'next/router';

import type { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
import type { IInAppNotification } from '~/interfaces/in-app-notification';

import FormattedDistanceDate from '../../FormattedDistanceDate';

const UserModelNotification: ForwardRefRenderFunction<IInAppNotificationOpenable, {
notification: IInAppNotification & HasObjectId
actionMsg: string
actionIcon: string
actionUsers: string
}> = ({
notification, actionMsg, actionIcon, actionUsers,
}, ref) => {
const router = useRouter();

// publish open()
useImperativeHandle(ref, () => ({
open() {
router.push('/admin/users');
},
}));

return (
<div className="p-2 overflow-hidden">
<div className="text-truncate">
<b>{actionUsers}</b> {actionMsg}
</div>
<i className={`${actionIcon} mr-2`} />
<FormattedDistanceDate
id={notification._id}
date={notification.createdAt}
isShowTooltip={false}
differenceForAvoidingFormat={Number.POSITIVE_INFINITY}
/>
</div>
);
};

export default forwardRef(UserModelNotification);
47 changes: 33 additions & 14 deletions apps/app/src/components/PasswordResetRequestForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import Link from 'next/link';

import { apiv3Post } from '~/client/util/apiv3-client';
import { toastSuccess, toastError } from '~/client/util/toastr';

import { useIsMailerSetup } from '~/stores/context';

const PasswordResetRequestForm: FC = () => {
const { t } = useTranslation();
const { data: isMailerSetup } = useIsMailerSetup();
const [email, setEmail] = useState('');

const changeEmail = useCallback((inputValue) => {
Expand All @@ -33,20 +34,38 @@ const PasswordResetRequestForm: FC = () => {

return (
<form onSubmit={sendPasswordResetRequestMail}>
<h3>{ t('forgot_password.password_reset_request_desc') }</h3>
<div className="form-group">
<div className="input-group">
<input name="email" placeholder="E-mail Address" className="form-control" type="email" onChange={e => changeEmail(e.target.value)} />
{!isMailerSetup ? (
<div className="alert alert-danger">
{t('forgot_password.please_enable_mailer_alert')}
</div>
</div>
<div className="form-group">
<button
className="btn btn-lg btn-primary btn-block"
type="submit"
>
{t('forgot_password.send')}
</button>
</div>
) : (
<>
<h1><i className="icon-lock large"></i></h1>
<h1 className="text-center">{ t('forgot_password.forgot_password') }</h1>
<h3>{t('forgot_password.password_reset_request_desc')}</h3>
<div className="form-group">
<div className="input-group">
<input
name="email"
placeholder="E-mail Address"
className="form-control"
type="email"
disabled={!isMailerSetup}
onChange={e => changeEmail(e.target.value)}
/>
</div>
</div>
<div className="form-group">
<button
className="btn btn-lg btn-primary btn-block"
type="submit"
disabled={!isMailerSetup}
>
{t('forgot_password.send')}
</button>
</div>
</>
)}
<Link href='/login' prefetch={false}>
<i className="icon-login mr-1" />{t('forgot_password.return_to_login')}
</Link>
Expand Down
6 changes: 6 additions & 0 deletions apps/app/src/interfaces/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import { IUser } from './user';

// Model
const MODEL_PAGE = 'Page';
const MODEL_USER = 'User';
const MODEL_COMMENT = 'Comment';

// Action
const ACTION_UNSETTLED = 'UNSETTLED';
const ACTION_USER_REGISTRATION_APPROVAL_REQUEST = 'USER_REGISTRATION_APPROVAL_REQUEST';
const ACTION_USER_REGISTRATION_SUCCESS = 'USER_REGISTRATION_SUCCESS';
const ACTION_USER_LOGIN_WITH_LOCAL = 'USER_LOGIN_WITH_LOCAL';
const ACTION_USER_LOGIN_WITH_LDAP = 'USER_LOGIN_WITH_LDAP';
Expand Down Expand Up @@ -162,6 +164,7 @@ const ACTION_ADMIN_SEARCH_INDICES_REBUILD = 'ADMIN_SEARCH_INDICES_REBUILD';

export const SupportedTargetModel = {
MODEL_PAGE,
MODEL_USER,
} as const;

export const SupportedEventModel = {
Expand All @@ -182,6 +185,7 @@ export const SupportedActionCategory = {

export const SupportedAction = {
ACTION_UNSETTLED,
ACTION_USER_REGISTRATION_APPROVAL_REQUEST,
ACTION_USER_REGISTRATION_SUCCESS,
ACTION_USER_LOGIN_WITH_LOCAL,
ACTION_USER_LOGIN_WITH_LDAP,
Expand Down Expand Up @@ -349,6 +353,7 @@ export const EssentialActionGroup = {
ACTION_PAGE_RECURSIVELY_DELETE_COMPLETELY,
ACTION_PAGE_RECURSIVELY_REVERT,
ACTION_COMMENT_CREATE,
ACTION_USER_REGISTRATION_APPROVAL_REQUEST,
} as const;

export const ActionGroupSize = {
Expand All @@ -375,6 +380,7 @@ export const SmallActionGroup = {
// SmallActionGroup + Action by all General Users - PAGE_VIEW
export const MediumActionGroup = {
...SmallActionGroup,
ACTION_USER_REGISTRATION_APPROVAL_REQUEST,
ACTION_USER_REGISTRATION_SUCCESS,
ACTION_USER_FOGOT_PASSWORD,
ACTION_USER_RESET_PASSWORD,
Expand Down