forked from Gitlink/forgeplus-react
Merge branch 'feature_bot' of http://106.75.45.236:3000/durian/forgeplus-react into gitlink_server
This commit is contained in:
commit
2462355415
|
|
@ -1,5 +1,5 @@
|
|||
import React from "react";
|
||||
import { Button, Checkbox, Form, Input, message, Select } from "antd";
|
||||
import { Button, Checkbox, Form, Input, message, Select, Row, Col } from "antd";
|
||||
import { useState } from "react";
|
||||
import '../../new/index.scss';
|
||||
import './index.scss';
|
||||
|
|
@ -13,12 +13,14 @@ function Jurisdiction(props){
|
|||
const resource = [{value: 2, name: '无权限'}, {value: 0, name: '只读'}, {value: 1, name: '读写'}];
|
||||
const [codeSelectValue , setCodeSelectValue ] = useState(undefined);
|
||||
const [prSelectValue , setPrSelectValue ] = useState(undefined);
|
||||
const [ issueSelectValue , setIssueSelectValue ] = useState(undefined);
|
||||
|
||||
useEffect(()=>{
|
||||
if(botDetail){
|
||||
const {limit_and_events:{juris_diction_code, juris_diction_pr}} = botDetail
|
||||
const {limit_and_events:{juris_diction_code, juris_diction_pr, juris_diction_issue}} = botDetail
|
||||
setCodeSelectValue(juris_diction_code);
|
||||
setPrSelectValue(juris_diction_pr);
|
||||
setIssueSelectValue(juris_diction_issue);
|
||||
}
|
||||
}, [botDetail])
|
||||
|
||||
|
|
@ -32,6 +34,11 @@ function Jurisdiction(props){
|
|||
return e;
|
||||
}
|
||||
|
||||
function issueControl(e){
|
||||
setIssueSelectValue(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
// 修改注册bot的权限
|
||||
function submit(e){
|
||||
e.preventDefault();
|
||||
|
|
@ -39,15 +46,17 @@ function Jurisdiction(props){
|
|||
if(err){
|
||||
return;
|
||||
}
|
||||
const {juris_diction_code, juris_diction_pr, event_code, event_pr} = fieldsValue;
|
||||
const {juris_diction_code, juris_diction_pr, event_code, event_pr, event_issue, juris_diction_issue} = fieldsValue;
|
||||
const params = {
|
||||
...botDetail,
|
||||
bot_id: parseInt(id),
|
||||
limit_and_events: {
|
||||
event_code: event_code ? event_code.toString() : "",
|
||||
event_pr: event_pr ? event_pr.toString() : "",
|
||||
event_code: event_code ? event_code.toString() : '',
|
||||
event_pr: event_pr ? event_pr.toString() : '',
|
||||
event_issue: event_issue ? event_issue.toString(): '',
|
||||
juris_diction_code,
|
||||
juris_diction_pr
|
||||
juris_diction_pr,
|
||||
juris_diction_issue
|
||||
},
|
||||
user_id: current_user && current_user.user_id,
|
||||
}
|
||||
|
|
@ -64,8 +73,8 @@ function Jurisdiction(props){
|
|||
|
||||
// 校验仓库访问权限
|
||||
function jurisDictionPrValidator(rule, value, callback){
|
||||
const {juris_diction_code} = getFieldsValue();
|
||||
if(juris_diction_code === 2 && value === 2){
|
||||
const {juris_diction_code, juris_diction_pr} = getFieldsValue();
|
||||
if(juris_diction_code === 2 && value === 2 && juris_diction_pr === 2){
|
||||
callback('请至少选择一个权限');
|
||||
return;
|
||||
}
|
||||
|
|
@ -73,21 +82,13 @@ function Jurisdiction(props){
|
|||
}
|
||||
|
||||
// 校验用户必选一个订阅事件
|
||||
function eventValidator(rule, value, callback, type){
|
||||
const {event_code, event_pr} = getFieldsValue();
|
||||
const resourceValue = resource[0].value;
|
||||
const boolPr = (event_code === undefined || (event_code && event_code.length === 0)) && prSelectValue === resourceValue;
|
||||
const boolCode = (event_pr === undefined || (event_pr && event_pr.length === 0)) && codeSelectValue === resourceValue;
|
||||
const bool = prSelectValue !== resourceValue && codeSelectValue !== resourceValue && (event_pr === undefined || (event_pr && event_pr.length === 0)) && (event_code === undefined || (event_code && event_code.length === 0))
|
||||
if(boolPr || boolCode){
|
||||
callback("请至少选择一个订阅");
|
||||
return;
|
||||
function eventValidator(rule, value, callback){
|
||||
const {event_code, event_pr, event_issue} = getFieldsValue();
|
||||
if(event_code || event_pr || event_issue){
|
||||
callback();
|
||||
}else{
|
||||
callback("请至少选择一个订阅事件");
|
||||
}
|
||||
if(bool && type === "pr"){
|
||||
callback("请至少选择一个订阅");
|
||||
return;
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
return <Form className="createExploitForm jurisdictionBox" onSubmit={submit}>
|
||||
|
|
@ -104,7 +105,16 @@ function Jurisdiction(props){
|
|||
<div className="dashedBor"></div>
|
||||
<Form.Item label="合并请求(PR)权限" className="resourceBox botItem">
|
||||
<div className="color-99">合并请求的打开、关闭、编辑、分配</div>
|
||||
{getFieldDecorator("juris_diction_pr",{rules:[{validator: jurisDictionPrValidator}],initialValue: botDetail.limit_and_events.juris_diction_pr, getValueFromEvent: prControl})(
|
||||
{getFieldDecorator("juris_diction_pr",{initialValue: botDetail.limit_and_events.juris_diction_pr, getValueFromEvent: prControl})(
|
||||
<Select>
|
||||
{resource.map(item=>{return <Option value={item.value} key={item.value}>{item.name}</Option>})}
|
||||
</Select>
|
||||
)}
|
||||
</Form.Item>
|
||||
<div className="dashedBor"></div>
|
||||
<Form.Item label="疑修(Issue)权限" className="resourceBox botItem">
|
||||
<div className="color-99">疑修的打开、关闭、编辑、分配、评论</div>
|
||||
{getFieldDecorator("juris_diction_issue",{rules:[{validator: jurisDictionPrValidator}],initialValue: resource[0].value, getValueFromEvent: issueControl})(
|
||||
<Select>
|
||||
{resource.map(item=>{return <Option value={item.value} key={item.value}>{item.name}</Option>})}
|
||||
</Select>
|
||||
|
|
@ -114,12 +124,14 @@ function Jurisdiction(props){
|
|||
{codeSelectValue !== resource[0].value && <Form.Item label="代码库事件" className="botItem width50 checkBox three dashedBorder">
|
||||
{getFieldDecorator("event_code", {
|
||||
initialValue: botDetail.limit_and_events.event_code ? botDetail.limit_and_events.event_code.split(',').map(item=>item = parseInt(item)) : [],
|
||||
rules:[{validator: (rule, value, callback)=>{eventValidator(rule, value, callback, "code")}}]
|
||||
rules:[{validator: (rule, value, callback)=>{eventValidator(rule, value, callback)}}]
|
||||
})(
|
||||
<Checkbox.Group>
|
||||
<Checkbox value={0}>推送<br/><span className="color-99">git推送到存储库</span></Checkbox>
|
||||
<Checkbox value={1}>创建<br/><span className="color-99">创建分支或标签</span></Checkbox>
|
||||
<Checkbox value={2}>删除<br/><span className="color-99">删除分支或标签</span></Checkbox>
|
||||
<Row>
|
||||
<Col span={16}><Checkbox value={0}>推送<br/><span className="color-99">git推送到存储库</span></Checkbox></Col>
|
||||
<Col span={8}><Checkbox value={1}>创建<br/><span className="color-99">创建分支或标签</span></Checkbox></Col>
|
||||
<Col span={16}><Checkbox value={2}>删除<br/><span className="color-99">删除分支或标签</span></Checkbox></Col>
|
||||
</Row>
|
||||
</Checkbox.Group>
|
||||
)}
|
||||
</Form.Item>}
|
||||
|
|
@ -127,11 +139,29 @@ function Jurisdiction(props){
|
|||
{prSelectValue !== resource[0].value && <Form.Item label="合并请求事件" className="botItem width50 checkBox">
|
||||
{getFieldDecorator("event_pr", {
|
||||
initialValue: botDetail.limit_and_events.event_pr ? botDetail.limit_and_events.event_pr.split(',').map(item=>item = parseInt(item)) : [],
|
||||
rules:[{validator: (rule, value, callback)=>{eventValidator(rule, value, callback, "pr")}}]
|
||||
rules:[{validator: (rule, value, callback)=>{eventValidator(rule, value, callback)}}]
|
||||
})(
|
||||
<Checkbox.Group>
|
||||
<Checkbox value={3}>合并请求<br/><span className="color-99">合并请求被打开、被关闭、被重新打开或被编辑</span></Checkbox>
|
||||
<Checkbox value={4}>合并请求分配<br/><span className="color-99">合并请求被分配或取消分配</span></Checkbox>
|
||||
<Row>
|
||||
<Col span={16}><Checkbox value={3}>合并请求<br/><span className="color-99">合并请求被打开、被关闭、被重新打开或被编辑</span></Checkbox></Col>
|
||||
<Col span={8}><Checkbox value={4}>合并请求分配<br/><span className="color-99">合并请求被分配或取消分配</span></Checkbox></Col>
|
||||
<Col span={16}><Checkbox value={6}>合并请求被评论<br/><span className="color-99">合并请求评论被创建、编辑或删除</span></Checkbox></Col>
|
||||
</Row>
|
||||
</Checkbox.Group>
|
||||
)}
|
||||
</Form.Item>}
|
||||
{(codeSelectValue !== resource[0].value || prSelectValue !== resource[0].value) && issueSelectValue !== resource[0].value && <div className="dashedBor"></div>}
|
||||
{issueSelectValue !== resource[0].value && <Form.Item label="疑修事件" className="botItem width50 checkBox three">
|
||||
{getFieldDecorator("event_issue",{
|
||||
rules:[{validator: (rule, value, callback)=>{eventValidator(rule, value, callback)}}]
|
||||
})(
|
||||
<Checkbox.Group>
|
||||
<Row>
|
||||
<Col span={16}><Checkbox value={7}>疑修<br/><span className="color-99">疑修已打开、已关闭、已重新打开或编辑</span></Checkbox></Col>
|
||||
<Col span={8}><Checkbox value={8}>疑修已指派<br/><span className="color-99">疑修已被指派或取消指派</span></Checkbox></Col>
|
||||
<Col span={16}><Checkbox value={9}>已标记疑修<br/><span className="color-99">疑修标记被更新或清除</span></Checkbox></Col>
|
||||
<Col span={8}><Checkbox value={10}>疑修评论<br/><span className="color-99">疑修评论被创建、编辑或删除</span></Checkbox></Col>
|
||||
</Row>
|
||||
</Checkbox.Group>
|
||||
)}
|
||||
</Form.Item>}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import React, { forwardRef, useState, useEffect } from "react";
|
||||
import { Button, Checkbox, Form, Input, message, Radio, Select } from "antd";
|
||||
import { Button, Checkbox, Col, Form, Input, message, Radio, Row, Select } from "antd";
|
||||
import { Link } from "react-router-dom";
|
||||
import MDEditor from '../../../../../modules/tpm/challengesnew/tpm-md-editor';
|
||||
import './index.scss';
|
||||
|
|
@ -14,7 +14,8 @@ function Disposition(props){
|
|||
const [ content , setContent ] = useState(undefined);
|
||||
const [ codeSelectValue , setCodeSelectValue ] = useState(resource[0].value);
|
||||
const [ prSelectValue , setPrSelectValue ] = useState(resource[0].value);
|
||||
|
||||
const [ issueSelectValue , setIssueSelectValue ] = useState(resource[0].value);
|
||||
|
||||
useEffect(()=>{
|
||||
document.title='注册新的Bot';
|
||||
}, [])
|
||||
|
|
@ -33,6 +34,11 @@ function Disposition(props){
|
|||
return e;
|
||||
}
|
||||
|
||||
function issueControl(e){
|
||||
setIssueSelectValue(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
// webhooks校验
|
||||
function checkAddr(rule, value, callback) {
|
||||
let reg = /(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
|
||||
|
|
@ -47,8 +53,8 @@ function Disposition(props){
|
|||
|
||||
// 校验仓库访问权限
|
||||
function jurisDictionPrValidator(rule, value, callback){
|
||||
const {juris_diction_code} = getFieldsValue();
|
||||
if(juris_diction_code === 2 && value === 2){
|
||||
const {juris_diction_code, juris_diction_pr} = getFieldsValue();
|
||||
if(juris_diction_code === 2 && value === 2 && juris_diction_pr === 2){
|
||||
callback('请至少选择一个权限');
|
||||
return;
|
||||
}
|
||||
|
|
@ -56,21 +62,13 @@ function Disposition(props){
|
|||
}
|
||||
|
||||
// 校验用户必选一个订阅事件
|
||||
function eventValidator(rule, value, callback, type){
|
||||
const {event_code, event_pr} = getFieldsValue();
|
||||
const resourceValue = resource[0].value;
|
||||
const boolPr = (event_code === undefined || (event_code && event_code.length === 0)) && prSelectValue === resourceValue;
|
||||
const boolCode = (event_pr === undefined || (event_pr && event_pr.length === 0)) && codeSelectValue === resourceValue;
|
||||
const bool = prSelectValue !== resourceValue && codeSelectValue !== resourceValue && (event_pr === undefined || (event_pr && event_pr.length === 0)) && (event_code === undefined || (event_code && event_code.length === 0))
|
||||
if(boolPr || boolCode){
|
||||
callback("请至少选择一个订阅");
|
||||
return;
|
||||
function eventValidator(rule, value, callback){
|
||||
const {event_code, event_pr, event_issue} = getFieldsValue();
|
||||
if(event_code || event_pr || event_issue){
|
||||
callback();
|
||||
}else{
|
||||
callback("请至少选择一个订阅事件");
|
||||
}
|
||||
if(bool && type === "pr"){
|
||||
callback("请至少选择一个订阅");
|
||||
return;
|
||||
}
|
||||
callback();
|
||||
}
|
||||
|
||||
// 注册新的bot
|
||||
|
|
@ -80,17 +78,19 @@ function Disposition(props){
|
|||
if(err){
|
||||
return;
|
||||
}
|
||||
const {bot_name, bot_des, webhook, is_public, juris_diction_code, juris_diction_pr, event_code, event_pr, oauth_callback_url} = fieldsValue;
|
||||
const {bot_name, bot_des, webhook, is_public, juris_diction_code, juris_diction_pr, event_code, event_pr, oauth_callback_url, event_issue, juris_diction_issue} = fieldsValue;
|
||||
const param = {
|
||||
bot_name, bot_des, webhook, is_public,
|
||||
login: current_user && current_user.login,
|
||||
user_id: current_user && current_user.user_id,
|
||||
logo: `/api/attachments/${window.location.host !== 'www.gitlink.org.cn' ? 347246 : 412603}`,
|
||||
limit_and_events: {
|
||||
event_code: event_code ? event_code.toString() : "",
|
||||
event_pr: event_pr ? event_pr.toString() : "",
|
||||
event_code: event_code ? event_code.toString() : '',
|
||||
event_pr: event_pr ? event_pr.toString() : '',
|
||||
event_issue: event_issue ? event_issue.toString(): '',
|
||||
juris_diction_code,
|
||||
juris_diction_pr
|
||||
juris_diction_pr,
|
||||
juris_diction_issue
|
||||
},
|
||||
oauth_callback_url
|
||||
}
|
||||
|
|
@ -157,32 +157,61 @@ function Disposition(props){
|
|||
<div className="dashedBor"></div>
|
||||
<Form.Item label="合并请求(PR)权限" className="resourceBox botItem">
|
||||
<div className="color-99">合并请求的打开、关闭、编辑、分配</div>
|
||||
{getFieldDecorator("juris_diction_pr",{rules:[{validator: jurisDictionPrValidator}],initialValue: resource[0].value, getValueFromEvent: prControl})(
|
||||
{getFieldDecorator("juris_diction_pr",{initialValue: resource[0].value, getValueFromEvent: prControl})(
|
||||
<Select>
|
||||
{resource.map(item=>{return <Option value={item.value} key={item.value}>{item.name}</Option>})}
|
||||
</Select>
|
||||
)}
|
||||
</Form.Item>
|
||||
<div className="dashedBor"></div>
|
||||
<Form.Item label="疑修(Issue)权限" className="resourceBox botItem">
|
||||
<div className="color-99">疑修的打开、关闭、编辑、分配、评论</div>
|
||||
{getFieldDecorator("juris_diction_issue",{rules:[{validator: jurisDictionPrValidator}],initialValue: resource[0].value, getValueFromEvent: issueControl})(
|
||||
<Select>
|
||||
{resource.map(item=>{return <Option value={item.value} key={item.value}>{item.name}</Option>})}
|
||||
</Select>
|
||||
)}
|
||||
</Form.Item>
|
||||
{(codeSelectValue !== resource[0].value || prSelectValue !== resource[0].value) && <div className="resourceTitle font-16 pb15 mb10">订阅事件</div>}
|
||||
{codeSelectValue !== resource[0].value && <Form.Item label="代码库事件" className="botItem width50 checkBox three dashedBorder">
|
||||
{codeSelectValue !== resource[0].value && <Form.Item label="代码库事件" className="botItem width50 checkBox dashedBorder">
|
||||
{getFieldDecorator("event_code",{
|
||||
rules:[{validator: (rule, value, callback)=>{eventValidator(rule, value, callback, "code")}}]
|
||||
rules:[{validator: (rule, value, callback)=>{eventValidator(rule, value, callback)}}]
|
||||
})(
|
||||
<Checkbox.Group>
|
||||
<Checkbox value={0}>推送<br/><span className="color-99">git推送到存储库</span></Checkbox>
|
||||
<Checkbox value={1}>创建<br/><span className="color-99">创建分支或标签</span></Checkbox>
|
||||
<Checkbox value={2}>删除<br/><span className="color-99">删除分支或标签</span></Checkbox>
|
||||
<Row>
|
||||
<Col span={16}><Checkbox value={0}>推送<br/><span className="color-99">git推送到存储库</span></Checkbox></Col>
|
||||
<Col span={8}><Checkbox value={1}>创建<br/><span className="color-99">创建分支或标签</span></Checkbox></Col>
|
||||
<Col span={16}><Checkbox value={2}>删除<br/><span className="color-99">删除分支或标签</span></Checkbox></Col>
|
||||
</Row>
|
||||
</Checkbox.Group>
|
||||
)}
|
||||
</Form.Item>}
|
||||
{(codeSelectValue !== resource[0].value && prSelectValue !== resource[0].value) && <div className="dashedBor"></div>}
|
||||
{prSelectValue !== resource[0].value && <Form.Item label="合并请求事件" className="botItem width50 checkBox">
|
||||
{getFieldDecorator("event_pr",{
|
||||
rules:[{validator: (rule, value, callback)=>{eventValidator(rule, value, callback, "pr")}}]
|
||||
rules:[{validator: (rule, value, callback)=>{eventValidator(rule, value, callback)}}]
|
||||
})(
|
||||
<Checkbox.Group>
|
||||
<Checkbox value={3}>合并请求<br/><span className="color-99">合并请求被打开、被关闭、被重新打开或被编辑</span></Checkbox>
|
||||
<Checkbox value={4}>合并请求分配<br/><span className="color-99">合并请求被分配或取消分配</span></Checkbox>
|
||||
<Row>
|
||||
<Col span={16}><Checkbox value={3}>合并请求<br/><span className="color-99">合并请求被打开、被关闭、被重新打开或被编辑</span></Checkbox></Col>
|
||||
<Col span={8}><Checkbox value={4}>合并请求分配<br/><span className="color-99">合并请求被分配或取消分配</span></Checkbox></Col>
|
||||
<Col span={16}><Checkbox value={6}>合并请求被评论<br/><span className="color-99">合并请求评论被创建、编辑或删除</span></Checkbox></Col>
|
||||
</Row>
|
||||
</Checkbox.Group>
|
||||
)}
|
||||
</Form.Item>}
|
||||
{(codeSelectValue !== resource[0].value || prSelectValue !== resource[0].value) && issueSelectValue !== resource[0].value && <div className="dashedBor"></div>}
|
||||
{issueSelectValue !== resource[0].value && <Form.Item label="疑修事件" className="botItem width50 checkBox">
|
||||
{getFieldDecorator("event_issue",{
|
||||
rules:[{validator: (rule, value, callback)=>{eventValidator(rule, value, callback)}}]
|
||||
})(
|
||||
<Checkbox.Group>
|
||||
<Row>
|
||||
<Col span={16}><Checkbox value={7}>疑修<br/><span className="color-99">疑修已打开、已关闭、已重新打开或编辑</span></Checkbox></Col>
|
||||
<Col span={8}><Checkbox value={8}>疑修已指派<br/><span className="color-99">疑修已被指派或取消指派</span></Checkbox></Col>
|
||||
<Col span={16}><Checkbox value={9}>已标记疑修<br/><span className="color-99">疑修标记被更新或清除</span></Checkbox></Col>
|
||||
<Col span={8}><Checkbox value={10}>疑修评论<br/><span className="color-99">疑修评论被创建、编辑或删除</span></Checkbox></Col>
|
||||
</Row>
|
||||
</Checkbox.Group>
|
||||
)}
|
||||
</Form.Item>}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
.width50{
|
||||
width: 60%;
|
||||
&.checkBox{
|
||||
width: 68%;
|
||||
width: 75%;
|
||||
}
|
||||
.height36{
|
||||
height: 36px;
|
||||
|
|
@ -50,23 +50,15 @@
|
|||
margin-bottom: 0;
|
||||
}
|
||||
&.checkBox .ant-checkbox-group{
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
.ant-row{width: 100%;}
|
||||
.color-99{padding-left: 24px;}
|
||||
}
|
||||
&.three .ant-checkbox-wrapper{
|
||||
width: 34%;
|
||||
margin-left: 0px;
|
||||
padding-left: 12px;
|
||||
&:first-child, &:last-child{
|
||||
padding-left: 0px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.dashedBor{
|
||||
border-bottom: 1px dashed #e0e6f5;
|
||||
margin-bottom: 12px;
|
||||
margin-top: -20px;
|
||||
}
|
||||
.resourceBox + .dashedBor{
|
||||
margin-top: -15px;
|
||||
|
|
|
|||
Loading…
Reference in New Issue