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

密码即将过期邮件提醒 #117

Closed
Xmandon opened this issue Oct 25, 2021 · 7 comments
Closed

密码即将过期邮件提醒 #117

Xmandon opened this issue Oct 25, 2021 · 7 comments
Assignees
Labels
Layer: saas SaaS module related Sign: feature requested New feature request

Comments

@Xmandon
Copy link
Collaborator

Xmandon commented Oct 25, 2021

No description provided.

@Xmandon Xmandon added Sign: feature requested New feature request Layer: saas SaaS module related labels Oct 25, 2021
@Xmandon Xmandon added this to the 202110H2 milestone Oct 25, 2021
@IMBlues IMBlues modified the milestones: 202110H2, 202111H1, 202111H2 Nov 8, 2021
@Xmandon Xmandon modified the milestones: 202111H2, Y2021M45-46 Nov 8, 2021
@Xmandon Xmandon removed this from the Y2021M45-46 milestone Nov 23, 2021
@Xmandon Xmandon mentioned this issue Jan 5, 2022
15 tasks
@Xmandon Xmandon added this to the Y2022M07-M08 milestone Feb 14, 2022
@Canway-shiisa
Copy link
Contributor

Canway-shiisa commented Feb 22, 2022

配置部分

  1. 增加namespace为notification的本地目录配置
  • api/user_settings/constant 默认用户目录增加类型为notification的配置
  1. 初始化本地目录通知配置
  • 增加对应的migration
  1. 增加<通知配置>查询接口
请求地址

/api/v2/categories/<int: category_id>/settings/namespaces/notification/

请求方法

GET

响应
{
    "result": true,
    "code": 0,
    "message": "success",
    "data": [
        {
            "key": "expired_sms_config",
            "value": {
                "sender": "蓝鲸智云企业版",
                "content": "【蓝鲸智云企业版】密码到期提醒!{username}您好!您的蓝鲸智云企业版平台密码已过期,为避免影响使用,请尽快登陆平台({url})修改密码。"
            },
            "namespace": "notification",
            "region": "default",
            "enabled": true
        },
        {
            "key": "be_about_to_expire_sms_config",
            "value": {
                "sender": "蓝鲸智云企业版",
                "content": "【蓝鲸智云企业版】密码到期提醒!{username},您好,您的蓝鲸平台密码将于{expire_at}天后到期,为避免影响使用,请尽快登陆平台({url})修改密码。"
            },
            "namespace": "notification",
            "region": "default",
            "enabled": true
        },
        {
            "key": "expired_email_config",
            "value": {
                "title": "【蓝鲸智云企业版】密码到期提醒",
                "sender": "蓝鲸智云企业版",
                "content": "{username},您好!您的蓝鲸智云企业版平台密码已过期,为避免影响使用,请尽快登陆平台({url})修改密码。蓝鲸智云平台用户管理处"
            },
            "namespace": "notification",
            "region": "default",
            "enabled": true
        },
        {
            "key": "be_about_to_expire_email_config",
            "value": {
                "title": "【蓝鲸智云企业版】密码到期提醒",
                "sender": "蓝鲸智云企业版",
                "content": "{username},您好!您的蓝鲸智云企业版平台密码将于{expire_at}天后到期,为避免影响使用,请尽快登陆平台({url})修改密码。蓝鲸智云平台用户管理处"
            },
            "namespace": "notification",
            "region": "default",
            "enabled": true
        },
        {
            "key": "notice_time",
            "value": [
                1,
                7,
                15
            ],
            "namespace": "notification",
            "region": "default",
            "enabled": true
        },
        {
            "key": "notice_method",
            "value": [
                "send_email",
                "send_sms"
            ],
            "namespace": "notification",
            "region": "default",
            "enabled": true
        }
    ]
}
  1. 增加<通知配置>修改接口
请求地址

/api/v2/categories/<int: category_id>/settings/namespaces/notification/

请求方法

PUT

请求参数
[
    {
        "key": "notice_method",
        "value": "[send_sms]",
        "region": "default"
    },
    {
        "key": "notice_time",
        "value": [
            3,
            5,
            7
        ],
        "region": "default"
    },
    {
        "key": "be_about_to_expire_email_config",
        "value": {
            "title": "【蓝鲸智云企业版】密码到期提醒",
            "sender": "蓝鲸智云企业版",
            "content": "{username},您好yya!您的蓝鲸智云企业版平台密码将于{expire_at}天后到期,为避免影响使用,请尽快登陆平台({url})修改密码。蓝鲸智云平台用户管理处"
        },
        "region": "default"
    },
    {
        "key": "expired_email_config",
        "value": {
            "title": "【蓝鲸智云企业版】密码到期提醒",
            "sender": "蓝鲸智云企业版",
            "content": "{username},您好!您的蓝鲸智云企业版平台密码已过期,为避免影响使用,请尽快登陆平台({url})修改密码。蓝鲸智云平台用户管理处"
        },
        "region": "default"
    },
    {
        "key": "be_about_to_expire_sms_config",
        "value": {
            "sender": "蓝鲸智云企业版",
            "content": "【蓝鲸智云企业版】密码到期提醒!{username},您好,您的蓝鲸平台密码将于{expire_at}天后到期,为避免影响使用,请尽快登陆平台({url})修改密码。"
        },
        "region": "default"
    },
    {
        "key": "expired_sms_config",
        "value": {
            "sender": "蓝鲸智云企业版",
            "content": "【蓝鲸智云企业版】密码到期提醒!{username}您好!您的蓝鲸智云企业版平台密码已过期,为避免影响使用,请尽快登陆平台({url})修改密码。"
        },
        "region": "default"
    }
]
响应
{
    "result": true,
    "code": 0,
    "message": "success",
    "data": [
        {
            "key": "notice_method",
            "value": "[send_sms]",
            "namespace": "notification",
            "region": "default",
            "enabled": true
        },
        {
            "key": "notice_time",
            "value": [
                3,
                5,
                7
            ],
            "namespace": "notification",
            "region": "default",
            "enabled": true
        },
        {
            "key": "be_about_to_expire_email_config",
            "value": {
                "title": "【蓝鲸智云企业版】密码到期提醒",
                "sender": "蓝鲸智云企业版",
                "content": "{username},您好yya!您的蓝鲸智云企业版平台密码将于{expire_at}天后到期,为避免影响使用,请尽快登陆平台({url})修改密码。蓝鲸智云平台用户管理处"
            },
            "namespace": "notification",
            "region": "default",
            "enabled": true
        },
        {
            "key": "expired_email_config",
            "value": {
                "title": "【蓝鲸智云企业版】密码到期提醒",
                "sender": "蓝鲸智云企业版",
                "content": "{username},您好!您的蓝鲸智云企业版平台密码已过期,为避免影响使用,请尽快登陆平台({url})修改密码。蓝鲸智云平台用户管理处"
            },
            "namespace": "notification",
            "region": "default",
            "enabled": true
        },
        {
            "key": "be_about_to_expire_sms_config",
            "value": {
                "sender": "蓝鲸智云企业版",
                "content": "【蓝鲸智云企业版】密码到期提醒!{username},您好,您的蓝鲸平台密码将于{expire_at}天后到期,为避免影响使用,请尽快登陆平台({url})修改密码。"
            },
            "namespace": "notification",
            "region": "default",
            "enabled": true
        },
        {
            "key": "expired_sms_config",
            "value": {
                "sender": "蓝鲸智云企业版",
                "content": "【蓝鲸智云企业版】密码到期提醒!{username}您好!您的蓝鲸智云企业版平台密码已过期,为避免影响使用,请尽快登陆平台({url})修改密码。"
            },
            "namespace": "notification",
            "region": "default",
            "enabled": true
        }
    ]
}

通知部分

思路:

  • 在bkuser_core/profiles/tasks下设置周期扫描任务,按天来扫描用户密码状态,如果用户密码已过期,给用户发送通知;如果距离密码过期的天数与用户目录通知配置中的过期前通知时间一致,给用户发送通知
  1. 定义周期任务
@periodic_task(run_every=48000)
def notice_for_password_expiration():
    category_id = ProfileCategory.objects.filter(type=CategoryType.LOCAL.value).id
    # 获取本地目录下所有 password_valid_days>0 的所有用户
    local_profiles = Profile.objects.filter(category_id=category_id, password_valid_days__gt=0)

    for profile in local_profiles:
        Notification(profile=profile).handler()
  1. 定义类Notification

    2.1 接收1,2中的profile , config_loader参数进行数据初始化

 class Notification:

    def __init__(self, config_loader, profile):
        self.config_loader = config_loader
        self.profile = profile
        self.url = settings.LOGIN_REDIRECT_TO

​ 2.2 Notification类中定义handler方法,根据用户目录配置的通知方法,执行Notification类下定义的通知方法

  def handler(self):
        notice_method_map = {
            "send_email": self._notice_by_email,
            "send_sms": self._notice_by_sms,
        }

        for notice_method in self.config_loader["notice_methods"]:
            notice_method_map[notice_method]()

​ 2.3 Notification类中定义_notice_by_email方法,实现邮件通知用户

    def _notice_by_email(self):
        # 判断用户密码为过期状态还是处于通知配置中的有效期
        if 密码过期:
        	email_config=xxx
        if 密码有效期 in config_loader["notice_time"]:
            email_config=yyy
            
        send_mail(
            sender=email_config["sender"],
            receivers=[self.profile.email],
            message=message,
            title=email_config["title"],
        )

2.4 Notification类中定义_notice_by_sms方法,实现使用短信通知用户

 def _notice_by_sms(self):
        # 判断用户密码为过期状态还是处于通知配置中的有效期

        if 密码过期:
            sms_config=xxx
        if 密码有效期 in config_loader["notice_time"]:
            sms_config=yyy

        send_sms(
            sender=sms_config["sender"],
            receivers=[self.profile.telephone],
            message=message
        )
  • 需要在bkuser_core/common/nofiter.py中增加封装send_sms逻辑

@IMBlues
Copy link
Contributor

IMBlues commented Feb 28, 2022

密码过期这里,我感觉需要评估一下,我们是否需要有一些防御机制:

  • 对于通知的频率限制,大批量的发送可能会耗尽通知资源
  • 有没有可能一些不使用蓝鲸的领导,由于信息被导入,会被过期密码机制扫到,发送干扰的短信,引起一些不必要的麻烦

@abbyWJM
Copy link

abbyWJM commented Apr 11, 2022

密码过期需求调整如下:
1、 消息推送增加配置条件:默认勾选“从未登录蓝鲸平台用户不发送密码到期提醒通知”,即账号从创建到密码过期从未登录过的账号不发送消息。如果取消勾选,则只要账号的密码过期,就发消息。
2、 每个账号每次密码过期只发送一次提醒通知。
3、 密码过期用户登录平台,过期提示与中增加“去修改”的快捷入口,点击跳转至修改密码页面。

@abbyWJM
Copy link

abbyWJM commented Apr 11, 2022

用户管理消息通知整合:
1、对调获取初始密码2种方式的位置,默认方式改为“发送随机密码”,可通过邮件或短信发送消息,默认选择邮件。
2、点击“编辑消息模板”展开编辑弹窗,可定义邮件发送方式为“邮件”还是“短信”,可两者都勾选,但至少选择1项。最后一项不可取消勾选。
3、可切换邮件或短信tab修改对应的模板信息,修改完成后,可点击“编辑消息模板”收起弹窗。
4、密码到期通知设置调整至自动冻结设置下方位置。
5、增加“从未登录蓝鲸平台用户不发送密码到期提醒通知”配置项,默认勾选。勾选后,密码即将到期提醒和密码已过期提醒通知将不发送至从未登录蓝鲸平台用户。
原型:https://jqda6w.axshare.com

@Canway-jessonwang
Copy link
Contributor

【排期】
开发方案:20220415-20220418
开发:20220418-20220420

@wklken
Copy link
Collaborator

wklken commented Oct 9, 2022

确认是否可以关闭

@Canway-shiisa
Copy link
Contributor

确认是否可以关闭

对应需求代码已经合入,可以关闭

@wklken wklken closed this as completed Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Layer: saas SaaS module related Sign: feature requested New feature request
Projects
None yet
Development

No branches or pull requests

7 participants