merge conflicts
This commit is contained in:
commit
8cf576946b
|
@ -37,13 +37,11 @@ public/react/yarn.lock
|
||||||
|
|
||||||
# Ignore react node_modules
|
# Ignore react node_modules
|
||||||
public/system/*
|
public/system/*
|
||||||
public/react/*
|
|
||||||
/public/react/.cache
|
/public/react/.cache
|
||||||
/public/react/node_modules/
|
/public/react/node_modules/
|
||||||
/public/react/config/stats.json
|
/public/react/config/stats.json
|
||||||
/public/react/stats.json
|
/public/react/stats.json
|
||||||
/public/react/.idea/*
|
/public/react/.idea/*
|
||||||
/public/react/build/*
|
|
||||||
/public/h5build
|
/public/h5build
|
||||||
/public/npm-debug.log
|
/public/npm-debug.log
|
||||||
|
|
||||||
|
@ -74,6 +72,7 @@ vendor/bundle/
|
||||||
/log
|
/log
|
||||||
/public/admin
|
/public/admin
|
||||||
/mysql_data
|
/mysql_data
|
||||||
|
/public/repo/
|
||||||
|
|
||||||
|
|
||||||
.generators
|
.generators
|
||||||
|
@ -85,3 +84,4 @@ redis_data/
|
||||||
Dockerfile
|
Dockerfile
|
||||||
dump.rdb
|
dump.rdb
|
||||||
.tags*
|
.tags*
|
||||||
|
ceshi_user.xlsx
|
|
@ -1,529 +0,0 @@
|
||||||
import React, {Component} from 'react';
|
|
||||||
import logo from './logo.svg';
|
|
||||||
import './App.css';
|
|
||||||
import {LocaleProvider} from 'antd'
|
|
||||||
import zhCN from 'antd/lib/locale-provider/zh_CN';
|
|
||||||
import {
|
|
||||||
BrowserRouter as Router,
|
|
||||||
Route,
|
|
||||||
Switch
|
|
||||||
} from 'react-router-dom';
|
|
||||||
import axios from 'axios';
|
|
||||||
import '@icedesign/base/dist/ICEDesignBase.css';
|
|
||||||
|
|
||||||
import '@icedesign/base/index.scss';
|
|
||||||
|
|
||||||
import LoginDialog from './modules/login/LoginDialog';
|
|
||||||
import Notcompletedysl from './modules/user/Notcompletedysl';
|
|
||||||
import Trialapplicationysl from './modules/login/Trialapplicationysl';
|
|
||||||
import Trialapplicationreview from './modules/user/Trialapplicationreview';
|
|
||||||
import Addcourses from "./modules/courses/coursesPublic/Addcourses";
|
|
||||||
import AccountProfile from"./modules/user/AccountProfile";
|
|
||||||
|
|
||||||
|
|
||||||
import Trialapplication from './modules/login/Trialapplication'
|
|
||||||
|
|
||||||
import NotFoundPage from './NotFoundPage'
|
|
||||||
|
|
||||||
import Loading from './Loading'
|
|
||||||
|
|
||||||
import Loadable from 'react-loadable';
|
|
||||||
|
|
||||||
|
|
||||||
import moment from 'moment'
|
|
||||||
|
|
||||||
import {MuiThemeProvider, createMuiTheme} from 'material-ui/styles';
|
|
||||||
|
|
||||||
// import './AppConfig'
|
|
||||||
|
|
||||||
import history from './history';
|
|
||||||
|
|
||||||
import {SnackbarHOC} from 'educoder'
|
|
||||||
import {initAxiosInterceptors} from './AppConfig'
|
|
||||||
|
|
||||||
|
|
||||||
// !!!tpi需要这个来加载css
|
|
||||||
import {TPMIndexHOC} from './modules/tpm/TPMIndexHOC';
|
|
||||||
|
|
||||||
|
|
||||||
const theme = createMuiTheme({
|
|
||||||
palette: {
|
|
||||||
primary: {
|
|
||||||
main: '#4CACFF',
|
|
||||||
contrastText: 'rgba(255, 255, 255, 0.87)'
|
|
||||||
},
|
|
||||||
secondary: {main: '#4CACFF'}, // #11cb5f This is just green.A700 as hex.
|
|
||||||
},
|
|
||||||
});
|
|
||||||
//
|
|
||||||
// const Trialapplication= Loadable({
|
|
||||||
// loader: () =>import('./modules/login/Trialapplication'),
|
|
||||||
// loading:Loading,
|
|
||||||
// })
|
|
||||||
//登入
|
|
||||||
const EducoderLogin = Loadable({
|
|
||||||
loader: () => import('./modules/login/EducoderLogin'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
const TestIndex = Loadable({
|
|
||||||
loader: () => import('./modules/test'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
const IndexWrapperComponent = Loadable({
|
|
||||||
loader: () => import('./modules/page/IndexWrapper'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
const CommentComponent = Loadable({
|
|
||||||
loader: () => import('./modules/comment/CommentContainer'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
const TestMaterialDesignComponent = Loadable({
|
|
||||||
loader: () => import('./modules/test/md/TestMaterialDesign'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
const TestCodeMirrorComponent = Loadable({
|
|
||||||
loader: () => import('./modules/test/codemirror/TestCodeMirror'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
const TestComponent = Loadable({
|
|
||||||
loader: () => import('./modules/test/TestRC'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
const TestUrlQueryComponent = Loadable({
|
|
||||||
loader: () => import('./modules/test/urlquery/TestUrlQuery'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
const TPMIndexComponent = Loadable({
|
|
||||||
loader: () => import('./modules/tpm/TPMIndex'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
const TPMShixunsIndexComponent = Loadable({
|
|
||||||
loader: () => import('./modules/tpm/shixuns/ShixunsIndex'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
//实训课程(原实训路径)
|
|
||||||
const ShixunPaths = Loadable({
|
|
||||||
loader: () => import('./modules/paths/Index'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
//在线课堂
|
|
||||||
const CoursesIndex = Loadable({
|
|
||||||
loader: () => import('./modules/courses/Index'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
const SearchPage = Loadable({
|
|
||||||
loader: () => import('./search/SearchPage'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
//教学案例
|
|
||||||
const MoopCases = Loadable({
|
|
||||||
loader: () => import('./modules/moop_cases/index'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
// 课堂讨论
|
|
||||||
// const BoardIndex = Loadable({
|
|
||||||
// loader: () => import('./modules/courses/boards/BoardIndex'),
|
|
||||||
// loading:Loading,
|
|
||||||
// })
|
|
||||||
|
|
||||||
// //课堂普通作业&分组作业
|
|
||||||
// const CoursesWorkIndex = Loadable({
|
|
||||||
// loader: () => import('./modules/courses/busyWork/Index'),
|
|
||||||
// loading:Loading,
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
|
|
||||||
// const TPMShixunchildIndexComponent = Loadable({
|
|
||||||
// loader: () => import('./modules/tpm/shixunchild/ShixunChildIndex'),
|
|
||||||
// loading: Loading,
|
|
||||||
// })
|
|
||||||
|
|
||||||
|
|
||||||
// const TPMshixunfork_listIndexComponent = Loadable({
|
|
||||||
// loader: () => import('./modules/tpm/shixunchild/Shixunfork_list'),
|
|
||||||
// loading: Loading,
|
|
||||||
// })
|
|
||||||
|
|
||||||
|
|
||||||
const ForumsIndexComponent = Loadable({
|
|
||||||
loader: () => import('./modules/forums/ForumsIndex'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
// trustie plus forum
|
|
||||||
// const TPForumsIndexComponent = Loadable({
|
|
||||||
// loader: () => import('./modules/tp-forums/TPForumsIndex'),
|
|
||||||
// loading: Loading,
|
|
||||||
// })
|
|
||||||
|
|
||||||
|
|
||||||
// const TestPageComponent = Loadable({
|
|
||||||
// loader: () => import('./modules/page/Index'),
|
|
||||||
// loading: Loading,
|
|
||||||
// })
|
|
||||||
|
|
||||||
|
|
||||||
//新建实训
|
|
||||||
const Newshixuns = Loadable({
|
|
||||||
loader: () => import('./modules/tpm/newshixuns/Newshixuns'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
//实训首页
|
|
||||||
const ShixunsHome = Loadable({
|
|
||||||
loader: () => import('./modules/home/shixunsHome'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
const CompatibilityPageLoadable = Loadable({
|
|
||||||
loader: () => import('./modules/common/CompatibilityPage'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
//403页面
|
|
||||||
const Shixunauthority = Loadable({
|
|
||||||
loader: () => import('./modules/403/Shixunauthority'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
//404页面
|
|
||||||
const Shixunnopage = Loadable({
|
|
||||||
loader: () => import('./modules/404/Shixunnopage'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
//500页面
|
|
||||||
const http500 = Loadable({
|
|
||||||
loader: () => import('./modules/500/http500'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
// 登录注册
|
|
||||||
const LoginRegisterPage = Loadable({
|
|
||||||
loader: () => import('./modules/user/LoginRegisterPage'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
const AccountPage = Loadable({
|
|
||||||
loader: () => import('./modules/user/AccountPage'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
// 个人主页
|
|
||||||
const UsersInfo = Loadable({
|
|
||||||
loader: () => import('./modules/user/usersInfo/Infos'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
// 兴趣页面
|
|
||||||
const Interestpage = Loadable({
|
|
||||||
loader: () => import('./modules/login/EducoderInteresse'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
//众包创新
|
|
||||||
const ProjectPackages=Loadable({
|
|
||||||
loader: () => import('./modules/projectPackages/ProjectPackageIndex'),
|
|
||||||
loading: Loading,
|
|
||||||
})
|
|
||||||
|
|
||||||
class App extends Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props)
|
|
||||||
// this.state = {
|
|
||||||
// isRenders:false,
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
// force an update if the URL changes
|
|
||||||
history.listen(() => {
|
|
||||||
this.forceUpdate()
|
|
||||||
const $ = window.$
|
|
||||||
// https://www.trustie.net/issues/21919 可能会有问题
|
|
||||||
$("html").animate({ scrollTop: $('html').scrollTop() - 0 })
|
|
||||||
});
|
|
||||||
|
|
||||||
initAxiosInterceptors(this.props)
|
|
||||||
|
|
||||||
//
|
|
||||||
// axios.interceptors.response.use((response) => {
|
|
||||||
// // console.log("response"+response);
|
|
||||||
// if(response!=undefined)
|
|
||||||
// // console.log("response"+response.data.statu);
|
|
||||||
// if (response&&response.data.status === 407) {
|
|
||||||
// this.setState({
|
|
||||||
// isRenders: true,
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
// return response;
|
|
||||||
// }, (error) => {
|
|
||||||
// //TODO 这里如果样式变了会出现css不加载的情况
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
//修改登录方法
|
|
||||||
Modifyloginvalue=()=>{
|
|
||||||
this.setState({
|
|
||||||
isRender:false,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
|
||||||
<LocaleProvider locale={zhCN}>
|
|
||||||
|
|
||||||
|
|
||||||
<MuiThemeProvider theme={theme}>
|
|
||||||
<LoginDialog {...this.props} {...this.state} Modifyloginvalue={()=>this.Modifyloginvalue()}></LoginDialog>
|
|
||||||
<Notcompletedysl {...this.props} {...this.state}></Notcompletedysl>
|
|
||||||
<Trialapplicationysl {...this.props} {...this.state}></Trialapplicationysl>
|
|
||||||
<Trialapplicationreview {...this.props} {...this.state}></Trialapplicationreview>
|
|
||||||
<Addcourses {...this.props} {...this.state}/>
|
|
||||||
<AccountProfile {...this.props} {...this.state}/>
|
|
||||||
{/*{*/}
|
|
||||||
{/* isRender === true?*/}
|
|
||||||
{/* <LoginDialog></LoginDialog> : ""*/}
|
|
||||||
{/*}*/}
|
|
||||||
|
|
||||||
{/*{*/}
|
|
||||||
{/* isRenders === true?*/}
|
|
||||||
{/*<Trialapplication></Trialapplication>*/}
|
|
||||||
{/*:""*/}
|
|
||||||
{/*}*/}
|
|
||||||
|
|
||||||
<Router>
|
|
||||||
<Switch>
|
|
||||||
{/*<Route path="/login" component={LoginRegisterPage}/>*/}
|
|
||||||
|
|
||||||
{/*众包创新*/}
|
|
||||||
<Route path={"/crowdsourcings"} component={ProjectPackages}/>
|
|
||||||
{/*认证*/}
|
|
||||||
<Route path="/account" component={AccountPage}/>
|
|
||||||
|
|
||||||
{/*403*/}
|
|
||||||
<Route path="/403" component={Shixunauthority}/>
|
|
||||||
|
|
||||||
<Route path="/500" component={http500}/>
|
|
||||||
|
|
||||||
{/*404*/}
|
|
||||||
<Route path="/nopage" component={Shixunnopage}/>
|
|
||||||
|
|
||||||
<Route path="/compatibility" component={CompatibilityPageLoadable}/>
|
|
||||||
<Route
|
|
||||||
path="/login" component={EducoderLogin}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path="/register" component={EducoderLogin}
|
|
||||||
/>
|
|
||||||
<Route path="/users/:username"
|
|
||||||
render={
|
|
||||||
(props) => (<UsersInfo {...this.props} {...props} {...this.state} />)
|
|
||||||
}></Route>
|
|
||||||
{/*<Route*/}
|
|
||||||
{/* path="/trialapplication" component={Trialapplication}*/}
|
|
||||||
{/*/>*/}
|
|
||||||
<Route
|
|
||||||
path="/changepassword" component={EducoderLogin}
|
|
||||||
/>
|
|
||||||
<Route
|
|
||||||
path="/interesse" component={Interestpage}
|
|
||||||
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Route path="/shixuns/new" component={Newshixuns}>
|
|
||||||
</Route>
|
|
||||||
|
|
||||||
<Route path="/tasks/:stageId" component={IndexWrapperComponent}/>
|
|
||||||
|
|
||||||
<Route path="/shixuns/:shixunId" component={TPMIndexComponent}>
|
|
||||||
</Route>
|
|
||||||
|
|
||||||
{/*列表页*/}
|
|
||||||
<Route path="/shixuns" component={TPMShixunsIndexComponent}/>
|
|
||||||
|
|
||||||
{/* <Route path="/shixunchild" component={TPMShixunchildIndexComponent}>
|
|
||||||
</Route>
|
|
||||||
<Route path="/fork_list" component={TPMshixunfork_listIndexComponent}>
|
|
||||||
</Route> */}
|
|
||||||
|
|
||||||
{/*<Route path="/forums" component={ForumsIndexComponent}>*/}
|
|
||||||
{/*</Route>*/}
|
|
||||||
|
|
||||||
|
|
||||||
{/*实训课程(原实训路径)*/}
|
|
||||||
<Route path="/paths" component={ShixunPaths}></Route>
|
|
||||||
|
|
||||||
<Route path="/search"
|
|
||||||
render={
|
|
||||||
(props)=>(<SearchPage {...this.props} {...props} {...this.state}></SearchPage>)
|
|
||||||
}
|
|
||||||
></Route>
|
|
||||||
|
|
||||||
{/*课堂*/}
|
|
||||||
<Route path="/courses" component={CoursesIndex} {...this.props}></Route>
|
|
||||||
|
|
||||||
{/* 课堂讨论 */}
|
|
||||||
{/* <Route path="/board" component = {BoardIndex} {...this.props}></Route> */}
|
|
||||||
|
|
||||||
{/* <Route path="/tpforums" component={TPForumsIndexComponent}>
|
|
||||||
</Route> */}
|
|
||||||
|
|
||||||
{/* <Route path="/myshixuns/:shixunId/stages/:stageId" component={Index}/> */}
|
|
||||||
{/* 兴趣页面*/}
|
|
||||||
{/*<Route path="/interest" component={Interestpage}/>*/}
|
|
||||||
|
|
||||||
<Route path="/comment" component={CommentComponent}/>
|
|
||||||
<Route path="/testMaterial" component={TestMaterialDesignComponent}/>
|
|
||||||
<Route path="/test" component={TestIndex}/>
|
|
||||||
<Route path="/testCodeMirror" component={TestCodeMirrorComponent}/>
|
|
||||||
<Route path="/testRCComponent" component={TestComponent}/>
|
|
||||||
<Route path="/testUrlQuery" component={TestUrlQueryComponent}/>
|
|
||||||
|
|
||||||
{/* 教学案例 */}
|
|
||||||
<Route path="/moop_cases"render={
|
|
||||||
(props) => (<MoopCases {...this.props} {...props} {...this.state} />)
|
|
||||||
}/>
|
|
||||||
|
|
||||||
{/* <Route component={NotFoundPage}/> */}
|
|
||||||
{/*列表页*/}
|
|
||||||
{/*<Route component={TPMShixunsIndexComponent}/>*/}
|
|
||||||
{/*首页*/}
|
|
||||||
<Route exact path="/" component={ShixunsHome}/>
|
|
||||||
<Route component={Shixunnopage}/>
|
|
||||||
|
|
||||||
{/*<Route component={ShixunsHome}/>*/}
|
|
||||||
|
|
||||||
</Switch>
|
|
||||||
</Router>
|
|
||||||
</MuiThemeProvider>
|
|
||||||
</LocaleProvider>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// moment国际化,设置为中文
|
|
||||||
moment.defineLocale('zh-cn', {
|
|
||||||
months: '一月_二月_三月_四月_五月_六月_七月_八月_九月_十月_十一月_十二月'.split('_'),
|
|
||||||
monthsShort: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'),
|
|
||||||
weekdays: '星期日_星期一_星期二_星期三_星期四_星期五_星期六'.split('_'),
|
|
||||||
weekdaysShort: '周日_周一_周二_周三_周四_周五_周六'.split('_'),
|
|
||||||
weekdaysMin: '日_一_二_三_四_五_六'.split('_'),
|
|
||||||
longDateFormat: {
|
|
||||||
LT: 'Ah点mm分',
|
|
||||||
LTS: 'Ah点m分s秒',
|
|
||||||
L: 'YYYY-MM-DD',
|
|
||||||
LL: 'YYYY年MMMD日',
|
|
||||||
LLL: 'YYYY年MMMD日Ah点mm分',
|
|
||||||
LLLL: 'YYYY年MMMD日ddddAh点mm分',
|
|
||||||
l: 'YYYY-MM-DD',
|
|
||||||
ll: 'YYYY年MMMD日',
|
|
||||||
lll: 'YYYY年MMMD日Ah点mm分',
|
|
||||||
llll: 'YYYY年MMMD日ddddAh点mm分'
|
|
||||||
},
|
|
||||||
meridiemParse: /凌晨|早上|上午|中午|下午|晚上/,
|
|
||||||
meridiemHour: function (hour, meridiem) {
|
|
||||||
if (hour === 12) {
|
|
||||||
hour = 0;
|
|
||||||
}
|
|
||||||
if (meridiem === '凌晨' || meridiem === '早上' ||
|
|
||||||
meridiem === '上午') {
|
|
||||||
return hour;
|
|
||||||
} else if (meridiem === '下午' || meridiem === '晚上') {
|
|
||||||
return hour + 12;
|
|
||||||
} else {
|
|
||||||
// '中午'
|
|
||||||
return hour >= 11 ? hour : hour + 12;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
meridiem: function (hour, minute, isLower) {
|
|
||||||
var hm = hour * 100 + minute;
|
|
||||||
if (hm < 600) {
|
|
||||||
return '凌晨';
|
|
||||||
} else if (hm < 900) {
|
|
||||||
return '早上';
|
|
||||||
} else if (hm < 1130) {
|
|
||||||
return '上午';
|
|
||||||
} else if (hm < 1230) {
|
|
||||||
return '中午';
|
|
||||||
} else if (hm < 1800) {
|
|
||||||
return '下午';
|
|
||||||
} else {
|
|
||||||
return '晚上';
|
|
||||||
}
|
|
||||||
},
|
|
||||||
calendar: {
|
|
||||||
sameDay: function () {
|
|
||||||
return this.minutes() === 0 ? '[今天]Ah[点整]' : '[今天]LT';
|
|
||||||
},
|
|
||||||
nextDay: function () {
|
|
||||||
return this.minutes() === 0 ? '[明天]Ah[点整]' : '[明天]LT';
|
|
||||||
},
|
|
||||||
lastDay: function () {
|
|
||||||
return this.minutes() === 0 ? '[昨天]Ah[点整]' : '[昨天]LT';
|
|
||||||
},
|
|
||||||
nextWeek: function () {
|
|
||||||
var startOfWeek, prefix;
|
|
||||||
startOfWeek = moment().startOf('week');
|
|
||||||
prefix = this.unix() - startOfWeek.unix() >= 7 * 24 * 3600 ? '[下]' : '[本]';
|
|
||||||
return this.minutes() === 0 ? prefix + 'dddAh点整' : prefix + 'dddAh点mm';
|
|
||||||
},
|
|
||||||
lastWeek: function () {
|
|
||||||
var startOfWeek, prefix;
|
|
||||||
startOfWeek = moment().startOf('week');
|
|
||||||
prefix = this.unix() < startOfWeek.unix() ? '[上]' : '[本]';
|
|
||||||
return this.minutes() === 0 ? prefix + 'dddAh点整' : prefix + 'dddAh点mm';
|
|
||||||
},
|
|
||||||
sameElse: 'LL'
|
|
||||||
},
|
|
||||||
ordinalParse: /\d{1,2}(日|月|周)/,
|
|
||||||
ordinal: function (number, period) {
|
|
||||||
switch (period) {
|
|
||||||
case 'd':
|
|
||||||
case 'D':
|
|
||||||
case 'DDD':
|
|
||||||
return number + '日';
|
|
||||||
case 'M':
|
|
||||||
return number + '月';
|
|
||||||
case 'w':
|
|
||||||
case 'W':
|
|
||||||
return number + '周';
|
|
||||||
default:
|
|
||||||
return number;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
relativeTime: {
|
|
||||||
future: '%s内',
|
|
||||||
past: '%s前',
|
|
||||||
s: '几秒',
|
|
||||||
m: '1分钟',
|
|
||||||
mm: '%d分钟',
|
|
||||||
h: '1小时',
|
|
||||||
hh: '%d小时',
|
|
||||||
d: '1天',
|
|
||||||
dd: '%d天',
|
|
||||||
M: '1个月',
|
|
||||||
MM: '%d个月',
|
|
||||||
y: '1年',
|
|
||||||
yy: '%d年'
|
|
||||||
},
|
|
||||||
week: {
|
|
||||||
// GB/T 7408-1994《数据元和交换格式·信息交换·日期和时间表示法》与ISO 8601:1988等效
|
|
||||||
dow: 1, // Monday is the first day of the week.
|
|
||||||
doy: 4 // The week that contains Jan 4th is the first week of the year.
|
|
||||||
}
|
|
||||||
});
|
|
||||||
export default SnackbarHOC()(App);
|
|
61
CHANGELOG.md
61
CHANGELOG.md
|
@ -1,9 +1,68 @@
|
||||||
# Changelog
|
# Changelog
|
||||||
|
## [v3.2.0](https://forgeplus.trustie.net/projects/jasder/forgeplus/releases) - 2021-06-09
|
||||||
|
|
||||||
|
### ENHANCEMENTS
|
||||||
|
* ADD 集成邮件和平台站内信等通知系统
|
||||||
|
* Fix 代码库二级页面-优化文件子目录浏览功能(#50388)
|
||||||
|
* Fix 代码库二级页面-优化commit提交详情页页面排版及数据显示(#50372)
|
||||||
|
* Fix 代码库二级页面-优化commit提交信息列表页加载方式和数据排序功能(#50348)
|
||||||
|
* Fix 代码库二级页面-优化创建发行版功能(#50346)
|
||||||
|
* Fix 代码库二级页面-优化标签列表页功能(#50344)
|
||||||
|
* Fix 代码库二级页面-优化发行版本列表页功能(#50345)
|
||||||
|
* Fix 代码库二级页面-优化分支列表页功能(#50343)
|
||||||
|
* Fix 其他问题优化(#51581) (#51343) (#51108)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### BUGFIXES
|
||||||
|
* Fix 发行版—标签跳转链接错误(#51666)
|
||||||
|
* Fix 文件预览报错(#51660)
|
||||||
|
* Fix 标签创建时间显示错误(#51658)
|
||||||
|
* Fix 分支列表中头像显示问题(#51656)
|
||||||
|
* Fix 文本信息过长(#51630) (#51626)
|
||||||
|
* Fix 版本库中附件下载400(#51625)
|
||||||
|
* Fix loading页面优化(#51588)
|
||||||
|
* Fix 提交详情页面优化(#51577)
|
||||||
|
* Fix 修复疑修复制功能(#51569)
|
||||||
|
* Fix 修复新建发行版用户信息显示错误的问题(#51665)
|
||||||
|
* Fix 修复查看文件详细信息报错的问题(#51561)
|
||||||
|
* Fix 修复提交记录中时间显示格式问题(#51526)
|
||||||
|
* Fix 组织下项目更加更新时间倒序排序(#50833)
|
||||||
|
|
||||||
|
|
||||||
|
## [v3.1.0](https://forgeplus.trustie.net/projects/jasder/forgeplus/releases) - 2021-06-09
|
||||||
|
|
||||||
|
* ENHANCEMENTS
|
||||||
|
* ADD 用户活动统计图表功能
|
||||||
|
* ADD 用户精选项目功能
|
||||||
|
* ADD 用户贡献度统计图表功能
|
||||||
|
* ADD 用户开发能力数据统计工
|
||||||
|
* ADD 用户角色定位展示功能
|
||||||
|
* ADD 用户专业定位标签展示功能
|
||||||
|
* ADD 修改用户基本资料功能
|
||||||
|
* ADD 更改密码功能
|
||||||
|
* ADD 用户个人主页基本现在展示可配置功能
|
||||||
|
|
||||||
|
* BUGFIXES
|
||||||
|
* Fix 解决一些bug
|
||||||
|
* Fix 优化美化页面
|
||||||
|
|
||||||
|
|
||||||
|
* BUGFIXES
|
||||||
|
* Fix 在线修改文件,页面文件显不及时的问题(46049)
|
||||||
|
* Fix Fork项目,接口多次调用问题(45052)
|
||||||
|
* FIX 页面置顶功能区域排版问题(45825)
|
||||||
|
* Fix 其他样式显示问题
|
||||||
|
|
||||||
|
* ENHANCEMENTS
|
||||||
|
* ADD 合并请求页面显示有冲突文件状态(46016)
|
||||||
|
* ADD 创建组织各属性添加规则匹配功能(45707)
|
||||||
|
* ADD 微信分享功能(45707)
|
||||||
|
|
||||||
## [v3.0.3](https://forgeplus.trustie.net/projects/jasder/forgeplus/releases) - 2021-05-08
|
## [v3.0.3](https://forgeplus.trustie.net/projects/jasder/forgeplus/releases) - 2021-05-08
|
||||||
|
|
||||||
* BUGFIXES
|
* BUGFIXES
|
||||||
* Fix 解决易修标题过长导致的排版问题(45469)
|
* Fix 解决疑修标题过长导致的排版问题(45469)
|
||||||
* Fix 解决合并请求详情页面排版错误的问题(45457)
|
* Fix 解决合并请求详情页面排版错误的问题(45457)
|
||||||
* FIX 解决转移仓库界面专有名词描述错误的问题(45455)
|
* FIX 解决转移仓库界面专有名词描述错误的问题(45455)
|
||||||
* Fix 解决markdown格式文件自动生成数字排序的问题(45454)
|
* Fix 解决markdown格式文件自动生成数字排序的问题(45454)
|
||||||
|
|
|
@ -176,7 +176,9 @@ GEM
|
||||||
mimemagic (~> 0.3.2)
|
mimemagic (~> 0.3.2)
|
||||||
maruku (0.7.3)
|
maruku (0.7.3)
|
||||||
method_source (0.9.2)
|
method_source (0.9.2)
|
||||||
mimemagic (0.3.4)
|
mimemagic (0.3.10)
|
||||||
|
nokogiri (~> 1)
|
||||||
|
rake
|
||||||
mini_mime (1.0.2)
|
mini_mime (1.0.2)
|
||||||
mini_portile2 (2.4.0)
|
mini_portile2 (2.4.0)
|
||||||
minitest (5.14.0)
|
minitest (5.14.0)
|
||||||
|
|
137
LICENSE
137
LICENSE
|
@ -1,21 +1,124 @@
|
||||||
MIT License
|
木兰宽松许可证, 第2版
|
||||||
|
|
||||||
Copyright (c) [year] [fullname]
|
2020年1月 http://license.coscl.org.cn/MulanPSL2
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束:
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
0. 定义
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
“软件” 是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
“贡献” 是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
“贡献者” 是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
“法人实体” 是指提交贡献的机构及其“关联实体”。
|
||||||
|
|
||||||
|
“关联实体” 是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。
|
||||||
|
|
||||||
|
1. 授予版权许可
|
||||||
|
|
||||||
|
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。
|
||||||
|
|
||||||
|
2. 授予专利许可
|
||||||
|
|
||||||
|
每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。
|
||||||
|
|
||||||
|
3. 无商标许可
|
||||||
|
|
||||||
|
“本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。
|
||||||
|
|
||||||
|
4. 分发限制
|
||||||
|
|
||||||
|
您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。
|
||||||
|
|
||||||
|
5. 免责声明与责任限制
|
||||||
|
|
||||||
|
“软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。
|
||||||
|
|
||||||
|
6. 语言
|
||||||
|
|
||||||
|
“本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。
|
||||||
|
|
||||||
|
条款结束
|
||||||
|
|
||||||
|
如何将木兰宽松许可证,第2版,应用到您的软件
|
||||||
|
|
||||||
|
如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步:
|
||||||
|
|
||||||
|
1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字;
|
||||||
|
|
||||||
|
2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中;
|
||||||
|
|
||||||
|
3, 请将如下声明文本放入每个源文件的头部注释中。
|
||||||
|
|
||||||
|
Copyright (c) [Year] [name of copyright holder]
|
||||||
|
[Software Name] is licensed under Mulan PSL v2.
|
||||||
|
You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
http://license.coscl.org.cn/MulanPSL2
|
||||||
|
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
See the Mulan PSL v2 for more details.
|
||||||
|
Mulan Permissive Software License,Version 2
|
||||||
|
Mulan Permissive Software License,Version 2 (Mulan PSL v2)
|
||||||
|
|
||||||
|
January 2020 http://license.coscl.org.cn/MulanPSL2
|
||||||
|
|
||||||
|
Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions:
|
||||||
|
|
||||||
|
0. Definition
|
||||||
|
|
||||||
|
Software means the program and related documents which are licensed under this License and comprise all Contribution(s).
|
||||||
|
|
||||||
|
Contribution means the copyrightable work licensed by a particular Contributor under this License.
|
||||||
|
|
||||||
|
Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License.
|
||||||
|
|
||||||
|
Legal Entity means the entity making a Contribution and all its Affiliates.
|
||||||
|
|
||||||
|
Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity.
|
||||||
|
|
||||||
|
1. Grant of Copyright License
|
||||||
|
|
||||||
|
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not.
|
||||||
|
|
||||||
|
2. Grant of Patent License
|
||||||
|
|
||||||
|
Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken.
|
||||||
|
|
||||||
|
3. No Trademark License
|
||||||
|
|
||||||
|
No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in section 4.
|
||||||
|
|
||||||
|
4. Distribution Restriction
|
||||||
|
|
||||||
|
You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software.
|
||||||
|
|
||||||
|
5. Disclaimer of Warranty and Limitation of Liability
|
||||||
|
|
||||||
|
THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||||
|
|
||||||
|
6. Language
|
||||||
|
|
||||||
|
THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL.
|
||||||
|
|
||||||
|
END OF THE TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software
|
||||||
|
|
||||||
|
To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps:
|
||||||
|
|
||||||
|
Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner;
|
||||||
|
Create a file named "LICENSE" which contains the whole context of this License in the first directory of your software package;
|
||||||
|
Attach the statement to the appropriate annotated syntax at the beginning of each source file.
|
||||||
|
Copyright (c) [Year] [name of copyright holder]
|
||||||
|
[Software Name] is licensed under Mulan PSL v2.
|
||||||
|
You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
http://license.coscl.org.cn/MulanPSL2
|
||||||
|
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
See the Mulan PSL v2 for more details.
|
148
README.md
148
README.md
|
@ -1,17 +1,27 @@
|
||||||
Trustie (确实)是一个以大众化协同开发、开放式资源共享、持续性可信评估为核心机理,面向高校创新实践的在线协作平台。
|
# GitLink - CCF开源创新服务平台
|
||||||
|
|
||||||
## 特性
|
GitLink(确实开源)是中国计算机学会(CCF)官方指定的开源创新服务平台,旨在以“为开源创新服务”为使命,以“成为开源创新的汇聚地”为愿景,秉承“创新、开放、协作、共享”的价值观,致力于为大规模开源开放协同创新助力赋能,打造创新成果孵化和新工科人才培养的开源创新生态!
|
||||||
|
|
||||||
- 软件创作与生产深度融合的软件开发环境体系结构 软件自由创作和工程生产的高效衔接,适于软件开发中群体智慧的有效汇聚。
|
<center>
|
||||||
|
<img src="https://code.gitlink.org.cn/young/forgeplus/raw/branch/master/docs/figs/gitlink.png?raw=true" width=80% /></center>
|
||||||
|
|
||||||
|
## 特色功能
|
||||||
|
|
||||||
- 构件化协同开发环境的可扩展运行框架多样化工具的集成和联动,形成了强动态扩展能力的平台框架。
|
- **分布式协作开发**:基于Git打造分布式代码托管环境,提供免费公、私有代码仓库,支持在线文件编辑、代码分支管理、协作贡献统计、代码仓库复刻(Fork)、贡献合并请求(PR)、群智贡献审阅等功能,让您的项目在这里健康、快速的成长!
|
||||||
|
|
||||||
- “互联网即资源库”的全新软件复用模式 成长式软件资源管理系统,实现了分散资源的知识融合、资源的可持续增长和有效复用。
|
- **一站式过程管理**:提供易修(Issue)、里程碑、通知提醒、标签归档等多样化任务管理工具,支持各类开发任务的发布、指派与跟踪,同时提供在线Wiki文档、组织多粒度管理等功能,为您搭建一站式的项目过程管理环境,让您的团队协作更高效、过程更透明!
|
||||||
|
|
||||||
## 部署
|
- **高效流水线运维**:融合DevOps思想,提供轻量级的工作流引擎(Engine),打通编码、测试、构建、部署等开发运维环节;支持自定义配置、代码静态扫描、构建自动触发、容器镜像托管等功能,同时支持接入第三方运维工具,让您的代码更加快速、可靠地形成高质量的产品!
|
||||||
|
|
||||||
|
- **多层次代码分析**:提供软件软代码和芯片RTL代码的溯源分析、文件级和组件级许可证识别及风险分析、输入性开源漏洞检测和加固建议,支持分析结果的多层次可视化展示,帮助您实施有效开源治理,厘清代码引用链,发现并消除漏洞感染链,为安全合规的开源引用保驾护航!
|
||||||
|
|
||||||
|
- **多维度用户画像**:实时采集和分析平台中的各类开源资源数据,搭建多维度用户画像评估系统,提供开发活动统计、贡献度日历、用户能力建模、角色与专业定位分析等功能,让您在个人主页展示开发动态与创新能力!
|
||||||
|
|
||||||
|
|
||||||
### Depends Versions
|
## 部署流程
|
||||||
|
|
||||||
|
|
||||||
|
### 依赖库
|
||||||
|
|
||||||
* Ruby 2.4.5
|
* Ruby 2.4.5
|
||||||
|
|
||||||
|
@ -23,22 +33,19 @@ Trustie (确实)是一个以大众化协同开发、开放式资源共享、
|
||||||
|
|
||||||
* imagemagick
|
* imagemagick
|
||||||
|
|
||||||
### Steps
|
### 步骤
|
||||||
|
|
||||||
#### 1. 克隆稳定版本
|
(1)克隆稳定版本
|
||||||
```
|
```
|
||||||
git clone -b standalone https://git.trustie.net/jasder/forgeplus.git
|
git clone -b master https://gitlink.org.cn/Gitlink/forgeplus.git
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 2. 安装依赖包
|
(2)安装依赖包
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd forgeplus && bundle install
|
cd forgeplus && bundle install
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 3. 配置初始化文件
|
(3)配置初始化文件:进入项目根目录执行以下命令
|
||||||
进入项目根目录执行一下命令:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cp config/configuration.yml.example config/configuration.yml
|
cp config/configuration.yml.example config/configuration.yml
|
||||||
cp config/database.yml.example config/database.yml
|
cp config/database.yml.example config/database.yml
|
||||||
|
@ -46,11 +53,7 @@ touch config/redis.yml
|
||||||
touch config/elasticsearch.yml
|
touch config/elasticsearch.yml
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 4. 配置数据库
|
(4)配置数据库:数据库配置信息请查看/config/database.yml文件,项目默认采用mysql数据库, 如需更改,请自行修改配置信息,默认配置如下
|
||||||
数据库配置信息请查看/config/database.yml文件,
|
|
||||||
项目默认采用mysql数据库, 如需更改,请自行修改配置信息,
|
|
||||||
默认配置如下:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
default: &default
|
default: &default
|
||||||
adapter: mysql2
|
adapter: mysql2
|
||||||
|
@ -60,14 +63,13 @@ default: &default
|
||||||
password: 123456
|
password: 123456
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 5. 配置gitea服务(可选)
|
(5)配置gitea服务(可选):如需要部署自己的gitea平台,请参考[gitea官方平台文档](https://docs.gitea.io/zh-cn/install-from-binary/)。因目前gitea平台api受限,暂时推荐从forge平台获取[gitea部署文件](https://forgeplus.trustie.net/projects/Trustie/gitea-binary)进行部署
|
||||||
**如需要部署自己的gitea平台,请参考gitea官方平台:https://docs.gitea.io/zh-cn/install-from-binary/**
|
|
||||||
|
|
||||||
**因目前gitea平台api受限,暂时推荐从forge平台获取gitea部署文件进行部署:https://forgeplus.trustie.net/projects/Trustie/gitea-binary**
|
- 配置gitea服务步骤:
|
||||||
|
|
||||||
**配置gitea服务步骤**
|
-- 部署gitea服务,并注册root账户
|
||||||
1. 部署gitea服务,并注册root账户
|
|
||||||
2. 修改forge平台的 config/configuration.yml中的gitea服务指向地址,如:
|
-- 修改forge平台的 config/configuration.yml中的gitea服务指向地址,如:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
gitea:
|
gitea:
|
||||||
|
@ -77,10 +79,9 @@ gitea:
|
||||||
base_url: '/api/v1'
|
base_url: '/api/v1'
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 6. 安装redis环境
|
(6)安装redis环境:请自行搜索各平台如何安装部署redis环境
|
||||||
**请自行搜索各平台如何安装部署redis环境**
|
|
||||||
|
|
||||||
#### 7. 安装imagemagick插件
|
(7)安装imagemagick插件:
|
||||||
- Mac OS X
|
- Mac OS X
|
||||||
```bash
|
```bash
|
||||||
brew install imagemagick ghostscript
|
brew install imagemagick ghostscript
|
||||||
|
@ -91,88 +92,89 @@ gitea:
|
||||||
sudo apt-get install -y imagemagick
|
sudo apt-get install -y imagemagick
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 8. 创建数据库
|
(8)创建数据库:开发环境为development, 生成环境为production
|
||||||
**开发环境为development, 生成环境为production**
|
|
||||||
```bash
|
```bash
|
||||||
rails db:create RAILS_ENV=development
|
rails db:create RAILS_ENV=development
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 9. 导入数据表结构
|
(9)导入数据表结构
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bundle exec rake sync_table_structure:import_csv
|
bundle exec rake sync_table_structure:import_csv
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 10. 执行migrate迁移文件
|
(10)执行migrate迁移文件:开发环境为development, 生成环境为production
|
||||||
**开发环境为development, 生成环境为production**
|
|
||||||
```bash
|
```bash
|
||||||
rails db:migrate RAILS_ENV=development
|
rails db:migrate RAILS_ENV=development
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 11. clone前端代码
|
(11)clone前端代码:将前端代码克隆到public/react目录下,目录结构应该是: public/react/build
|
||||||
**将前端代码克隆到public/react目录下,目录结构应该是: public/react/build**
|
|
||||||
```bash
|
```bash
|
||||||
git clone -b standalone https://git.trustie.net/jasder/build.git
|
git clone -b standalone https://gitlink.org.cn/Gitlink/build.git
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 12. 启动redis(此处已mac系统为例)
|
(12)启动redis(此处以macOS系统为例)
|
||||||
```bash
|
```bash
|
||||||
redis-server&
|
redis-server&
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 13. 启动sidekiq
|
(13)启动sidekiq:开发环境为development, 生成环境为production
|
||||||
**开发环境为development, 生成环境为production**
|
|
||||||
```bash
|
```bash
|
||||||
bundle exec sidekiq -C config/sidekiq.yml -e production -d
|
bundle exec sidekiq -C config/sidekiq.yml -e production -d
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 14. 启动rails服务
|
(14)启动rails服务
|
||||||
```bash
|
```bash
|
||||||
rails s
|
rails s
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 15. 浏览器访问
|
(15)浏览器访问:在浏览器中输入如下地址访问
|
||||||
在浏览器中输入如下地址访问:
|
|
||||||
```bash
|
```bash
|
||||||
http://localhost:3000/
|
http://localhost:3000/
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 16. 其他说明
|
(16)其他说明:通过页面注册以第一个用户为平台管理员用户
|
||||||
通过页面注册都第一个用户为平台管理员用户
|
|
||||||
|
|
||||||
## 页面展示
|
## 页面展示
|
||||||
|
|
||||||
- 代码库
|
- 项目列表
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<img src="https://code.gitlink.org.cn/young/forgeplus/raw/branch/master/docs/figs/project_list.png?raw=true" width=50% />
|
||||||
|
</center>
|
||||||
|
|
||||||
|
- 代码仓库
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<img src="https://code.gitlink.org.cn/young/forgeplus/raw/branch/master/docs/figs/repo.png?raw=true" width=50% />
|
||||||
|
</center>
|
||||||
|
|
||||||
- 任务管理
|
- 任务管理
|
||||||

|
|
||||||
|
<center>
|
||||||
|
<img src="https://code.gitlink.org.cn/young/forgeplus/raw/branch/master/docs/figs/issues.png?raw=true" width=50% />
|
||||||
|
</center>
|
||||||
|
|
||||||
|
- 合并请求
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<img src="https://code.gitlink.org.cn/young/forgeplus/raw/branch/master/docs/figs/PR.png?raw=true" width=50% />
|
||||||
|
</center>
|
||||||
|
|
||||||
|
- 引擎配置
|
||||||
|
|
||||||
|
<center>
|
||||||
|
<img src="https://code.gitlink.org.cn/young/forgeplus/raw/branch/master/docs/figs/engine.png?raw=true" width=50% />
|
||||||
|
</center>
|
||||||
|
|
||||||
- 任务查看
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
- 任务指派
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
- 里程碑
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### API
|
|
||||||
- [API文档](https://forgeplus.trustie.net/docs/api)
|
|
||||||
- [API](showdoc.com.cn)
|
|
||||||
账号:forgeplus@admin.com 密码:forge123
|
|
||||||
|
|
||||||
## 贡献代码
|
## 贡献代码
|
||||||
|
|
||||||
1. Fork 项目
|
我们期待您向GitLink提交贡献!在您贡献时,请遵循流程:[【Wiki文档-GitLink协作开发流程】](https://www.gitlink.org.cn/Gitlink/forgeplus/wiki "【Wiki文档-GitLink协作开发流程】")
|
||||||
2. 创建本地分支(git checkout -b my-new-feature)
|
|
||||||
3. 提交更改 (git commit -am 'Add some feature')
|
|
||||||
4. 推送到分支 (git push origin my-new-feature)
|
|
||||||
5. 向源项目的 **develop** 分支发起 Pull Request
|
|
||||||
|
|
||||||
## License
|
#### 指导文档
|
||||||
|
- [API文档](https://www.gitlink.org.cn/docs/api)
|
||||||
|
- [Git常用命令](https://git-scm.com/)
|
||||||
|
|
||||||
|
## 许可证协议
|
||||||
|
|
|
@ -51,6 +51,51 @@ http://localhost:3000/api/accounts/remote_register | jq
|
||||||
|-- token |string|用户token|
|
|-- token |string|用户token|
|
||||||
|
|
||||||
|
|
||||||
|
返回值
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"status": 0,
|
||||||
|
"message": "success",
|
||||||
|
"user": {
|
||||||
|
"id": 36400,
|
||||||
|
"token": "8c87a80d9cfacc92fcb2451845104f35119eda96"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 独立注册接口
|
||||||
|
```
|
||||||
|
POST accounts/register
|
||||||
|
```
|
||||||
|
*示例*
|
||||||
|
```bash
|
||||||
|
curl -X POST \
|
||||||
|
-d "login=2456233122@qq.com" \
|
||||||
|
-d "password=djs_D_00001" \
|
||||||
|
-d "namespace=16895620" \
|
||||||
|
-d "code=forge" \
|
||||||
|
http://localhost:3000/api/accounts/remote_register | jq
|
||||||
|
```
|
||||||
|
*请求参数说明:*
|
||||||
|
|
||||||
|
|参数名|必选|类型|说明|
|
||||||
|
|-|-|-|-|
|
||||||
|
|login |是|string |邮箱或者手机号 |
|
||||||
|
|namespace |是|string |登录名 |
|
||||||
|
|password |是|string |密码 |
|
||||||
|
|code |是|string |验证码 |
|
||||||
|
|
||||||
|
|
||||||
|
*返回参数说明:*
|
||||||
|
|
||||||
|
|参数名|类型|说明|
|
||||||
|
|-|-|-|
|
||||||
|
|user|json object |返回数据|
|
||||||
|
|-- id |int |用户id |
|
||||||
|
|-- token |string|用户token|
|
||||||
|
|
||||||
|
|
||||||
返回值
|
返回值
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
|
@ -338,10 +383,10 @@ http://localhost:3000/api/projects/ | jq
|
||||||
|-|-|-|-|
|
|-|-|-|-|
|
||||||
|user_id |是|int |用户id或者组织id |
|
|user_id |是|int |用户id或者组织id |
|
||||||
|name |是|string |项目名称 |
|
|name |是|string |项目名称 |
|
||||||
|description |是|string |项目描述 |
|
|description |否|string |项目描述 |
|
||||||
|repository_name |是|string |仓库名称, 只含有数字、字母、下划线不能以下划线开头和结尾,且唯一 |
|
|repository_name |是|string |仓库名称, 只含有数字、字母、下划线不能以下划线开头和结尾,且唯一 |
|
||||||
|project_category_id|是|int |项目类别id |
|
|project_category_id|否|int |项目类别id |
|
||||||
|project_language_id|是|int |项目语言id |
|
|project_language_id|否|int |项目语言id |
|
||||||
|ignore_id |否|int |gitignore相关id |
|
|ignore_id |否|int |gitignore相关id |
|
||||||
|license_id |否|int |开源许可证id |
|
|license_id |否|int |开源许可证id |
|
||||||
|private |否|boolean|项目是否私有, true:为私有,false: 公开,默认为公开 |
|
|private |否|boolean|项目是否私有, true:为私有,false: 公开,默认为公开 |
|
||||||
|
@ -374,9 +419,7 @@ curl -X POST \
|
||||||
-d "user_id=36408" \
|
-d "user_id=36408" \
|
||||||
-d "clone_addr=https://gitea.com/mx8090alex/golden.git" \
|
-d "clone_addr=https://gitea.com/mx8090alex/golden.git" \
|
||||||
-d "name=golden_mirror1" \
|
-d "name=golden_mirror1" \
|
||||||
-d "description=golden_mirror" \
|
-d "repository_name=golden_mirror1" \
|
||||||
-d "project_category_id=1" \
|
|
||||||
-d "project_language_id=2" \
|
|
||||||
http://localhost:3000/api/projects/migrate.json | jq
|
http://localhost:3000/api/projects/migrate.json | jq
|
||||||
```
|
```
|
||||||
*请求参数说明:*
|
*请求参数说明:*
|
||||||
|
@ -388,8 +431,8 @@ http://localhost:3000/api/projects/migrate.json | jq
|
||||||
|clone_addr |是|string |镜像项目clone地址 |
|
|clone_addr |是|string |镜像项目clone地址 |
|
||||||
|description |否|string |项目描述 |
|
|description |否|string |项目描述 |
|
||||||
|repository_name |是|string |仓库名称, 只含有数字、字母、下划线不能以下划线开头和结尾,且唯一 |
|
|repository_name |是|string |仓库名称, 只含有数字、字母、下划线不能以下划线开头和结尾,且唯一 |
|
||||||
|project_category_id|是|int |项目类别id |
|
|project_category_id|否|int |项目类别id |
|
||||||
|project_language_id|是|int |项目语言id |
|
|project_language_id|否|int |项目语言id |
|
||||||
|is_mirror |否|boolean|是否设置为镜像, true:是, false:否,默认为否 |
|
|is_mirror |否|boolean|是否设置为镜像, true:是, false:否,默认为否 |
|
||||||
|auth_username |否|string|镜像源仓库的登录用户名 |
|
|auth_username |否|string|镜像源仓库的登录用户名 |
|
||||||
|auth_password |否|string|镜像源仓库的登录秘密 |
|
|auth_password |否|string|镜像源仓库的登录秘密 |
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 9.8 KiB |
|
@ -99,3 +99,38 @@ $(document).on("turbolinks:before-cache", function () {
|
||||||
|
|
||||||
$(function () {
|
$(function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).on('turbolinks:load', function() {
|
||||||
|
|
||||||
|
$('.logo-item-left').on("change", 'input[type="file"]', function () {
|
||||||
|
var $fileInput = $(this);
|
||||||
|
var file = this.files[0];
|
||||||
|
var imageType = /image.*/;
|
||||||
|
if (file && file.type.match(imageType)) {
|
||||||
|
var reader = new FileReader();
|
||||||
|
reader.onload = function () {
|
||||||
|
var $box = $fileInput.parent();
|
||||||
|
$box.find('img').attr('src', reader.result).css('display', 'block');
|
||||||
|
$box.addClass('has-img');
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.attachment-item-left').on("change", 'input[type="file"]', function () {
|
||||||
|
var $fileInput = $(this);
|
||||||
|
var file = this.files[0];
|
||||||
|
var imageType = /image.*/;
|
||||||
|
if (file && file.type.match(imageType)) {
|
||||||
|
var reader = new FileReader();
|
||||||
|
reader.onload = function () {
|
||||||
|
var $box = $fileInput.parent();
|
||||||
|
$box.find('img').attr('src', reader.result).css('display', 'block');
|
||||||
|
$box.addClass('has-img');
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
|
@ -1,7 +1,7 @@
|
||||||
$(document).on('turbolinks:load', function() {
|
$(document).on('turbolinks:load', function() {
|
||||||
if ($('body.admins-courses-index-page').length > 0) {
|
if ($('body.admins-courses-index-page').length > 0) {
|
||||||
let searchContainer = $(".course-list-form");
|
var searchContainer = $(".course-list-form");
|
||||||
let searchForm = $("form.search-form",searchContainer);
|
var searchForm = $("form.search-form",searchContainer);
|
||||||
|
|
||||||
searchContainer.on('change', '.course-homepage-show', function(){
|
searchContainer.on('change', '.course-homepage-show', function(){
|
||||||
searchForm.find('input[type="submit"]').trigger('click');
|
searchForm.find('input[type="submit"]').trigger('click');
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
// Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,141 @@
|
||||||
|
/*
|
||||||
|
* @Description: Do not edit
|
||||||
|
* @Date: 2021-08-31 11:16:45
|
||||||
|
* @LastEditors: viletyy
|
||||||
|
* @Author: viletyy
|
||||||
|
* @LastEditTime: 2021-08-31 14:19:46
|
||||||
|
* @FilePath: /forgeplus/app/assets/javascripts/admins/system_notifications/index.js
|
||||||
|
*/
|
||||||
|
$(document).on('turbolinks:load', function(){
|
||||||
|
|
||||||
|
var showSuccessNotify = function() {
|
||||||
|
$.notify({
|
||||||
|
message: '操作成功'
|
||||||
|
},{
|
||||||
|
type: 'success'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// close user
|
||||||
|
$('.project-list-container').on('click', '.recommend-action', function(){
|
||||||
|
var $closeAction = $(this);
|
||||||
|
var $uncloseAction = $closeAction.siblings('.unrecommend-action');
|
||||||
|
var $editAction = $closeAction.siblings('.edit-recommend-action');
|
||||||
|
|
||||||
|
var keywordID = $closeAction.data('id');
|
||||||
|
customConfirm({
|
||||||
|
content: '确认将该项目设置为推荐项目吗?',
|
||||||
|
ok: function(){
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/projects/' + keywordID,
|
||||||
|
method: 'PUT',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
project: {
|
||||||
|
recommend: true,
|
||||||
|
recommend_index: 1
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: function() {
|
||||||
|
showSuccessNotify();
|
||||||
|
$closeAction.hide();
|
||||||
|
$uncloseAction.show();
|
||||||
|
$editAction.show();
|
||||||
|
$(".project-item-"+keywordID).children('td').eq(5).text("√")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// unclose user
|
||||||
|
$('.project-list-container').on('click', '.unrecommend-action', function(){
|
||||||
|
var $uncloseAction = $(this);
|
||||||
|
var $closeAction = $uncloseAction.siblings('.recommend-action');
|
||||||
|
var $editAction = $closeAction.siblings('.edit-recommend-action');
|
||||||
|
|
||||||
|
var keywordID = $uncloseAction.data('id');
|
||||||
|
customConfirm({
|
||||||
|
content: '确认取消该推荐项目吗?',
|
||||||
|
ok: function () {
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/projects/' + keywordID,
|
||||||
|
method: 'PUT',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
project: {
|
||||||
|
recommend: false,
|
||||||
|
recommend_index: 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: function() {
|
||||||
|
showSuccessNotify();
|
||||||
|
$closeAction.show();
|
||||||
|
$uncloseAction.hide();
|
||||||
|
$editAction.hide();
|
||||||
|
$(".project-item-"+keywordID).children('td').eq(5).text("")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// close user
|
||||||
|
$('.project-list-container').on('click', '.pinned-action', function(){
|
||||||
|
var $closeAction = $(this);
|
||||||
|
var $uncloseAction = $closeAction.siblings('.unpinned-action');
|
||||||
|
|
||||||
|
var keywordID = $closeAction.data('id');
|
||||||
|
customConfirm({
|
||||||
|
content: '确认将该项目设置为精选项目吗?',
|
||||||
|
ok: function(){
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/projects/' + keywordID,
|
||||||
|
method: 'PUT',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
project: {
|
||||||
|
is_pinned: true,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: function() {
|
||||||
|
showSuccessNotify();
|
||||||
|
$closeAction.hide();
|
||||||
|
$uncloseAction.show();
|
||||||
|
$(".project-item-"+keywordID).children('td').eq(4).text("√")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// unclose user
|
||||||
|
$('.project-list-container').on('click', '.unpinned-action', function(){
|
||||||
|
var $uncloseAction = $(this);
|
||||||
|
var $closeAction = $uncloseAction.siblings('.pinned-action');
|
||||||
|
|
||||||
|
var keywordID = $uncloseAction.data('id');
|
||||||
|
customConfirm({
|
||||||
|
content: '确认取消该精选项目吗?',
|
||||||
|
ok: function () {
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/projects/' + keywordID,
|
||||||
|
method: 'PUT',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
project: {
|
||||||
|
is_pinned: false,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: function() {
|
||||||
|
showSuccessNotify();
|
||||||
|
$closeAction.show();
|
||||||
|
$uncloseAction.hide();
|
||||||
|
$(".project-item-"+keywordID).children('td').eq(4).text("")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
})
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* @Description: Do not edit
|
||||||
|
* @Date: 2021-08-31 11:16:45
|
||||||
|
* @LastEditors: viletyy
|
||||||
|
* @Author: viletyy
|
||||||
|
* @LastEditTime: 2021-08-31 14:19:46
|
||||||
|
* @FilePath: /forgeplus/app/assets/javascripts/admins/reversed_keywords/index.js
|
||||||
|
*/
|
||||||
|
$(document).on('turbolinks:load', function(){
|
||||||
|
|
||||||
|
var showSuccessNotify = function() {
|
||||||
|
$.notify({
|
||||||
|
message: '操作成功'
|
||||||
|
},{
|
||||||
|
type: 'success'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// close user
|
||||||
|
$('.reversed-keyword-list-container').on('click', '.close-action', function(){
|
||||||
|
var $closeAction = $(this);
|
||||||
|
var $uncloseAction = $closeAction.siblings('.unclose-action');
|
||||||
|
|
||||||
|
var keywordID = $closeAction.data('id');
|
||||||
|
customConfirm({
|
||||||
|
content: '确认关闭限制吗?',
|
||||||
|
ok: function(){
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/reversed_keywords/' + keywordID,
|
||||||
|
method: 'PUT',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
reversed_keyword: {
|
||||||
|
closed: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: function() {
|
||||||
|
showSuccessNotify();
|
||||||
|
$closeAction.hide();
|
||||||
|
$uncloseAction.show();
|
||||||
|
$(".reversed-keyword-item-"+keywordID).children('td').eq(3).text("")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// unclose user
|
||||||
|
$('.reversed-keyword-list-container').on('click', '.unclose-action', function(){
|
||||||
|
var $uncloseAction = $(this);
|
||||||
|
var $closeAction = $uncloseAction.siblings('.close-action');
|
||||||
|
|
||||||
|
var keywordID = $uncloseAction.data('id');
|
||||||
|
customConfirm({
|
||||||
|
content: '确认开启限制吗?',
|
||||||
|
ok: function () {
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/reversed_keywords/' + keywordID,
|
||||||
|
method: 'PUT',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
reversed_keyword: {
|
||||||
|
closed: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: function() {
|
||||||
|
showSuccessNotify();
|
||||||
|
$closeAction.show();
|
||||||
|
$uncloseAction.hide();
|
||||||
|
$(".reversed-keyword-item-"+keywordID).children('td').eq(3).text("√")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
})
|
|
@ -1,7 +1,15 @@
|
||||||
|
/*
|
||||||
|
* @Description: Do not edit
|
||||||
|
* @Date: 2021-07-16 11:58:16
|
||||||
|
* @LastEditors: viletyy
|
||||||
|
* @Author: viletyy
|
||||||
|
* @LastEditTime: 2021-08-31 14:48:59
|
||||||
|
* @FilePath: /forgeplus/app/assets/javascripts/admins/shixun_settings/index.js
|
||||||
|
*/
|
||||||
$(document).on('turbolinks:load', function() {
|
$(document).on('turbolinks:load', function() {
|
||||||
if ($('body.admins-shixun-settings-index-page').length > 0) {
|
if ($('body.admins-shixun-settings-index-page').length > 0) {
|
||||||
let searchContainer = $(".shixun-settings-list-form");
|
var searchContainer = $(".shixun-settings-list-form");
|
||||||
let searchForm = $("form.search-form",searchContainer);
|
var searchForm = $("form.search-form",searchContainer);
|
||||||
|
|
||||||
searchContainer.on('change', '.shixun-settings-select', function(){
|
searchContainer.on('change', '.shixun-settings-select', function(){
|
||||||
searchForm.find('input[type="submit"]').trigger('click');
|
searchForm.find('input[type="submit"]').trigger('click');
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
/*
|
||||||
|
* @Description: Do not edit
|
||||||
|
* @Date: 2021-08-31 11:16:45
|
||||||
|
* @LastEditors: viletyy
|
||||||
|
* @Author: viletyy
|
||||||
|
* @LastEditTime: 2021-08-31 14:19:46
|
||||||
|
* @FilePath: /forgeplus/app/assets/javascripts/admins/system_notifications/index.js
|
||||||
|
*/
|
||||||
|
$(document).on('turbolinks:load', function(){
|
||||||
|
|
||||||
|
var showSuccessNotify = function() {
|
||||||
|
$.notify({
|
||||||
|
message: '操作成功'
|
||||||
|
},{
|
||||||
|
type: 'success'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// close user
|
||||||
|
$('.system-notification-list-container').on('click', '.close-action', function(){
|
||||||
|
var $closeAction = $(this);
|
||||||
|
var $uncloseAction = $closeAction.siblings('.unclose-action');
|
||||||
|
|
||||||
|
var keywordID = $closeAction.data('id');
|
||||||
|
customConfirm({
|
||||||
|
content: '确认取消置顶吗?',
|
||||||
|
ok: function(){
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/system_notifications/' + keywordID,
|
||||||
|
method: 'PUT',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
system_notification: {
|
||||||
|
is_top: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: function() {
|
||||||
|
showSuccessNotify();
|
||||||
|
$closeAction.hide();
|
||||||
|
$uncloseAction.show();
|
||||||
|
$(".system-notification-item-"+keywordID).children('td').eq(3).text("")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// unclose user
|
||||||
|
$('.system-notification-list-container').on('click', '.unclose-action', function(){
|
||||||
|
var $uncloseAction = $(this);
|
||||||
|
var $closeAction = $uncloseAction.siblings('.close-action');
|
||||||
|
|
||||||
|
var keywordID = $uncloseAction.data('id');
|
||||||
|
customConfirm({
|
||||||
|
content: '确认置顶吗?',
|
||||||
|
ok: function () {
|
||||||
|
$.ajax({
|
||||||
|
url: '/admins/system_notifications/' + keywordID,
|
||||||
|
method: 'PUT',
|
||||||
|
dataType: 'json',
|
||||||
|
data: {
|
||||||
|
system_notification: {
|
||||||
|
is_top: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
success: function() {
|
||||||
|
showSuccessNotify();
|
||||||
|
$closeAction.show();
|
||||||
|
$uncloseAction.hide();
|
||||||
|
$(".system-notification-item-"+keywordID).children('td').eq(3).text("√")
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
})
|
|
@ -0,0 +1,2 @@
|
||||||
|
// Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
// All this logic will automatically be available in application.js.
|
|
@ -58,3 +58,149 @@ input.form-control {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.logo-item {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
&-img {
|
||||||
|
display: block;
|
||||||
|
width: 80px;
|
||||||
|
height: 80px;
|
||||||
|
background: #e9ecef;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-upload {
|
||||||
|
cursor: pointer;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
width: 80px;
|
||||||
|
height: 80px;
|
||||||
|
background: #e9ecef;
|
||||||
|
border: 1px solid #ced4da;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 27px;
|
||||||
|
left: 39px;
|
||||||
|
width: 2px;
|
||||||
|
height: 26px;
|
||||||
|
background: #495057;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 39px;
|
||||||
|
left: 27px;
|
||||||
|
width: 26px;
|
||||||
|
height: 2px;
|
||||||
|
background: #495057;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-left {
|
||||||
|
position: relative;
|
||||||
|
width: 80px;
|
||||||
|
height: 80px;
|
||||||
|
|
||||||
|
&.has-img {
|
||||||
|
.logo-item-upload {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
.logo-item-upload {
|
||||||
|
display: block;
|
||||||
|
background: rgba(145, 145, 145, 0.8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-right {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
color: #777777;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-title {
|
||||||
|
color: #23272B;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.attachment-item {
|
||||||
|
display: flex;
|
||||||
|
|
||||||
|
&-img {
|
||||||
|
display: block;
|
||||||
|
width: 160px;
|
||||||
|
height: 160px;
|
||||||
|
background: #e9ecef;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-upload {
|
||||||
|
cursor: pointer;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
width: 160px;
|
||||||
|
height: 160px;
|
||||||
|
background: #e9ecef;
|
||||||
|
border: 1px solid #ced4da;
|
||||||
|
|
||||||
|
&::before {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 54px;
|
||||||
|
left: 78px;
|
||||||
|
width: 2px;
|
||||||
|
height: 52px;
|
||||||
|
background: #495057;
|
||||||
|
}
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
content: '';
|
||||||
|
position: absolute;
|
||||||
|
top: 78px;
|
||||||
|
left: 54px;
|
||||||
|
width: 52px;
|
||||||
|
height: 2px;
|
||||||
|
background: #495057;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-left {
|
||||||
|
position: relative;
|
||||||
|
width: 160px;
|
||||||
|
height: 160px;
|
||||||
|
|
||||||
|
&.has-img {
|
||||||
|
.attachment-item-upload {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
.attachment-item-upload {
|
||||||
|
display: block;
|
||||||
|
background: rgba(145, 145, 145, 0.8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&-right {
|
||||||
|
padding-top: 100px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
justify-content: space-between;
|
||||||
|
color: #777777;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
&-title {
|
||||||
|
color: #23272B;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
// Place all the styles related to the admins/faqs controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
||||||
|
// Place all the styles related to the helps/faqs controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -1,352 +1,386 @@
|
||||||
class AccountsController < ApplicationController
|
class AccountsController < ApplicationController
|
||||||
|
include ApplicationHelper
|
||||||
#skip_before_action :check_account, :only => [:logout]
|
|
||||||
|
def index
|
||||||
def index
|
render json: session
|
||||||
render json: session
|
end
|
||||||
end
|
|
||||||
|
# 其他平台同步注册的用户
|
||||||
# 其他平台同步注册的用户
|
def remote_register
|
||||||
def remote_register
|
Register::RemoteForm.new(remote_register_params).validate!
|
||||||
username = params[:username]&.gsub(/\s+/, "")
|
username = params[:username]&.gsub(/\s+/, "")
|
||||||
email = params[:email]&.gsub(/\s+/, "")
|
tip_exception("无法使用以下关键词:#{username},请重新命名") if ReversedKeyword.check_exists?(username)
|
||||||
password = params[:password]
|
email = params[:email]&.gsub(/\s+/, "")
|
||||||
platform = (params[:platform] || 'forge')&.gsub(/\s+/, "")
|
password = params[:password]
|
||||||
|
platform = (params[:platform] || 'forge')&.gsub(/\s+/, "")
|
||||||
ActiveRecord::Base.transaction do
|
|
||||||
result = autologin_register(username, email, password, platform)
|
ActiveRecord::Base.transaction do
|
||||||
if result[:message].blank?
|
result = autologin_register(username, email, password, platform)
|
||||||
render_ok({user: result[:user]})
|
if result[:message].blank?
|
||||||
else
|
render_ok({user: result[:user]})
|
||||||
render_error(result[:message])
|
else
|
||||||
end
|
render_error(result[:message])
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
end
|
||||||
uid_logger_error(e.message)
|
rescue Exception => e
|
||||||
tip_exception(-1, e.message)
|
uid_logger_error(e.message)
|
||||||
end
|
tip_exception(-1, e.message)
|
||||||
|
end
|
||||||
# 其他平台修改用户的信息,这边同步修改
|
|
||||||
def remote_update
|
# 其他平台修改用户的信息,这边同步修改
|
||||||
ActiveRecord::Base.transaction do
|
def remote_update
|
||||||
user_params = params[:user_params]
|
ActiveRecord::Base.transaction do
|
||||||
user_extension_params = params[:user_extension_params]
|
user_params = params[:user_params]
|
||||||
|
user_extension_params = params[:user_extension_params]
|
||||||
u = User.find_by(login: params[:old_user_login])
|
|
||||||
user_mail = u.try(:mail)
|
u = User.find_by(login: params[:old_user_login])
|
||||||
|
user_mail = u.try(:mail)
|
||||||
if u.present?
|
|
||||||
ue = u.user_extension
|
if u.present?
|
||||||
u.login = user_params["login"] if user_params["login"]
|
ue = u.user_extension
|
||||||
u.mail = user_params["mail"] if user_params["mail"]
|
u.login = user_params["login"] if user_params["login"]
|
||||||
u.lastname = user_params["lastname"] if user_params["lastname"]
|
u.mail = user_params["mail"] if user_params["mail"]
|
||||||
|
u.lastname = user_params["lastname"] if user_params["lastname"]
|
||||||
ue.gender = user_extension_params["gender"]
|
|
||||||
ue.school_id = user_extension_params["school_id"]
|
ue.gender = user_extension_params["gender"]
|
||||||
ue.location = user_extension_params["location"]
|
ue.school_id = user_extension_params["school_id"]
|
||||||
ue.location_city = user_extension_params["location_city"]
|
ue.location = user_extension_params["location"]
|
||||||
ue.identity = user_extension_params["identity"]
|
ue.location_city = user_extension_params["location_city"]
|
||||||
ue.technical_title = user_extension_params["technical_title"]
|
ue.identity = user_extension_params["identity"]
|
||||||
ue.student_id = user_extension_params["student_id"]
|
ue.technical_title = user_extension_params["technical_title"]
|
||||||
ue.description = user_extension_params["description"]
|
ue.student_id = user_extension_params["student_id"]
|
||||||
ue.save!
|
ue.description = user_extension_params["description"]
|
||||||
u.save!
|
ue.save!
|
||||||
|
u.save!
|
||||||
sync_params = {}
|
|
||||||
|
sync_params = {}
|
||||||
if (user_params["mail"] && user_params["mail"] != user_mail)
|
|
||||||
sync_params = sync_params.merge(email: user_params["mail"])
|
if (user_params["mail"] && user_params["mail"] != user_mail)
|
||||||
end
|
sync_params = sync_params.merge(email: user_params["mail"])
|
||||||
|
end
|
||||||
if sync_params.present?
|
|
||||||
interactor = Gitea::User::UpdateInteractor.call(u.login, sync_params)
|
if sync_params.present?
|
||||||
if interactor.success?
|
interactor = Gitea::User::UpdateInteractor.call(u.login, sync_params)
|
||||||
render_ok
|
if interactor.success?
|
||||||
else
|
render_ok
|
||||||
render_error(interactor.error)
|
else
|
||||||
end
|
render_error(interactor.error)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
end
|
||||||
uid_logger_error(e.message)
|
rescue Exception => e
|
||||||
tip_exception(-1, e.message)
|
uid_logger_error(e.message)
|
||||||
end
|
tip_exception(-1, e.message)
|
||||||
|
end
|
||||||
# 其他平台同步登录
|
|
||||||
def remote_login
|
# 其他平台同步登录
|
||||||
@user = User.try_to_login(params[:login], params[:password])
|
def remote_login
|
||||||
if @user
|
@user = User.try_to_login(params[:login], params[:password])
|
||||||
successful_authentication(@user)
|
if @user
|
||||||
render_ok({user: {id: @user.id, token: @user.gitea_token}})
|
successful_authentication(@user)
|
||||||
else
|
render_ok({user: {id: @user.id, token: @user.gitea_token}})
|
||||||
render_error("用户不存在")
|
else
|
||||||
end
|
render_error("用户不存在")
|
||||||
end
|
end
|
||||||
|
end
|
||||||
#修改密码
|
|
||||||
def remote_password
|
#修改密码
|
||||||
@user = User.find_by(login: params[:login])
|
def remote_password
|
||||||
return render_error("未找到相关用户!") if @user.blank?
|
@user = User.find_by(login: params[:login])
|
||||||
|
return render_error("未找到相关用户!") if @user.blank?
|
||||||
sync_params = {
|
|
||||||
password: params[:password].to_s,
|
sync_params = {
|
||||||
email: @user.mail
|
password: params[:password].to_s,
|
||||||
}
|
email: @user.mail
|
||||||
|
}
|
||||||
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
|
||||||
if interactor.success?
|
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
||||||
@user.update_attribute(:password, params[:password])
|
if interactor.success?
|
||||||
render_ok
|
@user.update_attribute(:password, params[:password])
|
||||||
else
|
render_ok
|
||||||
render_error(interactor.error)
|
else
|
||||||
end
|
render_error(interactor.error)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
# 用户注册
|
|
||||||
# 注意:用户注册需要兼顾本地版,本地版是不需要验证码及激活码以及使用授权的,注册完成即可使用
|
# 用户注册
|
||||||
# params[:login] 邮箱或者手机号
|
# 注意:用户注册需要兼顾本地版,本地版是不需要验证码及激活码以及使用授权的,注册完成即可使用
|
||||||
# params[:code] 验证码
|
# params[:login] 邮箱或者手机号
|
||||||
# code_type 1:注册手机验证码 8:邮箱注册验证码
|
# params[:namespace] 登录名
|
||||||
# 本地forge注册入口
|
# params[:code] 验证码
|
||||||
def register
|
# code_type 1:注册手机验证码 8:邮箱注册验证码
|
||||||
begin
|
# 本地forge注册入口需要重新更改逻辑
|
||||||
# 查询验证码是否正确;type只可能是1或者8
|
def register
|
||||||
type = phone_mail_type(params[:login].strip)
|
# type只可能是1或者8
|
||||||
# code = params[:code].strip
|
user = nil
|
||||||
|
begin
|
||||||
if type == 1
|
Register::Form.new(register_params).validate!
|
||||||
uid_logger("start register by phone: type is #{type}")
|
|
||||||
pre = 'p'
|
user = Users::RegisterService.call(register_params)
|
||||||
email = nil
|
password = register_params[:password].strip
|
||||||
phone = params[:login]
|
|
||||||
# verifi_code = VerificationCode.where(phone: phone, code: code, code_type: 1).last
|
# gitea用户注册, email, username, password
|
||||||
# TODO: 暂时限定邮箱注册
|
interactor = Gitea::RegisterInteractor.call({username: user.login, email: user.mail, password: password})
|
||||||
return normal_status(-1, '只支持邮箱注册')
|
if interactor.success?
|
||||||
else
|
gitea_user = interactor.result
|
||||||
uid_logger("start register by email: type is #{type}")
|
result = Gitea::User::GenerateTokenService.call(user.login, password)
|
||||||
pre = 'm'
|
user.gitea_token = result['sha1']
|
||||||
email = params[:login]
|
user.gitea_uid = gitea_user[:body]['id']
|
||||||
phone = nil
|
if user.save!
|
||||||
return normal_status(-1, "该邮箱已注册") if User.exists?(mail: params[:login])
|
UserExtension.create!(user_id: user.id)
|
||||||
return normal_status(-1, "邮箱格式错误") unless params[:login] =~ CustomRegexp::EMAIL
|
successful_authentication(user)
|
||||||
# verifi_code = VerificationCode.where(email: email, code: code, code_type: 8).last
|
render_ok
|
||||||
end
|
end
|
||||||
# uid_logger("start register: verifi_code is #{verifi_code}, code is #{code}, time is #{Time.now.to_i - verifi_code.try(:created_at).to_i}")
|
else
|
||||||
# check_code = (verifi_code.try(:code) == code.strip && (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60)
|
tip_exception(-1, interactor.error)
|
||||||
# todo 上线前请删除万能验证码"513231"
|
end
|
||||||
return normal_status(-1, "8~16位密码,支持字母数字和符号") unless params[:password] =~ CustomRegexp::PASSWORD
|
rescue Register::BaseForm::EmailError => e
|
||||||
|
render_result(-2, e.message)
|
||||||
code = generate_identifier User, 8, pre
|
rescue Register::BaseForm::LoginError => e
|
||||||
login = pre + code
|
render_result(-3, e.message)
|
||||||
@user = User.new(admin: false, login: login, mail: email, phone: phone, type: "User")
|
rescue Register::BaseForm::PhoneError => e
|
||||||
@user.password = params[:password]
|
render_result(-4, e.message)
|
||||||
# 现在因为是验证码,所以在注册的时候就可以激活
|
rescue Register::BaseForm::PasswordFormatError => e
|
||||||
@user.activate
|
render_result(-5, e.message)
|
||||||
# 必须要用save操作,密码的保存是在users中
|
rescue Register::BaseForm::PasswordConfirmationError => e
|
||||||
|
render_result(-7, e.message)
|
||||||
interactor = Gitea::RegisterInteractor.call({username: login, email: email, password: params[:password]})
|
rescue Register::BaseForm::VerifiCodeError => e
|
||||||
if interactor.success?
|
render_result(-6, e.message)
|
||||||
gitea_user = interactor.result
|
rescue Exception => e
|
||||||
result = Gitea::User::GenerateTokenService.new(login, params[:password]).call
|
Gitea::User::DeleteService.call(user.login) unless user.nil?
|
||||||
@user.gitea_token = result['sha1']
|
uid_logger_error(e.message)
|
||||||
@user.gitea_uid = gitea_user[:body]['id']
|
tip_exception(-1, e.message)
|
||||||
if @user.save!
|
end
|
||||||
UserExtension.create!(user_id: @user.id)
|
end
|
||||||
successful_authentication(@user)
|
|
||||||
normal_status("注册成功")
|
# 用户登录
|
||||||
end
|
def login
|
||||||
else
|
Users::LoginForm.new(login_params).validate!
|
||||||
tip_exception(-1, interactor.error)
|
@user = User.try_to_login(params[:login], params[:password])
|
||||||
end
|
|
||||||
rescue Exception => e
|
return normal_status(-2, "错误的账号或密码") if @user.blank?
|
||||||
uid_logger_error(e.message)
|
# user is already in local database
|
||||||
tip_exception(-1, e.message)
|
return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked?
|
||||||
end
|
|
||||||
end
|
login_control = LimitForbidControl::UserLogin.new(@user)
|
||||||
|
return normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码") if login_control.forbid?
|
||||||
# 用户登录
|
|
||||||
def login
|
password_ok = @user.check_password?(params[:password].to_s)
|
||||||
Users::LoginForm.new(account_params).validate!
|
unless password_ok
|
||||||
@user = User.try_to_login(params[:login], params[:password])
|
if login_control.remain_times-1 == 0
|
||||||
|
normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码")
|
||||||
return normal_status(-2, "错误的账号或密码") if @user.blank?
|
else
|
||||||
# user is already in local database
|
normal_status(-2, "你已经输错密码#{login_control.error_times+1}次,还剩余#{login_control.remain_times-1}次机会")
|
||||||
return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked?
|
end
|
||||||
|
login_control.increment!
|
||||||
login_control = LimitForbidControl::UserLogin.new(@user)
|
return
|
||||||
return normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码") if login_control.forbid?
|
end
|
||||||
|
|
||||||
password_ok = @user.check_password?(params[:password].to_s)
|
successful_authentication(@user)
|
||||||
unless password_ok
|
sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步
|
||||||
if login_control.remain_times-1 == 0
|
|
||||||
normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码")
|
# session[:user_id] = @user.id
|
||||||
else
|
end
|
||||||
normal_status(-2, "你已经输错密码#{login_control.error_times+1}次,还剩余#{login_control.remain_times-1}次机会")
|
|
||||||
end
|
def change_password
|
||||||
login_control.increment!
|
@user = User.find_by(login: params[:login])
|
||||||
return
|
return render_error("未找到相关用户!") if @user.blank?
|
||||||
end
|
return render_error("旧密码不正确") unless @user.check_password?(params[:old_password])
|
||||||
|
|
||||||
successful_authentication(@user)
|
sync_params = {
|
||||||
sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步
|
password: params[:password].to_s,
|
||||||
|
email: @user.mail,
|
||||||
# session[:user_id] = @user.id
|
login_name: @user.name,
|
||||||
end
|
source_id: 0
|
||||||
|
}
|
||||||
# 忘记密码
|
|
||||||
def reset_password
|
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
||||||
begin
|
if interactor.success?
|
||||||
code = params[:code]
|
@user.update_attribute(:password, params[:password])
|
||||||
login_type = phone_mail_type(params[:login].strip)
|
render_ok
|
||||||
# 获取验证码
|
else
|
||||||
if login_type == 1
|
render_error(interactor.error)
|
||||||
phone = params[:login]
|
end
|
||||||
verifi_code = VerificationCode.where(phone: phone, code: code, code_type: 2).last
|
end
|
||||||
user = User.find_by_phone(phone)
|
|
||||||
else
|
# 忘记密码
|
||||||
email = params[:login]
|
def reset_password
|
||||||
verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last
|
begin
|
||||||
user = User.find_by_mail(email) #这里有问题,应该是为email,而不是mail 6.13-hs
|
Accounts::ResetPasswordForm.new(reset_password_params).validate!
|
||||||
end
|
|
||||||
return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
|
user = find_user
|
||||||
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
|
return render_error('未找到相关账号') if user.blank?
|
||||||
return normal_status(-1, "8~16位密码,支持字母数字和符号") unless params[:new_password] =~ CustomRegexp::PASSWORD
|
|
||||||
|
user = Accounts::ResetPasswordService.call(user, reset_password_params)
|
||||||
user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
LimitForbidControl::UserLogin.new(user).clear if user.save!
|
||||||
ActiveRecord::Base.transaction do
|
|
||||||
user.save!
|
render_ok
|
||||||
LimitForbidControl::UserLogin.new(user).clear
|
rescue Register::BaseForm::EmailError => e
|
||||||
end
|
render_result(-2, e.message)
|
||||||
sucess_status
|
rescue Register::BaseForm::PhoneError => e
|
||||||
rescue Exception => e
|
render_result(-4, e.message)
|
||||||
uid_logger_error(e.message)
|
rescue Register::BaseForm::PasswordFormatError => e
|
||||||
tip_exception(e.message)
|
render_result(-5, e.message)
|
||||||
end
|
rescue Register::BaseForm::PasswordConfirmationError => e
|
||||||
end
|
render_result(-7, e.message)
|
||||||
|
rescue Register::BaseForm::VerifiCodeError => e
|
||||||
def successful_authentication(user)
|
render_result(-6, e.message)
|
||||||
uid_logger("Successful authentication start: '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}")
|
rescue ActiveRecord::Rollback => e
|
||||||
# Valid user
|
render_result(-1, "服务器异常")
|
||||||
self.logged_user = user
|
rescue Exception => e
|
||||||
# generate a key and set cookie if autologin
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
set_autologin_cookie(user)
|
end
|
||||||
UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id), :ip => request.remote_ip)
|
end
|
||||||
user.update_column(:last_login_on, Time.now)
|
|
||||||
session[:"#{default_yun_session}"] = user.id
|
def successful_authentication(user)
|
||||||
Rails.logger.info("#########_____session_default_yun_session__________###############{default_yun_session}")
|
uid_logger("Successful authentication start: '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}")
|
||||||
# 注册完成后有一天的试用申请(先去掉)
|
# Valid user
|
||||||
# UserDayCertification.create(user_id: user.id, status: 1)
|
self.logged_user = user
|
||||||
end
|
# generate a key and set cookie if autologin
|
||||||
|
|
||||||
def set_autologin_cookie(user)
|
set_autologin_cookie(user)
|
||||||
token = Token.get_or_create_permanent_login_token(user, "autologin")
|
UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id), :ip => request.remote_ip)
|
||||||
sync_user_token_to_trustie(user.login, token.value)
|
user.update_column(:last_login_on, Time.now)
|
||||||
|
session[:"#{default_yun_session}"] = user.id
|
||||||
cookie_options = {
|
Rails.logger.info("#########_____session_default_yun_session__________###############{default_yun_session}")
|
||||||
:value => token.value,
|
# 注册完成后有一天的试用申请(先去掉)
|
||||||
:expires => 1.month.from_now,
|
# UserDayCertification.create(user_id: user.id, status: 1)
|
||||||
:path => '/',
|
end
|
||||||
:secure => false,
|
|
||||||
:httponly => true
|
def set_autologin_cookie(user)
|
||||||
}
|
token = Token.get_or_create_permanent_login_token(user, "autologin")
|
||||||
if edu_setting('cookie_domain').present?
|
# sync_user_token_to_trustie(user.login, token.value)
|
||||||
cookie_options = cookie_options.merge(domain: edu_setting('cookie_domain'))
|
|
||||||
end
|
cookie_options = {
|
||||||
cookies[autologin_cookie_name] = cookie_options
|
:value => token.value,
|
||||||
cookies.signed[:user_id] ||= user.id
|
:expires => 1.month.from_now,
|
||||||
|
:path => '/',
|
||||||
logger.info("cookies is #{cookies} ======> #{cookies.signed[:user_id]} =====> #{cookies[autologin_cookie_name]}")
|
:secure => false,
|
||||||
end
|
:httponly => true
|
||||||
|
}
|
||||||
def logout
|
if edu_setting('cookie_domain').present?
|
||||||
Rails.logger.info("########___logout_current_user____________########{current_user.try(:id)}")
|
cookie_options = cookie_options.merge(domain: edu_setting('cookie_domain'))
|
||||||
UserAction.create(action_id: User.current.id, action_type: "Logout", user_id: User.current.id, :ip => request.remote_ip)
|
end
|
||||||
logout_user
|
cookies[autologin_cookie_name] = cookie_options
|
||||||
render :json => {status: 1, message: "退出成功!"}
|
cookies.signed[:user_id] ||= user.id
|
||||||
end
|
|
||||||
|
logger.info("cookies is #{cookies} ======> #{cookies.signed[:user_id]} =====> #{cookies[autologin_cookie_name]}")
|
||||||
# 检验邮箱是否已被注册及邮箱或者手机号是否合法
|
end
|
||||||
# 参数type为事件类型 1:注册;2:忘记密码;3:绑定
|
|
||||||
def valid_email_and_phone
|
def logout
|
||||||
check_mail_and_phone_valid(params[:login], params[:type])
|
Rails.logger.info("########___logout_current_user____________########{current_user.try(:id)}")
|
||||||
end
|
UserAction.create(action_id: User.current.id, action_type: "Logout", user_id: User.current.id, :ip => request.remote_ip)
|
||||||
|
logout_user
|
||||||
# 发送验证码
|
render :json => {status: 1, message: "退出成功!"}
|
||||||
# params[:login] 手机号或者邮箱号
|
end
|
||||||
# params[:type]为事件通知类型 1:用户注册注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验收手机号有效 # 如果有新的继续后面加
|
|
||||||
# 发送验证码:send_type 1:注册手机验证码 2:找回密码手机验证码 3:找回密码邮箱验证码 4:绑定手机 5:绑定邮箱
|
# 检验邮箱是否已被注册及邮箱或者手机号是否合法
|
||||||
# 6:手机验证码登录 7:邮箱验证码登录 8:邮箱注册验证码 9: 验收手机号有效
|
# 参数type为事件类型 1:注册;2:忘记密码;3:绑定
|
||||||
def get_verification_code
|
def valid_email_and_phone
|
||||||
code = %W(0 1 2 3 4 5 6 7 8 9)
|
check_mail_and_phone_valid(params[:login], params[:type])
|
||||||
value = params[:login]
|
end
|
||||||
type = params[:type].strip.to_i
|
|
||||||
login_type = phone_mail_type(value)
|
# 发送验证码
|
||||||
send_type = verify_type(login_type, type)
|
# params[:login] 手机号或者邮箱号
|
||||||
verification_code = code.sample(6).join
|
# params[:type]为事件通知类型 1:用户注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验收手机号有效 # 如果有新的继续后面加
|
||||||
|
# 发送验证码:send_type 1:注册手机验证码 2:找回密码手机验证码 3:找回密码邮箱验证码 4:绑定手机 5:绑定邮箱
|
||||||
sign = Digest::MD5.hexdigest("#{OPENKEY}#{value}")
|
# 6:手机验证码登录 7:邮箱验证码登录 8:邮箱注册验证码 9: 验收手机号有效
|
||||||
tip_exception(501, "请求不合理") if sign != params[:smscode]
|
def get_verification_code
|
||||||
|
code = %W(0 1 2 3 4 5 6 7 8 9)
|
||||||
logger.info("########get_verification_code: login_type: #{login_type}, send_type:#{send_type}, ")
|
value = params[:login]
|
||||||
|
type = params[:type].strip.to_i
|
||||||
# 记录验证码
|
login_type = phone_mail_type(value)
|
||||||
check_verification_code(verification_code, send_type, value)
|
send_type = verify_type(login_type, type)
|
||||||
sucess_status
|
verification_code = code.sample(6).join
|
||||||
end
|
|
||||||
|
sign = Digest::MD5.hexdigest("#{OPENKEY}#{value}")
|
||||||
# 1 手机类型;0 邮箱类型
|
tip_exception(501, "请求不合理") if sign != params[:smscode]
|
||||||
# 注意新版的login是自动名生成的
|
|
||||||
def phone_mail_type value
|
logger.info "########### 验证码:#{verification_code}"
|
||||||
value =~ /^1\d{10}$/ ? 1 : 0
|
logger.info("########get_verification_code: login_type: #{login_type}, send_type:#{send_type}, ")
|
||||||
end
|
|
||||||
|
# 记录验证码
|
||||||
private
|
check_verification_code(verification_code, send_type, value)
|
||||||
|
render_ok
|
||||||
# type 事件类型 1:用户注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验证手机号是否有效 # 如果有新的继续后面加
|
end
|
||||||
# login_type 1:手机类型 2:邮箱类型
|
|
||||||
def verify_type login_type, type
|
# check user's login or email or phone is used
|
||||||
case type
|
# params[:value] 手机号或者邮箱号或者登录名
|
||||||
when 1
|
# params[:type] 为事件类型 1:登录名(login) 2:email(邮箱) 3:phone(手机号)
|
||||||
login_type == 1 ? 1 : 8
|
def check
|
||||||
when 2
|
Register::CheckColumnsForm.new(check_params).validate!
|
||||||
login_type == 1 ? 2 : 3
|
render_ok
|
||||||
when 3
|
end
|
||||||
login_type == 1 ? 4 : tip_exception('请填写正确的手机号')
|
|
||||||
when 4
|
private
|
||||||
login_type == 1 ? tip_exception('请填写正确的邮箱') : 5
|
|
||||||
when 5
|
# type 事件类型 1:用户注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验证手机号是否有效 # 如果有新的继续后面加
|
||||||
login_type == 1 ? 9 : tip_exception('请填写正确的手机号')
|
# login_type 1:手机类型 2:邮箱类型
|
||||||
end
|
def verify_type login_type, type
|
||||||
end
|
case type
|
||||||
|
when 1
|
||||||
def generate_login(login)
|
login_type == 1 ? 1 : 8
|
||||||
type = phone_mail_type(login.strip)
|
when 2
|
||||||
|
login_type == 1 ? 2 : 3
|
||||||
if type == 1
|
when 3
|
||||||
uid_logger("start register by phone: type is #{type}")
|
login_type == 1 ? 4 : tip_exception('请填写正确的手机号')
|
||||||
pre = 'p'
|
when 4
|
||||||
email = nil
|
login_type == 1 ? tip_exception('请填写正确的邮箱') : 5
|
||||||
phone = login
|
when 5
|
||||||
else
|
login_type == 1 ? 9 : tip_exception('请填写正确的手机号')
|
||||||
uid_logger("start register by email: type is #{type}")
|
end
|
||||||
pre = 'm'
|
end
|
||||||
email = login
|
|
||||||
phone = nil
|
def generate_login(login)
|
||||||
end
|
type = phone_mail_type(login.strip)
|
||||||
code = generate_identifier User, 8, pre
|
|
||||||
|
if type == 1
|
||||||
{ login: pre + code, email: email, phone: phone }
|
uid_logger("start register by phone: type is #{type}")
|
||||||
end
|
pre = 'p'
|
||||||
|
email = nil
|
||||||
def user_params
|
phone = login
|
||||||
params.require(:user).permit(:login, :email, :phone)
|
else
|
||||||
end
|
uid_logger("start register by email: type is #{type}")
|
||||||
|
pre = 'm'
|
||||||
def account_params
|
email = login
|
||||||
params.require(:account).permit(:login, :password)
|
phone = nil
|
||||||
end
|
end
|
||||||
end
|
code = generate_identifier User, 8, pre
|
||||||
|
|
||||||
|
{ login: pre + code, email: email, phone: phone }
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_params
|
||||||
|
params.require(:user).permit(:login, :email, :phone)
|
||||||
|
end
|
||||||
|
|
||||||
|
def login_params
|
||||||
|
params.require(:account).permit(:login, :password)
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_params
|
||||||
|
params.permit(:type, :value)
|
||||||
|
end
|
||||||
|
|
||||||
|
def register_params
|
||||||
|
params.permit(:login, :namespace, :password, :password_confirmation, :code)
|
||||||
|
end
|
||||||
|
|
||||||
|
def reset_password_params
|
||||||
|
params.permit(:login, :password, :password_confirmation, :code)
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_user
|
||||||
|
phone_or_mail = strip(reset_password_params[:login])
|
||||||
|
User.where("phone = :search OR mail = :search", search: phone_or_mail).last
|
||||||
|
end
|
||||||
|
|
||||||
|
def remote_register_params
|
||||||
|
params.permit(:username, :email, :password, :platform)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
|
@ -32,7 +32,7 @@ class Admins::AuthSchoolsController < Admins::BaseController
|
||||||
def search_manager
|
def search_manager
|
||||||
school = School.find_by(id: params[:school_id])
|
school = School.find_by(id: params[:school_id])
|
||||||
user_ids = school&.ec_school_users&.pluck(:user_id)
|
user_ids = school&.ec_school_users&.pluck(:user_id)
|
||||||
@users = User.where.not(id: user_ids).where("concat(lastname, firstname) like ?", "%#{params[:name].strip.to_s}%").limit(10)
|
@users = User.where.not(id: user_ids).where("CONCAT(lastname, firstname) like ? OR nickname like ?", "%#{params[:name].strip.to_s}%", "%#{params[:name].strip.to_s}%").limit(10)
|
||||||
end
|
end
|
||||||
|
|
||||||
# 添加认证学校管理员
|
# 添加认证学校管理员
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
class Admins::EduSettingsController < Admins::BaseController
|
||||||
|
before_action :find_setting, only: [:edit,:update, :destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
default_sort('id', 'desc')
|
||||||
|
|
||||||
|
edu_settings = Admins::EduSettingQuery.call(params)
|
||||||
|
@edu_settings = paginate edu_settings
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@edu_setting = EduSetting.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@edu_setting = EduSetting.new(edu_setting_params)
|
||||||
|
if @edu_setting.save
|
||||||
|
redirect_to admins_edu_settings_path
|
||||||
|
flash[:success] = '创建成功'
|
||||||
|
else
|
||||||
|
redirect_to admins_edu_settings_path
|
||||||
|
flash[:danger] = @edu_setting.errors.full_messages.join(",")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @edu_setting.update!(edu_setting_params)
|
||||||
|
flash[:success] = '更新成功'
|
||||||
|
else
|
||||||
|
flash[:danger] = @edu_setting.errors.full_messages.join(",")
|
||||||
|
end
|
||||||
|
redirect_to admins_edu_settings_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @edu_setting.destroy!
|
||||||
|
flash[:success] = '删除成功'
|
||||||
|
else
|
||||||
|
lash[:danger] = '删除失败'
|
||||||
|
end
|
||||||
|
redirect_to admins_edu_settings_path
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_setting
|
||||||
|
@edu_setting ||= EduSetting.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def edu_setting_params
|
||||||
|
params.require(:edu_setting).permit(:name, :value, :description)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,58 @@
|
||||||
|
class Admins::FaqsController < Admins::BaseController
|
||||||
|
before_action :find_faq, only: [:edit,:update, :destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
sort_by = Faq.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'updated_at'
|
||||||
|
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||||
|
|
||||||
|
keyword = params[:keyword].to_s.strip
|
||||||
|
collection = Faq.search_question(keyword).order("#{sort_by} #{sort_direction}")
|
||||||
|
@faqs = paginate collection
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@faq = Faq.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
begin
|
||||||
|
@faq.update!(faq_params)
|
||||||
|
flash[:success] = '修改成功'
|
||||||
|
rescue Exception
|
||||||
|
flash[:danger] = @faq.errors.full_messages.to_sentence
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to admins_faqs_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@faq.destroy
|
||||||
|
|
||||||
|
redirect_to admins_faqs_path
|
||||||
|
flash[:success] = "删除成功"
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@faq = Faq.new(faq_params)
|
||||||
|
begin
|
||||||
|
@faq.save!
|
||||||
|
flash[:success] = '创建成功'
|
||||||
|
rescue Exception
|
||||||
|
flash[:danger] = @faq.errors.full_messages.to_sentence
|
||||||
|
end
|
||||||
|
redirect_to admins_faqs_path
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_faq
|
||||||
|
@faq = Faq.find params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def faq_params
|
||||||
|
params.require(:faq).permit(:question, :url)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -33,7 +33,7 @@ class Admins::LaboratoriesController < Admins::BaseController
|
||||||
keyword = params[:keyword].to_s.strip
|
keyword = params[:keyword].to_s.strip
|
||||||
if keyword.present?
|
if keyword.present?
|
||||||
like_sql = 'shixuns.name LIKE :keyword OR CONCAT(users.lastname, users.firstname) LIKE :keyword '\
|
like_sql = 'shixuns.name LIKE :keyword OR CONCAT(users.lastname, users.firstname) LIKE :keyword '\
|
||||||
'OR mirror_repositories.name LIKE :keyword'
|
'users.nickname LIKE :keyword OR mirror_repositories.name LIKE :keyword'
|
||||||
shixuns = shixuns.joins(:user, :mirror_repositories).where(like_sql, keyword: "%#{keyword}%")
|
shixuns = shixuns.joins(:user, :mirror_repositories).where(like_sql, keyword: "%#{keyword}%")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ class Admins::LaboratoriesController < Admins::BaseController
|
||||||
|
|
||||||
keyword = params[:keyword].to_s.strip
|
keyword = params[:keyword].to_s.strip
|
||||||
if keyword.present?
|
if keyword.present?
|
||||||
like_sql = 'subjects.name LIKE :keyword OR CONCAT(users.lastname, users.firstname) LIKE :keyword'
|
like_sql = 'subjects.name LIKE :keyword OR CONCAT(users.lastname, users.firstname) LIKE :keyword OR users.nickname LIKE :keyword'
|
||||||
subjects = subjects.joins(:user).where(like_sql, keyword: "%#{keyword}%")
|
subjects = subjects.joins(:user).where(like_sql, keyword: "%#{keyword}%")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
class Admins::MessageTemplatesController < Admins::BaseController
|
||||||
|
before_action :get_template, only: [:edit, :update, :destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
message_templates = MessageTemplate.group(:type).count.keys
|
||||||
|
@message_templates = kaminari_array_paginate(message_templates)
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @message_template.update_attributes(message_template_params)
|
||||||
|
redirect_to admins_message_templates_path
|
||||||
|
flash[:success] = '消息模版更新成功'
|
||||||
|
else
|
||||||
|
redirect_to admins_message_templates_path
|
||||||
|
flash[:danger] = @message_template.errors.full_messages.join(",")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def init_data
|
||||||
|
if MessageTemplate.build_init_data
|
||||||
|
redirect_to admins_message_templates_path
|
||||||
|
flash[:success] = '消息模版初始化成功'
|
||||||
|
else
|
||||||
|
redirect_to admins_message_templates_path
|
||||||
|
flash[:danger] = '消息模版初始化失败'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def message_template_params
|
||||||
|
params.require(@message_template.type.split("::").join("_").underscore.to_sym).permit!
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_template
|
||||||
|
@message_template = MessageTemplate.find_by(id: params[:id])
|
||||||
|
unless @message_template.present?
|
||||||
|
redirect_to admins_message_templates_path
|
||||||
|
flash[:danger] = "消息模版不存在"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,8 +3,8 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
||||||
before_action :validate_names, only: [:create, :update]
|
before_action :validate_names, only: [:create, :update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
sort_by = params[:sort_by] ||= 'created_at'
|
sort_by = ProjectCategory.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||||
sort_direction = params[:sort_direction] ||= 'desc'
|
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||||
q = ProjectCategory.ransack(name_cont: params[:name])
|
q = ProjectCategory.ransack(name_cont: params[:name])
|
||||||
project_categories = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
project_categories = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||||
@project_categories = paginate(project_categories)
|
@project_categories = paginate(project_categories)
|
||||||
|
@ -22,7 +22,7 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
||||||
max_position_items = ProjectCategory.select(:id, :position).pluck(:position).reject!(&:blank?)
|
max_position_items = ProjectCategory.select(:id, :position).pluck(:position).reject!(&:blank?)
|
||||||
max_position = max_position_items.present? ? max_position_items.max.to_i : 0
|
max_position = max_position_items.present? ? max_position_items.max.to_i : 0
|
||||||
|
|
||||||
@project_category = ProjectCategory.new(name: @name,position: max_position)
|
@project_category = ProjectCategory.new(name: @name,position: max_position, pinned_index: params[:project_category][:pinned_index].to_i)
|
||||||
if @project_category.save
|
if @project_category.save
|
||||||
redirect_to admins_project_categories_path
|
redirect_to admins_project_categories_path
|
||||||
flash[:success] = '创建成功'
|
flash[:success] = '创建成功'
|
||||||
|
@ -33,17 +33,18 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
if @project_category.update_attribute(:name, @name)
|
if @project_category.update_attributes({name: @name, pinned_index: params[:project_category][:pinned_index].to_i})
|
||||||
|
save_image_file(params[:logo], 'logo')
|
||||||
redirect_to admins_project_categories_path
|
redirect_to admins_project_categories_path
|
||||||
flash[:success] = '更新成功'
|
flash[:success] = '更新成功'
|
||||||
else
|
else
|
||||||
redirect_to admins_project_categories_path
|
redirect_to admins_project_categories_path
|
||||||
flash[:success] = '更新失败'
|
flash[:danger] = '更新失败'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
if @project_language.destroy
|
if @project_category.destroy
|
||||||
redirect_to admins_project_categories_path
|
redirect_to admins_project_categories_path
|
||||||
flash[:success] = "删除成功"
|
flash[:success] = "删除成功"
|
||||||
else
|
else
|
||||||
|
@ -80,4 +81,12 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
||||||
flash[:danger] = '分类已存在'
|
flash[:danger] = '分类已存在'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def save_image_file(file, type)
|
||||||
|
return unless file.present? && file.is_a?(ActionDispatch::Http::UploadedFile)
|
||||||
|
|
||||||
|
file_path = Util::FileManage.source_disk_filename(@project_category, type)
|
||||||
|
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
|
||||||
|
Util.write_file(file, file_path)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -3,8 +3,8 @@ class Admins::ProjectIgnoresController < Admins::BaseController
|
||||||
before_action :validate_params, only: [:create, :update]
|
before_action :validate_params, only: [:create, :update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
sort_by = params[:sort_by] ||= 'created_at'
|
sort_by = Ignore.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||||
sort_direction = params[:sort_direction] ||= 'desc'
|
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||||
q = Ignore.ransack(name_cont: params[:search])
|
q = Ignore.ransack(name_cont: params[:search])
|
||||||
project_ignores = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
project_ignores = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||||
@project_ignores = paginate(project_ignores)
|
@project_ignores = paginate(project_ignores)
|
||||||
|
|
|
@ -3,8 +3,8 @@ class Admins::ProjectLanguagesController < Admins::BaseController
|
||||||
before_action :validate_names, only: [:create, :update]
|
before_action :validate_names, only: [:create, :update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
sort_by = params[:sort_by] ||= 'created_at'
|
sort_by = ProjectLanguage.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||||
sort_direction = params[:sort_direction] ||= 'desc'
|
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||||
q = ProjectLanguage.ransack(name_cont: params[:search])
|
q = ProjectLanguage.ransack(name_cont: params[:search])
|
||||||
project_languages = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
project_languages = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||||
@project_languages = paginate(project_languages)
|
@project_languages = paginate(project_languages)
|
||||||
|
|
|
@ -3,8 +3,8 @@ class Admins::ProjectLicensesController < Admins::BaseController
|
||||||
before_action :validate_params, only: [:create, :update]
|
before_action :validate_params, only: [:create, :update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
sort_by = params[:sort_by] ||= 'created_at'
|
sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||||
sort_direction = params[:sort_direction] ||= 'desc'
|
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||||
q = License.ransack(name_cont: params[:search])
|
q = License.ransack(name_cont: params[:search])
|
||||||
project_licenses = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
project_licenses = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||||
@project_licenses = paginate(project_licenses)
|
@project_licenses = paginate(project_licenses)
|
||||||
|
|
|
@ -1,14 +1,34 @@
|
||||||
class Admins::ProjectsController < Admins::BaseController
|
class Admins::ProjectsController < Admins::BaseController
|
||||||
|
before_action :find_project, only: [:edit, :update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
sort_by = params[:sort_by] ||= 'created_on'
|
sort_by = Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_on'
|
||||||
sort_direction = params[:sort_direction] ||= 'desc'
|
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||||
|
|
||||||
search = params[:search].to_s.strip
|
search = params[:search].to_s.strip
|
||||||
projects = Project.where("name like ?", "%#{search}%").order("#{sort_by} #{sort_direction}")
|
projects = Project.where("name like ?", "%#{search}%").order("#{sort_by} #{sort_direction}")
|
||||||
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
|
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def edit ;end
|
||||||
|
|
||||||
|
def update
|
||||||
|
respond_to do |format|
|
||||||
|
if @project.update_attributes(project_update_params)
|
||||||
|
format.html do
|
||||||
|
redirect_to admins_projects_path
|
||||||
|
flash[:sucess] = "更新成功"
|
||||||
|
end
|
||||||
|
format.js {render_ok}
|
||||||
|
else
|
||||||
|
format.html do
|
||||||
|
redirect_to admins_projects_path
|
||||||
|
flash[:danger] = "更新失败"
|
||||||
|
end
|
||||||
|
format.js {render_js_error}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
project = Project.find_by!(id: params[:id])
|
project = Project.find_by!(id: params[:id])
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
|
@ -22,4 +42,13 @@ class Admins::ProjectsController < Admins::BaseController
|
||||||
redirect_to admins_projects_path
|
redirect_to admins_projects_path
|
||||||
flash[:danger] = "删除失败"
|
flash[:danger] = "删除失败"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_project
|
||||||
|
@project = Project.find_by_id(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def project_update_params
|
||||||
|
params.require(:project).permit(:is_pinned, :recommend, :recommend_index)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -0,0 +1,84 @@
|
||||||
|
class Admins::ReversedKeywordsController < Admins::BaseController
|
||||||
|
before_action :get_keyword, only: [:edit,:update, :destroy]
|
||||||
|
# before_action :validate_identifer, only: [:create, :update]
|
||||||
|
|
||||||
|
def index
|
||||||
|
sort_by = ReversedKeyword.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||||
|
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||||
|
q = ReversedKeyword.ransack(identifier_cont: params[:search])
|
||||||
|
keywords = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||||
|
@keywords = paginate(keywords)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@keyword = ReversedKeyword.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@keyword = ReversedKeyword.new(keyword_params)
|
||||||
|
if @keyword.save
|
||||||
|
redirect_to admins_reversed_keywords_path
|
||||||
|
flash[:success] = '系统保留关键词创建成功'
|
||||||
|
else
|
||||||
|
redirect_to admins_reversed_keywords_path
|
||||||
|
flash[:danger] = @keyword.errors.full_messages.join(",")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @keyword.update_attributes(keyword_params)
|
||||||
|
format.html do
|
||||||
|
redirect_to admins_reversed_keywords_path
|
||||||
|
flash[:success] = '系统保留关键词更新成功'
|
||||||
|
end
|
||||||
|
format.js {render_ok}
|
||||||
|
else
|
||||||
|
format.html do
|
||||||
|
redirect_to admins_reversed_keywords_path
|
||||||
|
flash[:danger] = @keyword.errors.full_messages.join(",")
|
||||||
|
end
|
||||||
|
format.js {render_js_error}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @keyword.destroy
|
||||||
|
redirect_to admins_reversed_keywords_path
|
||||||
|
flash[:success] = "系统保留关键词删除成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_reversed_keywords_path
|
||||||
|
flash[:danger] = "系统保留关键词删除失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def keyword_params
|
||||||
|
params.require(:reversed_keyword).permit!
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_keyword
|
||||||
|
@keyword = ReversedKeyword.find_by(id: params[:id])
|
||||||
|
unless @keyword.present?
|
||||||
|
redirect_to admins_reversed_keywords_path
|
||||||
|
flash[:danger] = "系统保留关键词不存在"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def validate_identifer
|
||||||
|
identifer = keyword_params[:identifier].to_s.downcase
|
||||||
|
if identifer.blank?
|
||||||
|
redirect_to admins_reversed_keywords_path
|
||||||
|
flash[:danger] = '系统保留关键词标识不能为空'
|
||||||
|
elsif ProjectLanguage.exists?(name: identifer)
|
||||||
|
redirect_to admins_reversed_keywords_path
|
||||||
|
flash[:danger] = '系统保留关键词已存在'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,56 @@
|
||||||
|
class Admins::SitesController < Admins::BaseController
|
||||||
|
before_action :find_site, only: [:edit,:update, :destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
default_sort('id', 'desc')
|
||||||
|
|
||||||
|
sites = Admins::SiteQuery.call(params)
|
||||||
|
@sites = paginate sites
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@site = Site.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@site = Site.new(site_params)
|
||||||
|
if @site.save
|
||||||
|
redirect_to admins_sites_path
|
||||||
|
flash[:success] = '创建成功'
|
||||||
|
else
|
||||||
|
redirect_to admins_sites_path
|
||||||
|
flash[:danger] = @site.errors.full_messages.join(",")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @site.update!(site_params)
|
||||||
|
flash[:success] = '更新成功'
|
||||||
|
else
|
||||||
|
flash[:danger] = @site.errors.full_messages.join(",")
|
||||||
|
end
|
||||||
|
redirect_to admins_sites_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @site.destroy!
|
||||||
|
flash[:success] = '删除成功'
|
||||||
|
else
|
||||||
|
lash[:danger] = '删除失败'
|
||||||
|
end
|
||||||
|
redirect_to admins_sites_path
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_site
|
||||||
|
@site ||= Site.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def site_params
|
||||||
|
params.require(:site).permit(:name, :url, :key, :site_type)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,75 @@
|
||||||
|
class Admins::SystemNotificationsController < Admins::BaseController
|
||||||
|
before_action :get_notification, only: [:history, :edit,:update, :destroy]
|
||||||
|
# before_action :validate_identifer, only: [:create, :update]
|
||||||
|
|
||||||
|
def index
|
||||||
|
sort_by = SystemNotification.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||||
|
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||||
|
q = SystemNotification.ransack(subject_cont: params[:search])
|
||||||
|
notifications = q.result(distinct: true).reorder("#{sort_by} #{sort_direction},created_at desc")
|
||||||
|
@notifications = paginate(notifications)
|
||||||
|
end
|
||||||
|
|
||||||
|
def history
|
||||||
|
@users = @notification.users
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@notification = SystemNotification.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@notification = SystemNotification.new(notification_params)
|
||||||
|
if @notification.save
|
||||||
|
redirect_to admins_system_notifications_path
|
||||||
|
flash[:success] = '系统消息创建成功'
|
||||||
|
else
|
||||||
|
redirect_to admins_system_notifications_path
|
||||||
|
flash[:danger] = @notification.errors.full_messages.join(",")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
respond_to do |format|
|
||||||
|
if @notification.update_attributes(notification_params)
|
||||||
|
format.html do
|
||||||
|
redirect_to admins_system_notifications_path
|
||||||
|
flash[:success] = '系统消息更新成功'
|
||||||
|
end
|
||||||
|
format.js {render_ok}
|
||||||
|
else
|
||||||
|
format.html do
|
||||||
|
redirect_to admins_system_notifications_path
|
||||||
|
flash[:danger] = @notification.errors.full_messages.join(",")
|
||||||
|
end
|
||||||
|
format.js {render_js_error}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @notification.destroy
|
||||||
|
redirect_to admins_system_notifications_path
|
||||||
|
flash[:success] = "系统消息删除成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_system_notifications_path
|
||||||
|
flash[:danger] = "系统消息删除失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def notification_params
|
||||||
|
params.require(:system_notification).permit!
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_notification
|
||||||
|
@notification = SystemNotification.find_by(id: params[:id])
|
||||||
|
unless @notification.present?
|
||||||
|
redirect_to admins_system_notifications_path
|
||||||
|
flash[:danger] = "系统消息不存在"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,57 @@
|
||||||
|
class Admins::Topic::ActivityForumsController < Admins::Topic::BaseController
|
||||||
|
before_action :find_activity_forum, only: [:edit, :update, :destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
q = ::Topic::ActivityForum.ransack(title_cont: params[:search])
|
||||||
|
activity_forums = q.result(distinct: true)
|
||||||
|
@activity_forums = paginate(activity_forums)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@activity_forum = ::Topic::ActivityForum.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@activity_forum = ::Topic::ActivityForum.new(activity_forum_params)
|
||||||
|
if @activity_forum.save
|
||||||
|
redirect_to admins_topic_activity_forums_path
|
||||||
|
flash[:success] = "新增平台动态成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_activity_forums_path
|
||||||
|
flash[:danger] = "新增平台动态失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@activity_forum.attributes = activity_forum_params
|
||||||
|
if @activity_forum.save
|
||||||
|
redirect_to admins_topic_activity_forums_path
|
||||||
|
flash[:success] = "更新平台动态成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_activity_forums_path
|
||||||
|
flash[:danger] = "更新平台动态失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @activity_forum.destroy
|
||||||
|
redirect_to admins_topic_activity_forums_path
|
||||||
|
flash[:success] = "删除平台动态成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_activity_forums_path
|
||||||
|
flash[:danger] = "删除平台动态失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_activity_forum
|
||||||
|
@activity_forum = ::Topic::ActivityForum.find_by_id(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def activity_forum_params
|
||||||
|
params.require(:topic_activity_forum).permit(:title, :uuid, :url, :order_index)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,57 @@
|
||||||
|
class Admins::Topic::BannersController < Admins::Topic::BaseController
|
||||||
|
before_action :find_banner, only: [:edit, :update, :destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@banners = paginate(::Topic::Banner)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@banner = ::Topic::Banner.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@banner = ::Topic::Banner.new(banner_params)
|
||||||
|
if @banner.save
|
||||||
|
save_image_file(params[:image], @banner)
|
||||||
|
redirect_to admins_topic_banners_path
|
||||||
|
flash[:success] = "新增banner成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_banners_path
|
||||||
|
flash[:danger] = "新增banner失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@banner.attributes = banner_params
|
||||||
|
if @banner.save
|
||||||
|
save_image_file(params[:image], @banner)
|
||||||
|
redirect_to admins_topic_banners_path
|
||||||
|
flash[:success] = "更新banner成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_banners_path
|
||||||
|
flash[:danger] = "更新banner失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @banner.destroy
|
||||||
|
redirect_to admins_topic_banners_path
|
||||||
|
flash[:success] = "删除banner成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_banners_path
|
||||||
|
flash[:danger] = "删除banner失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_banner
|
||||||
|
@banner = ::Topic::Banner.find_by_id(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def banner_params
|
||||||
|
params.require(:topic_banner).permit(:title, :order_index)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,11 @@
|
||||||
|
class Admins::Topic::BaseController < Admins::BaseController
|
||||||
|
|
||||||
|
protected
|
||||||
|
def save_image_file(file, topic)
|
||||||
|
return unless file.present? && file.is_a?(ActionDispatch::Http::UploadedFile)
|
||||||
|
|
||||||
|
file_path = Util::FileManage.source_disk_filename(topic, 'image')
|
||||||
|
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
|
||||||
|
Util.write_file(file, file_path)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,57 @@
|
||||||
|
class Admins::Topic::CardsController < Admins::Topic::BaseController
|
||||||
|
before_action :find_card, only: [:edit, :update, :destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
q = ::Topic::Card.ransack(title_cont: params[:search])
|
||||||
|
cards = q.result(distinct: true)
|
||||||
|
@cards = paginate(cards)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@card = ::Topic::Card.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@card = ::Topic::Card.new(card_params)
|
||||||
|
if @card.save
|
||||||
|
redirect_to admins_topic_cards_path
|
||||||
|
flash[:success] = "新增合作单位成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_cards_path
|
||||||
|
flash[:danger] = "新增合作单位失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@card.attributes = card_params
|
||||||
|
if @card.save
|
||||||
|
redirect_to admins_topic_cards_path
|
||||||
|
flash[:success] = "更新合作单位成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_cards_path
|
||||||
|
flash[:danger] = "更新合作单位失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @card.destroy
|
||||||
|
redirect_to admins_topic_cards_path
|
||||||
|
flash[:success] = "删除合作单位成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_cards_path
|
||||||
|
flash[:danger] = "删除合作单位失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_card
|
||||||
|
@card = ::Topic::Card.find_by_id(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def card_params
|
||||||
|
params.require(:topic_card).permit(:title, :url, :order_index)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,57 @@
|
||||||
|
class Admins::Topic::CooperatorsController < Admins::Topic::BaseController
|
||||||
|
before_action :find_cooperator, only: [:edit, :update, :destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@cooperators = paginate(::Topic::Cooperator)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@cooperator = ::Topic::Cooperator.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@cooperator = ::Topic::Cooperator.new(cooperator_params)
|
||||||
|
if @cooperator.save
|
||||||
|
save_image_file(params[:image], @cooperator)
|
||||||
|
redirect_to admins_topic_cooperators_path
|
||||||
|
flash[:success] = "新增合作单位成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_cooperators_path
|
||||||
|
flash[:danger] = "新增合作单位失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@cooperator.attributes = cooperator_params
|
||||||
|
if @cooperator.save
|
||||||
|
save_image_file(params[:image], @cooperator)
|
||||||
|
redirect_to admins_topic_cooperators_path
|
||||||
|
flash[:success] = "更新合作单位成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_cooperators_path
|
||||||
|
flash[:danger] = "更新合作单位失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @cooperator.destroy
|
||||||
|
redirect_to admins_topic_cooperators_path
|
||||||
|
flash[:success] = "删除合作单位成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_cooperators_path
|
||||||
|
flash[:danger] = "删除合作单位失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_cooperator
|
||||||
|
@cooperator = ::Topic::Cooperator.find_by_id(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def cooperator_params
|
||||||
|
params.require(:topic_cooperator).permit(:title, :url, :order_index)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,57 @@
|
||||||
|
class Admins::Topic::ExcellentProjectsController < Admins::Topic::BaseController
|
||||||
|
before_action :find_excellent_project, only: [:edit, :update, :destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
q = ::Topic::ExcellentProject.ransack(title_cont: params[:search])
|
||||||
|
excellent_projects = q.result(distinct: true)
|
||||||
|
@excellent_projects = paginate(excellent_projects)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@excellent_project = ::Topic::ExcellentProject.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@excellent_project = ::Topic::ExcellentProject.new(excellent_project_params)
|
||||||
|
if @excellent_project.save
|
||||||
|
redirect_to admins_topic_excellent_projects_path
|
||||||
|
flash[:success] = "新增优秀仓库成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_excellent_projects_path
|
||||||
|
flash[:danger] = "新增优秀仓库失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@excellent_project.attributes = excellent_project_params
|
||||||
|
if @excellent_project.save
|
||||||
|
redirect_to admins_topic_excellent_projects_path
|
||||||
|
flash[:success] = "更新优秀仓库成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_excellent_projects_path
|
||||||
|
flash[:danger] = "更新优秀仓库失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @excellent_project.destroy
|
||||||
|
redirect_to admins_topic_excellent_projects_path
|
||||||
|
flash[:success] = "删除优秀仓库成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_excellent_projects_path
|
||||||
|
flash[:danger] = "删除优秀仓库失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_excellent_project
|
||||||
|
@excellent_project = ::Topic::ExcellentProject.find_by_id(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def excellent_project_params
|
||||||
|
params.require(:topic_excellent_project).permit(:title, :uuid, :url, :order_index)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,57 @@
|
||||||
|
class Admins::Topic::ExperienceForumsController < Admins::Topic::BaseController
|
||||||
|
before_action :find_experience_forum, only: [:edit, :update, :destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
q = ::Topic::ExperienceForum.ransack(title_cont: params[:search])
|
||||||
|
experience_forums = q.result(distinct: true)
|
||||||
|
@experience_forums = paginate(experience_forums)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@experience_forum = ::Topic::ExperienceForum.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@experience_forum = ::Topic::ExperienceForum.new(experience_forum_params)
|
||||||
|
if @experience_forum.save
|
||||||
|
redirect_to admins_topic_experience_forums_path
|
||||||
|
flash[:success] = "新增经验分享成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_experience_forums_path
|
||||||
|
flash[:danger] = "新增经验分享失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@experience_forum.attributes = experience_forum_params
|
||||||
|
if @experience_forum.save
|
||||||
|
redirect_to admins_topic_experience_forums_path
|
||||||
|
flash[:success] = "更新经验分享成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_experience_forums_path
|
||||||
|
flash[:danger] = "更新经验分享失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @experience_forum.destroy
|
||||||
|
redirect_to admins_topic_experience_forums_path
|
||||||
|
flash[:success] = "删除经验分享成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_experience_forums_path
|
||||||
|
flash[:danger] = "删除经验分享失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_experience_forum
|
||||||
|
@experience_forum = ::Topic::ExperienceForum.find_by_id(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def experience_forum_params
|
||||||
|
params.require(:topic_experience_forum).permit(:title, :uuid, :url, :order_index)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,57 @@
|
||||||
|
class Admins::Topic::PinnedForumsController < Admins::Topic::BaseController
|
||||||
|
before_action :find_pinned_forum, only: [:edit, :update, :destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
q = ::Topic::PinnedForum.ransack(title_cont: params[:search])
|
||||||
|
pinned_forums = q.result(distinct: true)
|
||||||
|
@pinned_forums = paginate(pinned_forums)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@pinned_forum = ::Topic::PinnedForum.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@pinned_forum = ::Topic::PinnedForum.new(pinned_forum_params)
|
||||||
|
if @pinned_forum.save
|
||||||
|
redirect_to admins_topic_pinned_forums_path
|
||||||
|
flash[:success] = "新增精选文章成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_pinned_forums_path
|
||||||
|
flash[:danger] = "新增精选文章失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@pinned_forum.attributes = pinned_forum_params
|
||||||
|
if @pinned_forum.save
|
||||||
|
redirect_to admins_topic_pinned_forums_path
|
||||||
|
flash[:success] = "更新精选文章成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_pinned_forums_path
|
||||||
|
flash[:danger] = "更新精选文章失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
if @pinned_forum.destroy
|
||||||
|
redirect_to admins_topic_pinned_forums_path
|
||||||
|
flash[:success] = "删除精选文章成功"
|
||||||
|
else
|
||||||
|
redirect_to admins_topic_pinned_forums_path
|
||||||
|
flash[:danger] = "删除精选文章失败"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_pinned_forum
|
||||||
|
@pinned_forum = ::Topic::PinnedForum.find_by_id(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
def pinned_forum_params
|
||||||
|
params.require(:topic_pinned_forum).permit(:title, :uuid, :url, :order_index)
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,4 +1,6 @@
|
||||||
class Admins::UsersController < Admins::BaseController
|
class Admins::UsersController < Admins::BaseController
|
||||||
|
before_action :finder_user, except: [:index]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
params[:sort_by] = params[:sort_by].presence || 'created_on'
|
params[:sort_by] = params[:sort_by].presence || 'created_on'
|
||||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||||
|
@ -8,12 +10,9 @@ class Admins::UsersController < Admins::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@user = User.find(params[:id])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@user = User.find(params[:id])
|
|
||||||
|
|
||||||
Admins::UpdateUserService.call(@user, update_params)
|
Admins::UpdateUserService.call(@user, update_params)
|
||||||
flash[:success] = '保存成功'
|
flash[:success] = '保存成功'
|
||||||
redirect_to edit_admins_user_path(@user)
|
redirect_to edit_admins_user_path(@user)
|
||||||
|
@ -26,43 +25,47 @@ class Admins::UsersController < Admins::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
User.find(params[:id]).destroy!
|
@user.destroy!
|
||||||
|
Gitea::User::DeleteService.call(@user.login)
|
||||||
|
|
||||||
render_delete_success
|
render_delete_success
|
||||||
end
|
end
|
||||||
|
|
||||||
def lock
|
def lock
|
||||||
User.find(params[:id]).lock!
|
@user.lock!
|
||||||
|
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def unlock
|
def unlock
|
||||||
User.find(params[:id]).activate!
|
@user.activate!
|
||||||
|
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def reward_grade
|
def reward_grade
|
||||||
user = User.find(params[:user_id])
|
|
||||||
return render_unprocessable_entity('金币数量必须大于0') if params[:grade].to_i <= 0
|
return render_unprocessable_entity('金币数量必须大于0') if params[:grade].to_i <= 0
|
||||||
|
|
||||||
RewardGradeService.call(user, container_id: user.id, container_type: 'Feedback', score: params[:grade].to_i, not_unique: true)
|
RewardGradeService.call(@user, container_id: @user.id, container_type: 'Feedback', score: params[:grade].to_i, not_unique: true)
|
||||||
|
|
||||||
render_ok(grade: user.grade)
|
render_ok(grade: @user.grade)
|
||||||
end
|
end
|
||||||
|
|
||||||
def reset_login_times
|
def reset_login_times
|
||||||
User.find(params[:id]).reset_login_times!
|
@user.reset_login_times!
|
||||||
|
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def finder_user
|
||||||
|
@user = User.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
def update_params
|
def update_params
|
||||||
params.require(:user).permit(%i[lastname nickname gender identity technical_title student_id is_shixun_marker
|
params.require(:user).permit(%i[lastname nickname gender identity technical_title student_id is_shixun_marker
|
||||||
mail phone location location_city school_id department_id admin business is_test
|
mail phone location location_city school_id department_id admin business is_test
|
||||||
password professional_certification authentication])
|
password professional_certification authentication login])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,7 +26,8 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
|
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
|
||||||
OPENKEY = "79e33abd4b6588941ab7622aed1e67e8"
|
OPENKEY = Rails.application.config_for(:configuration)['sign_key'] || "79e33abd4b6588941ab7622aed1e67e8"
|
||||||
|
|
||||||
|
|
||||||
helper_method :current_user, :base_url
|
helper_method :current_user, :base_url
|
||||||
|
|
||||||
|
@ -70,49 +71,11 @@ class ApplicationController < ActionController::Base
|
||||||
(current_user.professional_certification && (ue.teacher? || ue.professional?))
|
(current_user.professional_certification && (ue.teacher? || ue.professional?))
|
||||||
end
|
end
|
||||||
|
|
||||||
def shixun_marker
|
|
||||||
unless current_user.is_shixun_marker? || current_user.admin_or_business?
|
|
||||||
tip_exception(403, "..")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# 实训的访问权限
|
|
||||||
def shixun_access_allowed
|
|
||||||
if !current_user.shixun_permission(@shixun)
|
|
||||||
tip_exception(403, "..")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def admin_or_business?
|
def admin_or_business?
|
||||||
User.current.admin? || User.current.business?
|
User.current.admin? || User.current.business?
|
||||||
end
|
end
|
||||||
|
|
||||||
# 访问课堂时没权限直接弹加入课堂的弹框 :409
|
|
||||||
def user_course_identity
|
|
||||||
@user_course_identity = current_user.course_identity(@course)
|
|
||||||
if @user_course_identity > Course::STUDENT && @course.is_public == 0
|
|
||||||
tip_exception(401, "..") unless User.current.logged?
|
|
||||||
check_account
|
|
||||||
tip_exception(@course.excellent ? 410 : 409, "您没有权限进入")
|
|
||||||
end
|
|
||||||
if @user_course_identity > Course::CREATOR && @user_course_identity <= Course::STUDENT && @course.tea_id != current_user.id
|
|
||||||
# 实名认证和职业认证的身份判断
|
|
||||||
tip_exception(411, "你的实名认证和职业认证审核未通过") if @course.authentication &&
|
|
||||||
@course.professional_certification && (!current_user.authentication && !current_user.professional_certification)
|
|
||||||
tip_exception(411, "你的实名认证审核未通过") if @course.authentication && !current_user.authentication
|
|
||||||
tip_exception(411, "你的职业认证审核未通过") if @course.professional_certification && !current_user.professional_certification
|
|
||||||
end
|
|
||||||
uid_logger("###############user_course_identity:#{@user_course_identity}")
|
|
||||||
end
|
|
||||||
|
|
||||||
# 题库的访问权限
|
|
||||||
def bank_visit_auth
|
|
||||||
tip_exception(-2,"未通过职业认证") if current_user.is_teacher? && !current_user.certification_teacher? && !current_user.admin_or_business? && @bank.user_id != current_user.id && @bank.is_public
|
|
||||||
tip_exception(403, "无权限") unless @bank.user_id == current_user.id || current_user.admin_or_business? ||
|
|
||||||
(current_user.certification_teacher? && @bank.is_public)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
# 判断用户的邮箱或者手机是否可用
|
# 判断用户的邮箱或者手机是否可用
|
||||||
# params[:type] 1: 注册;2:忘记密码;3:绑定
|
# params[:type] 1: 注册;2:忘记密码;3:绑定
|
||||||
def check_mail_and_phone_valid login, type
|
def check_mail_and_phone_valid login, type
|
||||||
|
@ -120,16 +83,16 @@ class ApplicationController < ActionController::Base
|
||||||
login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])$/
|
login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])$/
|
||||||
tip_exception(-2, "请输入正确的手机号或邮箱")
|
tip_exception(-2, "请输入正确的手机号或邮箱")
|
||||||
end
|
end
|
||||||
# 考虑到安全参数问题,多一次查询,去掉Union
|
|
||||||
user = User.where(phone: login).first || User.where(mail: login).first
|
user_exist = Owner.exists?(phone: login) || Owner.exists?(mail: login)
|
||||||
if type.to_i == 1 && !user.nil?
|
if user_exist && type.to_i == 1
|
||||||
tip_exception(-2, "该手机号码或邮箱已被注册")
|
tip_exception(-2, "该手机号码或邮箱已被注册")
|
||||||
elsif type.to_i == 2 && user.nil?
|
elsif type.to_i == 2 && !user_exist
|
||||||
tip_exception(-2, "该手机号码或邮箱未注册")
|
tip_exception(-2, "该手机号码或邮箱未注册")
|
||||||
elsif type.to_i == 3 && user.present?
|
elsif type.to_i == 3 && user_exist
|
||||||
tip_exception(-2, "该手机号码或邮箱已绑定")
|
tip_exception(-2, "该手机号码或邮箱已绑定")
|
||||||
end
|
end
|
||||||
sucess_status
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
# 发送及记录激活码
|
# 发送及记录激活码
|
||||||
|
@ -140,7 +103,7 @@ class ApplicationController < ActionController::Base
|
||||||
when 1, 2, 4, 9
|
when 1, 2, 4, 9
|
||||||
# 手机类型的发送
|
# 手机类型的发送
|
||||||
sigle_para = {phone: value}
|
sigle_para = {phone: value}
|
||||||
status = Educoder::Sms.send(mobile: value, code: code)
|
status = Gitlink::Sms.send(mobile: value, code: code)
|
||||||
tip_exception(-2, code_msg(status)) if status != 0
|
tip_exception(-2, code_msg(status)) if status != 0
|
||||||
when 8, 3, 5
|
when 8, 3, 5
|
||||||
# 邮箱类型的发送
|
# 邮箱类型的发送
|
||||||
|
@ -186,26 +149,6 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_course
|
|
||||||
return normal_status(2, '缺少course_id参数!') if params[:course_id].blank?
|
|
||||||
@course = Course.find(params[:course_id])
|
|
||||||
tip_exception(404, "") if @course.is_delete == 1 && !current_user.admin_or_business?
|
|
||||||
rescue Exception => e
|
|
||||||
tip_exception(e.message)
|
|
||||||
end
|
|
||||||
|
|
||||||
def course_manager
|
|
||||||
return normal_status(403, '只有课堂管理员才有权限') if @user_course_identity > Course::CREATOR
|
|
||||||
end
|
|
||||||
|
|
||||||
def find_board
|
|
||||||
return normal_status(2, "缺少board_id参数") if params[:board_id].blank?
|
|
||||||
@board = Board.find(params[:board_id])
|
|
||||||
rescue Exception => e
|
|
||||||
uid_logger_error(e.message)
|
|
||||||
tip_exception(e.message)
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate_type(object_type)
|
def validate_type(object_type)
|
||||||
normal_status(2, "参数") if params.has_key?(:sort_type) && !SORT_TYPE.include?(params[:sort_type].strip)
|
normal_status(2, "参数") if params.has_key?(:sort_type) && !SORT_TYPE.include?(params[:sort_type].strip)
|
||||||
end
|
end
|
||||||
|
@ -215,21 +158,6 @@ class ApplicationController < ActionController::Base
|
||||||
@page_size = params[:page_size] || 15
|
@page_size = params[:page_size] || 15
|
||||||
end
|
end
|
||||||
|
|
||||||
# 课堂教师权限
|
|
||||||
def teacher_allowed
|
|
||||||
logger.info("#####identity: #{current_user.course_identity(@course)}")
|
|
||||||
unless current_user.course_identity(@course) < Course::STUDENT
|
|
||||||
normal_status(403, "")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# 课堂教师、课堂管理员、超级管理员的权限(不包含助教)
|
|
||||||
def teacher_or_admin_allowed
|
|
||||||
unless current_user.course_identity(@course) < Course::ASSISTANT_PROFESSOR
|
|
||||||
normal_status(403, "")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def require_admin
|
def require_admin
|
||||||
normal_status(403, "") unless User.current.admin?
|
normal_status(403, "") unless User.current.admin?
|
||||||
end
|
end
|
||||||
|
@ -246,9 +174,17 @@ class ApplicationController < ActionController::Base
|
||||||
tip_exception(401, "请登录后再操作") unless User.current.logged?
|
tip_exception(401, "请登录后再操作") unless User.current.logged?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def require_profile_completed
|
||||||
|
tip_exception(411, "请完善资料后再操作") unless User.current.profile_is_completed?
|
||||||
|
end
|
||||||
|
|
||||||
|
def require_user_profile_completed(user)
|
||||||
|
tip_exception(412, "请用户完善资料后再操作") unless user.profile_is_completed?
|
||||||
|
end
|
||||||
|
|
||||||
# 异常提醒
|
# 异常提醒
|
||||||
def tip_exception(status = -1, message)
|
def tip_exception(status = -1, message)
|
||||||
raise Educoder::TipException.new(status, message)
|
raise Gitlink::TipException.new(status, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def missing_template
|
def missing_template
|
||||||
|
@ -257,7 +193,7 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
# 弹框提醒
|
# 弹框提醒
|
||||||
def tip_show_exception(status = -2, message)
|
def tip_show_exception(status = -2, message)
|
||||||
raise Educoder::TipException.new(status, message)
|
raise Gitlink::TipException.new(status, message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def normal_status(status = 0, message)
|
def normal_status(status = 0, message)
|
||||||
|
@ -272,7 +208,7 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
# 资料是否完善
|
# 资料是否完善
|
||||||
def check_account
|
def check_account
|
||||||
if !current_user.profile_completed?
|
if !current_user. profile_is_completed?
|
||||||
#info_url = '/account/profile'
|
#info_url = '/account/profile'
|
||||||
tip_exception(402, nil)
|
tip_exception(402, nil)
|
||||||
end
|
end
|
||||||
|
@ -400,11 +336,6 @@ class ApplicationController < ActionController::Base
|
||||||
@message = message
|
@message = message
|
||||||
end
|
end
|
||||||
|
|
||||||
# 实训等对应的仓库地址
|
|
||||||
def repo_ip_url(repo_path)
|
|
||||||
"#{edu_setting('git_address_ip')}/#{repo_path}"
|
|
||||||
end
|
|
||||||
|
|
||||||
def repo_url(repo_path)
|
def repo_url(repo_path)
|
||||||
"#{edu_setting('git_address_domain')}/#{repo_path}"
|
"#{edu_setting('git_address_domain')}/#{repo_path}"
|
||||||
end
|
end
|
||||||
|
@ -437,7 +368,7 @@ class ApplicationController < ActionController::Base
|
||||||
JSON.parse(res)
|
JSON.parse(res)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error("--uri_exec: exception #{e.message}")
|
uid_logger_error("--uri_exec: exception #{e.message}")
|
||||||
raise Educoder::TipException.new("实训平台繁忙(繁忙等级:84)")
|
raise Gitlink::TipException.new("实训平台繁忙(繁忙等级:84)")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -456,7 +387,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger("--uri_exec: exception #{e.message}")
|
uid_logger("--uri_exec: exception #{e.message}")
|
||||||
raise Educoder::TipException.new(message)
|
raise Gitlink::TipException.new(message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -480,7 +411,7 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger("--uri_exec: exception #{e.message}")
|
uid_logger("--uri_exec: exception #{e.message}")
|
||||||
raise Educoder::TipException.new("服务器繁忙")
|
raise Gitlink::TipException.new("服务器繁忙")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -614,8 +545,8 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
# 排序
|
# 排序
|
||||||
rorder = option[:order] || "updated_at"
|
rorder = UserExtension.column_names.include?(option[:order]) ? option[:order] : "updated_at"
|
||||||
b_order = option[:b_order] || "desc"
|
b_order = %w(desc asc).include?(option[:b_order]) ? option[:b_order] : "desc"
|
||||||
if rorder == "created_at" || rorder == "work_score"
|
if rorder == "created_at" || rorder == "work_score"
|
||||||
work_list = work_list.order("graduation_works.#{rorder} #{b_order}")
|
work_list = work_list.order("graduation_works.#{rorder} #{b_order}")
|
||||||
elsif rorder == "student_id"
|
elsif rorder == "student_id"
|
||||||
|
@ -652,8 +583,8 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
# 获取Oauth Client
|
# 获取Oauth Client
|
||||||
def get_client(site)
|
def get_client(site)
|
||||||
client_id = Rails.configuration.educoder['client_id']
|
client_id = Rails.configuration.Gitlink['client_id']
|
||||||
client_secret = Rails.configuration.educoder['client_secret']
|
client_secret = Rails.configuration.Gitlink['client_secret']
|
||||||
|
|
||||||
OAuth2::Client.new(client_id, client_secret, site: site)
|
OAuth2::Client.new(client_id, client_secret, site: site)
|
||||||
end
|
end
|
||||||
|
@ -673,7 +604,7 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
def kaminari_paginate(relation)
|
def kaminari_paginate(relation)
|
||||||
limit = params[:limit] || params[:per_page]
|
limit = params[:limit] || params[:per_page]
|
||||||
limit = (limit.to_i.zero? || limit.to_i > 15) ? 15 : limit.to_i
|
limit = (limit.to_i.zero? || limit.to_i > 20) ? 20 : limit.to_i
|
||||||
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
|
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
|
||||||
|
|
||||||
relation.page(page).per(limit)
|
relation.page(page).per(limit)
|
||||||
|
@ -681,7 +612,7 @@ class ApplicationController < ActionController::Base
|
||||||
|
|
||||||
def kaminari_array_paginate(relation)
|
def kaminari_array_paginate(relation)
|
||||||
limit = params[:limit] || params[:per_page]
|
limit = params[:limit] || params[:per_page]
|
||||||
limit = (limit.to_i.zero? || limit.to_i > 15) ? 15 : limit.to_i
|
limit = (limit.to_i.zero? || limit.to_i > 20) ? 20 : limit.to_i
|
||||||
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
|
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
|
||||||
|
|
||||||
Kaminari.paginate_array(relation).page(page).per(limit)
|
Kaminari.paginate_array(relation).page(page).per(limit)
|
||||||
|
@ -753,10 +684,10 @@ class ApplicationController < ActionController::Base
|
||||||
if @project and current_user.can_read_project?(@project)
|
if @project and current_user.can_read_project?(@project)
|
||||||
logger.info "###########: has project and can read project"
|
logger.info "###########: has project and can read project"
|
||||||
@project
|
@project
|
||||||
elsif @project && current_user.is_a?(AnonymousUser)
|
# elsif @project && current_user.is_a?(AnonymousUser)
|
||||||
logger.info "###########:This is AnonymousUser"
|
# logger.info "###########:This is AnonymousUser"
|
||||||
@project = nil if !@project.is_public?
|
# @project = nil if !@project.is_public?
|
||||||
render_forbidden and return
|
# render_forbidden and return
|
||||||
else
|
else
|
||||||
logger.info "###########:project not found"
|
logger.info "###########:project not found"
|
||||||
@project = nil
|
@project = nil
|
||||||
|
@ -770,9 +701,35 @@ class ApplicationController < ActionController::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def base_url
|
def base_url
|
||||||
request.base_url
|
Rails.application.config_for(:configuration)['platform_url'] || request.base_url
|
||||||
|
end
|
||||||
|
|
||||||
|
def image_type?(str)
|
||||||
|
default_type = %w(png jpg gif tif psd svg bmp webp jpeg ico psd)
|
||||||
|
default_type.include?(str&.downcase)
|
||||||
|
end
|
||||||
|
|
||||||
|
def convert_image!
|
||||||
|
@image = params[:image]
|
||||||
|
@image = @image.nil? && params[:user].present? ? params[:user][:image] : @image
|
||||||
|
return unless @image.present?
|
||||||
|
max_size = EduSetting.get('upload_avatar_max_size') || 2 * 1024 * 1024 # 2M
|
||||||
|
if @image.class == ActionDispatch::Http::UploadedFile
|
||||||
|
return render_error('请上传文件') if @image.size.zero?
|
||||||
|
return render_error('文件大小超过限制') if @image.size > max_size.to_i
|
||||||
|
return render_error('头像格式不正确!') unless image_type?(File.extname(@image.original_filename.to_s)[1..-1])
|
||||||
|
else
|
||||||
|
image = @image.to_s.strip
|
||||||
|
return render_error('请上传正确的图片') if image.blank?
|
||||||
|
@image = Util.convert_base64_image(image, max_size: max_size.to_i)
|
||||||
|
end
|
||||||
|
rescue Base64ImageConverter::Error => ex
|
||||||
|
render_error(ex.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def avatar_path(object)
|
||||||
|
ApplicationController.helpers.disk_filename(object.class, object.id)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def object_not_found
|
def object_not_found
|
||||||
|
@ -786,37 +743,10 @@ class ApplicationController < ActionController::Base
|
||||||
render json: exception.tip_json
|
render json: exception.tip_json
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_parameter_missing
|
|
||||||
render json: { status: -1, message: '参数缺失' }
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_export_cookies
|
def set_export_cookies
|
||||||
cookies[:fileDownload] = true
|
cookies[:fileDownload] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
# 149课程的评审用户数据创建(包含创建课堂学生)
|
|
||||||
def open_class_user
|
|
||||||
user = User.find_by(login: "OpenClassUser")
|
|
||||||
unless user
|
|
||||||
ActiveRecord::Base.transaction do
|
|
||||||
user_params = {status: 1, login: "OpenClassUser", lastname: "开放课程",
|
|
||||||
nickname: "开放课程", professional_certification: 1, certification: 1, grade: 0,
|
|
||||||
password: "12345678", phone: "11122223333", profile_completed: 1}
|
|
||||||
user = User.create!(user_params)
|
|
||||||
|
|
||||||
UserExtension.create!(user_id: user.id, gender: 0, school_id: 3396, :identity => 1, :student_id => "openclassuser") # 3396
|
|
||||||
|
|
||||||
subject = Subject.find_by(id: 149)
|
|
||||||
if subject
|
|
||||||
subject.courses.each do |course|
|
|
||||||
CourseMember.create!(course_id: course.id, role: 3, user_id: user.id) if !course.course_members.exists?(user_id: user.id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
user
|
|
||||||
end
|
|
||||||
|
|
||||||
# 记录热门搜索关键字
|
# 记录热门搜索关键字
|
||||||
def record_search_keyword
|
def record_search_keyword
|
||||||
keyword = params[:keyword].to_s.strip
|
keyword = params[:keyword].to_s.strip
|
||||||
|
@ -1471,5 +1401,8 @@ class ApplicationController < ActionController::Base
|
||||||
return success_blockchain
|
return success_blockchain
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
def find_atme_receivers
|
||||||
|
@atme_receivers = User.where(login: params[:receivers_login])
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
class AppliedProjectsController < ApplicationController
|
||||||
|
before_action :require_login
|
||||||
|
def create
|
||||||
|
@applied_project = Projects::ApplyJoinService.call(current_user, applied_params)
|
||||||
|
rescue Projects::ApplyJoinService::Error => ex
|
||||||
|
render_error(ex.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def applied_params
|
||||||
|
params.require(:applied_project).permit(:code, :role)
|
||||||
|
end
|
||||||
|
end
|
|
@ -32,8 +32,17 @@ class AttachmentsController < ApplicationController
|
||||||
def get_file
|
def get_file
|
||||||
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
||||||
url = URI.encode(params[:download_url].to_s.gsub("http:", "https:"))
|
url = URI.encode(params[:download_url].to_s.gsub("http:", "https:"))
|
||||||
response = Faraday.get(url)
|
if url.starts_with?(base_url)
|
||||||
filename = params[:download_url].to_s.split("/").pop()
|
domain = Gitea.gitea_config[:domain]
|
||||||
|
api_url = Gitea.gitea_config[:base_url]
|
||||||
|
url = url.split(base_url)[1].gsub("api", "repos").gsub('?filepath=', '/').gsub('&', '?')
|
||||||
|
request_url = [domain, api_url, url, "?ref=#{params[:ref]}&access_token=#{current_user&.gitea_token}"].join
|
||||||
|
response = Faraday.get(request_url)
|
||||||
|
filename = url.to_s.split("/").pop()
|
||||||
|
else
|
||||||
|
response = Faraday.get(url)
|
||||||
|
filename = params[:download_url].to_s.split("/").pop()
|
||||||
|
end
|
||||||
send_data(response.body.force_encoding("UTF-8"), filename: filename, type: "application/octet-stream", disposition: 'attachment')
|
send_data(response.body.force_encoding("UTF-8"), filename: filename, type: "application/octet-stream", disposition: 'attachment')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -187,7 +196,7 @@ class AttachmentsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_save_to_ucloud(path, file, content_type)
|
def file_save_to_ucloud(path, file, content_type)
|
||||||
ufile = Educoder::Ufile.new(
|
ufile = Gitlink::Ufile.new(
|
||||||
ucloud_public_key: edu_setting('public_key'),
|
ucloud_public_key: edu_setting('public_key'),
|
||||||
ucloud_private_key: edu_setting('private_key'),
|
ucloud_private_key: edu_setting('private_key'),
|
||||||
ucloud_public_read: true,
|
ucloud_public_read: true,
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Ci::BaseController < ApplicationController
|
||||||
namespace = params[:owner]
|
namespace = params[:owner]
|
||||||
id = params[:repo] || params[:id]
|
id = params[:repo] || params[:id]
|
||||||
|
|
||||||
@ci_user, @repo = Ci::Repo.find_with_namespace(namespace, id)
|
@ci_user, @repo = Ci::Repo.find_with_namespace(namespace, id, current_user.login)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_all_repo
|
def load_all_repo
|
||||||
|
|
|
@ -46,7 +46,7 @@ class Ci::SecretsController < Ci::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def ci_drone_url
|
def ci_drone_url
|
||||||
user = User.find_by(login: params[:owner])
|
user = User.find_by(login: params[:owner]) || User.find_by(login: current_user.login)
|
||||||
user&.ci_cloud_account.drone_url
|
user&.ci_cloud_account.drone_url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,138 @@
|
||||||
|
#coding=utf-8
|
||||||
|
class ClaimsController < ApplicationController
|
||||||
|
# skip_before_action :verify_authenticity_token
|
||||||
|
protect_from_forgery with: :null_session
|
||||||
|
before_action :require_login, except: [:index]
|
||||||
|
before_action :set_issue
|
||||||
|
|
||||||
|
def index
|
||||||
|
@user_claimed = 0
|
||||||
|
@claims = @issue.claims.claim_includes.order("created_at desc")
|
||||||
|
|
||||||
|
@claims.each do |claim|
|
||||||
|
if claim.user_id == current_user.id
|
||||||
|
@user_claimed = 1
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
render file: 'app/views/claims/list.json.jbuilder'
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@claim = Claim.find_by_sql(["select id from claims where issue_id=? and user_id=?",params[:issue_id], current_user.id])
|
||||||
|
if @claim.present?
|
||||||
|
return normal_status(-1,"您已经声明过该易修")
|
||||||
|
end
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
@claim = Claim.new(parse_issue_params(params))
|
||||||
|
if @claim.save
|
||||||
|
@claims = @issue.claims.claim_includes.order("created_at desc")
|
||||||
|
@user_claimed = 1
|
||||||
|
|
||||||
|
journal_params = {
|
||||||
|
journalized_id: params[:issue_id],
|
||||||
|
journalized_type: "Issue",
|
||||||
|
user_id: current_user.id ,
|
||||||
|
notes: "新建声明: #{params[:claim_note]}",
|
||||||
|
}
|
||||||
|
|
||||||
|
journal = Journal.new(journal_params)
|
||||||
|
if journal.save
|
||||||
|
render file: 'app/views/claims/list.json.jbuilder'
|
||||||
|
else
|
||||||
|
normal_status(-1,"新建声明关联评论操作失败")
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
normal_status(-1,"新建声明操作失败")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@claim = Claim.find_by_id(params[:claim_id])
|
||||||
|
if @claim.blank?
|
||||||
|
return normal_status(-1,"易修不存在")
|
||||||
|
end
|
||||||
|
|
||||||
|
if @claim.user_id != current_user.id
|
||||||
|
return normal_status(-1,"你不能更新别人的声明")
|
||||||
|
end
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
if @claim.update_attribute(:note,params[:claim_note])
|
||||||
|
@claims = @issue.claims.claim_includes.order("created_at desc")
|
||||||
|
@user_claimed = 1
|
||||||
|
|
||||||
|
journal_params = {
|
||||||
|
journalized_id: params[:issue_id],
|
||||||
|
journalized_type: "Issue",
|
||||||
|
user_id: current_user.id ,
|
||||||
|
notes: "更新声明: #{params[:claim_note]}",
|
||||||
|
}
|
||||||
|
|
||||||
|
journal = Journal.new(journal_params)
|
||||||
|
if journal.save
|
||||||
|
render file: 'app/views/claims/list.json.jbuilder'
|
||||||
|
else
|
||||||
|
normal_status(-1,"新建声明关联评论操作失败")
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
normal_status(-1,"声明更新操作失败")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
@claim = Claim.find_by_sql(["select id from claims where issue_id=? and user_id=?",params[:issue_id], current_user.id])
|
||||||
|
if @claim.blank?
|
||||||
|
normal_status(-1,"您未曾声明过该易修")
|
||||||
|
else
|
||||||
|
@claim = @claim[0]
|
||||||
|
# 判断current user是否是claimer
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
if @claim.destroy
|
||||||
|
|
||||||
|
@claims = @issue.claims.claim_includes.order("created_at desc")
|
||||||
|
@user_claimed = 0
|
||||||
|
|
||||||
|
journal_params = {
|
||||||
|
journalized_id: params[:issue_id],
|
||||||
|
journalized_type: "Issue",
|
||||||
|
user_id: current_user.id ,
|
||||||
|
notes: "取消声明",
|
||||||
|
}
|
||||||
|
|
||||||
|
journal = Journal.new(journal_params)
|
||||||
|
if journal.save
|
||||||
|
render file: 'app/views/claims/list.json.jbuilder'
|
||||||
|
else
|
||||||
|
normal_status(-1,"新建声明关联评论操作失败")
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
normal_status(-1,"取消声明操作失败")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def parse_issue_params(params)
|
||||||
|
{
|
||||||
|
issue_id: params[:issue_id],
|
||||||
|
user_id: current_user.id,
|
||||||
|
note: params[:claim_note],
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def set_issue
|
||||||
|
@issue = Issue.find_by_id(params[:issue_id])
|
||||||
|
unless @issue.present?
|
||||||
|
normal_status(-1, "易修不存在")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -6,26 +6,50 @@ class CompareController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
load_compare_params
|
||||||
compare
|
compare
|
||||||
|
@merge_status, @merge_message = get_merge_message
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def get_merge_message
|
||||||
|
if @base.blank? || @head.blank?
|
||||||
|
return -2, "请选择分支"
|
||||||
|
else
|
||||||
|
if @head.include?(":")
|
||||||
|
fork_project = @project.forked_projects.joins(:owner).where(users: {login: @head.to_s.split("/")[0]}).take
|
||||||
|
return -2, "请选择正确的仓库" unless fork_project.present?
|
||||||
|
@exist_pullrequest = @project.pull_requests.where(is_original: true, head: @head.to_s.split(":")[1], base: @base, status: 0, fork_project_id: fork_project.id).take
|
||||||
|
else
|
||||||
|
@exist_pullrequest = @project.pull_requests.where(is_original: false, head: @base, base: @head, status: 0).take
|
||||||
|
end
|
||||||
|
if @exist_pullrequest.present?
|
||||||
|
return -2, "在这些分支之间的合并请求已存在:<a href='/#{@owner.login}/#{@project.identifier}/pulls/#{@exist_pullrequest.id}'>#{@exist_pullrequest.try(:title)}</a>"
|
||||||
|
else
|
||||||
|
if @compare_result["Commits"].blank? && @compare_result["Diff"].blank?
|
||||||
|
return -2, "分支内容相同,无需创建合并请求"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return 0, "可以合并"
|
||||||
|
end
|
||||||
|
|
||||||
def compare
|
def compare
|
||||||
base, head = compare_params
|
|
||||||
|
|
||||||
# TODO: 处理fork的项目向源项目发送PR的base、head参数问题
|
# TODO: 处理fork的项目向源项目发送PR的base、head参数问题
|
||||||
@compare_result ||=
|
@compare_result ||=
|
||||||
head.include?(":") ? gitea_compare(base, head) : gitea_compare(head, base)
|
@head.include?(":") ? gitea_compare(@base, @head) : gitea_compare(@head, @base)
|
||||||
end
|
end
|
||||||
|
|
||||||
def compare_params
|
def load_compare_params
|
||||||
base = Addressable::URI.unescape(params[:base])
|
# @base = Addressable::URI.unescape(params[:base])
|
||||||
head = params[:head].include?('json') ? params[:head]&.split('.json')[0] : params[:head]
|
@base = params[:base].include?(":") ? Addressable::URI.unescape(params[:base].split(":")[0]) + ':' + Base64.decode64(params[:base].split(":")[1]) : Base64.decode64(params[:base])
|
||||||
|
@head = params[:head].include?('.json') ? params[:head][0..-6] : params[:head]
|
||||||
[base, head]
|
# @head = Addressable::URI.unescape(@head)
|
||||||
|
@head = @head.include?(":") ? Addressable::URI.unescape(@head.split(":")[0]) + ':' + Base64.decode64(@head.split(":")[1]) : Base64.decode64(@head)
|
||||||
end
|
end
|
||||||
|
|
||||||
def gitea_compare(base, head)
|
def gitea_compare(base, head)
|
||||||
Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, base, head)
|
Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, CGI.escape(base), CGI.escape(head), current_user.gitea_token)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,13 +3,12 @@ class ComposesController < ApplicationController
|
||||||
before_action :find_compose, except: [:index, :new,:create]
|
before_action :find_compose, except: [:index, :new,:create]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@order_type = params[:order] || "created_at"
|
|
||||||
@search_name = params[:search]
|
@search_name = params[:search]
|
||||||
composes = Compose.compose_includes
|
composes = Compose.compose_includes
|
||||||
if @search_name.present?
|
if @search_name.present?
|
||||||
composes = composes.where("title like ?", "%#{@search_name}%")
|
composes = composes.where("title like ?", "%#{@search_name}%")
|
||||||
end
|
end
|
||||||
composes = composes.order("#{@order_type} desc")
|
composes = composes.order("#{order_type} desc")
|
||||||
@page = params[:page] || 1
|
@page = params[:page] || 1
|
||||||
@limit = params[:limit] || 15
|
@limit = params[:limit] || 15
|
||||||
@composes_size = composes.size
|
@composes_size = composes.size
|
||||||
|
@ -96,4 +95,8 @@ class ComposesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def order_type
|
||||||
|
Compose.column_names.include?(params[:order_type]) ? params[:order_type] : 'created_at'
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -2,7 +2,7 @@ module Acceleratorable
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
def enable_accelerator?(clone_addr)
|
def enable_accelerator?(clone_addr)
|
||||||
clone_addr.include?(github_domain) || clone_addr.include?(gitlab_domain)
|
is_foreign_url?(clone_addr) && config_accelerator?
|
||||||
end
|
end
|
||||||
|
|
||||||
def accelerator_url(repo_name)
|
def accelerator_url(repo_name)
|
||||||
|
@ -25,4 +25,12 @@ module Acceleratorable
|
||||||
Gitea.gitea_config[:accelerator]["access_key_id"]
|
Gitea.gitea_config[:accelerator]["access_key_id"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def config_accelerator?
|
||||||
|
Gitea.gitea_config[:accelerator].present?
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_foreign_url?(clone_addr)
|
||||||
|
clone_addr.include?(github_domain) || clone_addr.include?(gitlab_domain)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -179,7 +179,7 @@ module Ci::CloudAccountManageable
|
||||||
|
|
||||||
def drone_oauth_user!(url, state)
|
def drone_oauth_user!(url, state)
|
||||||
logger.info "[drone] drone_oauth_user url: #{url}"
|
logger.info "[drone] drone_oauth_user url: #{url}"
|
||||||
conn = Faraday.new(url: url) do |req|
|
conn = Faraday.new(url: "#{Gitea.gitea_config[:domain]}#{url}") do |req|
|
||||||
req.request :url_encoded
|
req.request :url_encoded
|
||||||
req.adapter Faraday.default_adapter
|
req.adapter Faraday.default_adapter
|
||||||
req.headers["cookie"] = "_session_=#{SecureRandom.hex(28)}; _oauth_state_=#{state}"
|
req.headers["cookie"] = "_session_=#{SecureRandom.hex(28)}; _oauth_state_=#{state}"
|
||||||
|
@ -188,7 +188,8 @@ module Ci::CloudAccountManageable
|
||||||
response = conn.get
|
response = conn.get
|
||||||
logger.info "[drone] response headers: #{response.headers}"
|
logger.info "[drone] response headers: #{response.headers}"
|
||||||
|
|
||||||
response.headers['location'].include?('error') ? false : true
|
true
|
||||||
|
# response.headers['location'].include?('error') ? false : true
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -20,7 +20,7 @@ module ControllerRescueHandler
|
||||||
end
|
end
|
||||||
# rescue_from ActionView::MissingTemplate, with: :object_not_found
|
# rescue_from ActionView::MissingTemplate, with: :object_not_found
|
||||||
# rescue_from ActiveRecord::RecordNotFound, with: :object_not_found
|
# rescue_from ActiveRecord::RecordNotFound, with: :object_not_found
|
||||||
rescue_from Educoder::TipException, with: :tip_show
|
rescue_from Gitlink::TipException, with: :tip_show
|
||||||
rescue_from ::ActionView::MissingTemplate, with: :missing_template
|
rescue_from ::ActionView::MissingTemplate, with: :missing_template
|
||||||
rescue_from ActiveRecord::RecordNotFound, with: :object_not_found
|
rescue_from ActiveRecord::RecordNotFound, with: :object_not_found
|
||||||
rescue_from ActionController::ParameterMissing, with: :render_parameter_missing
|
rescue_from ActionController::ParameterMissing, with: :render_parameter_missing
|
||||||
|
|
|
@ -36,10 +36,10 @@ module GitCommon
|
||||||
begin
|
begin
|
||||||
@commits = GitService.commits(repo_path: @repo_path)
|
@commits = GitService.commits(repo_path: @repo_path)
|
||||||
logger.info("git first commit is #{@commits.try(:first)}")
|
logger.info("git first commit is #{@commits.try(:first)}")
|
||||||
raise Educoder::TipException.new("请先创建版本库") if @commits.nil?
|
raise Gitlink::TipException.new("请先创建版本库") if @commits.nil?
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
raise Educoder::TipException.new("提交记录异常")
|
raise Gitlink::TipException.new("提交记录异常")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ module GitHelper
|
||||||
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
Rails.logger.error(e.message)
|
Rails.logger.error(e.message)
|
||||||
raise Educoder::TipException.new("文档内容获取异常")
|
raise Gitlink::TipException.new("文档内容获取异常")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ module GitHelper
|
||||||
|
|
||||||
# 版本库Fork功能
|
# 版本库Fork功能
|
||||||
def project_fork(container, original_rep_path, username)
|
def project_fork(container, original_rep_path, username)
|
||||||
raise Educoder::TipException.new("fork源路径为空,fork失败!") if original_rep_path.blank?
|
raise Gitlink::TipException.new("fork源路径为空,fork失败!") if original_rep_path.blank?
|
||||||
# 将要生成的仓库名字
|
# 将要生成的仓库名字
|
||||||
new_repo_name = "#{username.try(:strip)}/#{container.try(:identifier)}#{ Time.now.strftime("%Y%m%d%H%M%S")}"
|
new_repo_name = "#{username.try(:strip)}/#{container.try(:identifier)}#{ Time.now.strftime("%Y%m%d%H%M%S")}"
|
||||||
# uid_logger("start fork container: repo_name is #{new_repo_name}")
|
# uid_logger("start fork container: repo_name is #{new_repo_name}")
|
||||||
|
|
|
@ -41,7 +41,7 @@ module LaboratoryHelper
|
||||||
my_courses: "https://www.trustie.net/users/#{current_user.try(:login)}/user_courselist",
|
my_courses: "https://www.trustie.net/users/#{current_user.try(:login)}/user_courselist",
|
||||||
my_projects: "/users/#{current_user.try(:login)}/projects",
|
my_projects: "/users/#{current_user.try(:login)}/projects",
|
||||||
my_organ: "https://www.trustie.net/users/#{current_user.try(:login)}/user_organizations",
|
my_organ: "https://www.trustie.net/users/#{current_user.try(:login)}/user_organizations",
|
||||||
default_url: "https://www.trustie.net/",
|
default_url: Rails.application.config_for(:configuration)['platform_url'],
|
||||||
tiding_url: "https://www.trustie.net/users/#{current_user.try(:login)}/user_messages",
|
tiding_url: "https://www.trustie.net/users/#{current_user.try(:login)}/user_messages",
|
||||||
register_url: "https://www.trustie.net/login?login=false"
|
register_url: "https://www.trustie.net/login?login=false"
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ module RegisterHelper
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
def autosync_register_trustie(username, password, email)
|
def autosync_register_trustie(username, password, email, lastname="")
|
||||||
config = Rails.application.config_for(:configuration).symbolize_keys!
|
config = Rails.application.config_for(:configuration).symbolize_keys!
|
||||||
|
|
||||||
api_host = config[:sync_url]
|
api_host = config[:sync_url]
|
||||||
|
@ -42,8 +42,9 @@ module RegisterHelper
|
||||||
sync_json = {
|
sync_json = {
|
||||||
"mail": email,
|
"mail": email,
|
||||||
"password": password,
|
"password": password,
|
||||||
"login": username
|
"login": username,
|
||||||
}
|
"lastname": lastname
|
||||||
|
}.compact
|
||||||
uri = URI.parse(url)
|
uri = URI.parse(url)
|
||||||
|
|
||||||
if api_host
|
if api_host
|
||||||
|
|
|
@ -28,4 +28,8 @@ module RenderHelper
|
||||||
def render_result(status=1, message='success')
|
def render_result(status=1, message='success')
|
||||||
render json: { status: status, message: message }
|
render json: { status: status, message: message }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def render_parameter_missing
|
||||||
|
render json: { status: -1, message: '参数缺失' }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,10 +29,8 @@ class EduSettingsController < ApplicationController
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @edu_setting.save
|
if @edu_setting.save
|
||||||
format.html { redirect_to @edu_setting, notice: 'Edu setting was successfully created.' }
|
|
||||||
format.json { render :show, status: :created, location: @edu_setting }
|
format.json { render :show, status: :created, location: @edu_setting }
|
||||||
else
|
else
|
||||||
format.html { render :new }
|
|
||||||
format.json { render json: @edu_setting.errors, status: :unprocessable_entity }
|
format.json { render json: @edu_setting.errors, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -43,10 +41,8 @@ class EduSettingsController < ApplicationController
|
||||||
def update
|
def update
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
if @edu_setting.update(edu_setting_params)
|
if @edu_setting.update(edu_setting_params)
|
||||||
format.html { redirect_to @edu_setting, notice: 'Edu setting was successfully updated.' }
|
|
||||||
format.json { render :show, status: :ok, location: @edu_setting }
|
format.json { render :show, status: :ok, location: @edu_setting }
|
||||||
else
|
else
|
||||||
format.html { render :edit }
|
|
||||||
format.json { render json: @edu_setting.errors, status: :unprocessable_entity }
|
format.json { render json: @edu_setting.errors, status: :unprocessable_entity }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -57,7 +53,6 @@ class EduSettingsController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
@edu_setting.destroy
|
@edu_setting.destroy
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html { redirect_to edu_settings_url, notice: 'Edu setting was successfully destroyed.' }
|
|
||||||
format.json { head :no_content }
|
format.json { head :no_content }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class ForksController < ApplicationController
|
class ForksController < ApplicationController
|
||||||
before_action :require_login
|
before_action :require_login
|
||||||
|
before_action :require_profile_completed, only: [:create]
|
||||||
before_action :load_project
|
before_action :load_project
|
||||||
before_action :authenticate_project!, :authenticate_user!
|
before_action :authenticate_project!, :authenticate_user!
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ class ForksController < ApplicationController
|
||||||
if current_user&.id == @project.user_id
|
if current_user&.id == @project.user_id
|
||||||
render_result(-1, "自己不能fork自己的项目")
|
render_result(-1, "自己不能fork自己的项目")
|
||||||
elsif Project.exists?(user_id: current_user.id, identifier: @project.identifier)
|
elsif Project.exists?(user_id: current_user.id, identifier: @project.identifier)
|
||||||
render_result(-1, "fork失败,你已拥有了这个项目")
|
render_result(0, "fork失败,你已拥有了这个项目")
|
||||||
end
|
end
|
||||||
# return if current_user != @project.owner
|
# return if current_user != @project.owner
|
||||||
# render_result(-1, "自己不能fork自己的项目")
|
# render_result(-1, "自己不能fork自己的项目")
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
class Helps::FaqsController < ApplicationController
|
||||||
|
skip_before_action :check_sign, :user_setup
|
||||||
|
|
||||||
|
def index
|
||||||
|
faqs = Faq.select_without_id.order(updated_at: :desc)
|
||||||
|
render json: faqs.as_json(:except => [:id])
|
||||||
|
end
|
||||||
|
end
|
|
@ -2,15 +2,12 @@ class IssueTagsController < ApplicationController
|
||||||
before_action :require_login, except: [:index]
|
before_action :require_login, except: [:index]
|
||||||
before_action :load_repository
|
before_action :load_repository
|
||||||
before_action :set_user
|
before_action :set_user
|
||||||
before_action :check_issue_permission, except: :index
|
before_action :check_issue_tags_permission
|
||||||
before_action :set_issue_tag, only: [:edit, :update, :destroy]
|
before_action :set_issue_tag, only: [:edit, :update, :destroy]
|
||||||
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
order_name = params[:order_name] || "created_at"
|
issue_tags = @project.issue_tags.reorder("#{order_name} #{order_type}")
|
||||||
order_type = params[:order_type] || "desc"
|
|
||||||
|
|
||||||
issue_tags = @project.issue_tags.order("#{order_name} #{order_type}")
|
|
||||||
@user_admin_or_member = current_user.present? && (current_user.admin || @project.member?(current_user))
|
@user_admin_or_member = current_user.present? && (current_user.admin || @project.member?(current_user))
|
||||||
@page = params[:page] || 1
|
@page = params[:page] || 1
|
||||||
@limit = params[:limit] || 15
|
@limit = params[:limit] || 15
|
||||||
|
@ -20,7 +17,7 @@ class IssueTagsController < ApplicationController
|
||||||
|
|
||||||
|
|
||||||
def create
|
def create
|
||||||
title = params[:name].to_s.strip.first(10)
|
title = params[:name].to_s.strip.first(15)
|
||||||
desc = params[:description].to_s.first(30)
|
desc = params[:description].to_s.first(30)
|
||||||
color = params[:color] || "#ccc"
|
color = params[:color] || "#ccc"
|
||||||
|
|
||||||
|
@ -32,7 +29,7 @@ class IssueTagsController < ApplicationController
|
||||||
|
|
||||||
if title.present?
|
if title.present?
|
||||||
if IssueTag.exists?(name: title, project_id: @project.id)
|
if IssueTag.exists?(name: title, project_id: @project.id)
|
||||||
normal_status(-1, "标签已存在")
|
normal_status(-1, "项目标记已存在")
|
||||||
else
|
else
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
|
@ -40,12 +37,12 @@ class IssueTagsController < ApplicationController
|
||||||
if issue_tag.save
|
if issue_tag.save
|
||||||
# gitea_tag = Gitea::Labels::CreateService.new(current_user, @repository.try(:identifier), tag_params).call
|
# gitea_tag = Gitea::Labels::CreateService.new(current_user, @repository.try(:identifier), tag_params).call
|
||||||
# if gitea_tag && issue_tag.update_attributes(gid: gitea_tag["id"], gitea_url: gitea_tag["url"])
|
# if gitea_tag && issue_tag.update_attributes(gid: gitea_tag["id"], gitea_url: gitea_tag["url"])
|
||||||
# normal_status(0, "标签创建成功")
|
normal_status(0, "项目标记创建成功!")
|
||||||
# else
|
# else
|
||||||
# normal_status(-1, "标签创建失败")
|
# normal_status(-1, "项目标记创建失败")
|
||||||
# end
|
# end
|
||||||
else
|
else
|
||||||
normal_status(-1, "标签创建失败")
|
normal_status(-1, "项目标记创建失败")
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
puts "create version release error: #{e.message}"
|
puts "create version release error: #{e.message}"
|
||||||
|
@ -54,7 +51,7 @@ class IssueTagsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
normal_status(-1, "标签名称不能为空")
|
normal_status(-1, "项目标记名称不能为空")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -63,8 +60,8 @@ class IssueTagsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
title = params[:name]
|
title = params[:name].to_s.strip.first(15)
|
||||||
desc = params[:description]
|
desc = params[:description].to_s.first(30)
|
||||||
color = params[:color] || "#ccc"
|
color = params[:color] || "#ccc"
|
||||||
|
|
||||||
tag_params = {
|
tag_params = {
|
||||||
|
@ -74,19 +71,19 @@ class IssueTagsController < ApplicationController
|
||||||
}
|
}
|
||||||
if title.present?
|
if title.present?
|
||||||
if IssueTag.exists?(name: title, project_id: @project.id) && (@issue_tag.name != title)
|
if IssueTag.exists?(name: title, project_id: @project.id) && (@issue_tag.name != title)
|
||||||
normal_status(-1, "标签已存在")
|
normal_status(-1, "项目标记已存在")
|
||||||
else
|
else
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
if @issue_tag.update_attributes(tag_params)
|
if @issue_tag.update_attributes(tag_params)
|
||||||
# gitea_tag = Gitea::Labels::UpdateService.new(current_user, @repository.try(:identifier),@issue_tag.try(:gid), tag_params).call
|
# gitea_tag = Gitea::Labels::UpdateService.new(current_user, @repository.try(:identifier),@issue_tag.try(:gid), tag_params).call
|
||||||
# if gitea_tag
|
# if gitea_tag
|
||||||
# normal_status(0, "标签更新成功")
|
# normal_status(0, "项目标记更新成功")
|
||||||
# else
|
# else
|
||||||
# normal_status(-1, "标签更新失败")
|
# normal_status(-1, "项目标记更新失败")
|
||||||
# end
|
# end
|
||||||
else
|
else
|
||||||
normal_status(-1, "标签更新失败")
|
normal_status(-1, "项目标记更新失败")
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
puts "create version release error: #{e.message}"
|
puts "create version release error: #{e.message}"
|
||||||
|
@ -95,7 +92,7 @@ class IssueTagsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
normal_status(-1, "标签名称不能为空")
|
normal_status(-1, "项目标记名称不能为空")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -105,12 +102,12 @@ class IssueTagsController < ApplicationController
|
||||||
if @issue_tag.destroy
|
if @issue_tag.destroy
|
||||||
# issue_tag = Gitea::Labels::DeleteService.new(@user, @repository.try(:identifier), @issue_tag.try(:gid)).call
|
# issue_tag = Gitea::Labels::DeleteService.new(@user, @repository.try(:identifier), @issue_tag.try(:gid)).call
|
||||||
# if issue_tag
|
# if issue_tag
|
||||||
# normal_status(0, "标签删除成功")
|
# normal_status(0, "项目标记删除成功")
|
||||||
# else
|
# else
|
||||||
# normal_status(-1, "标签删除失败")
|
# normal_status(-1, "项目标记删除失败")
|
||||||
# end
|
# end
|
||||||
else
|
else
|
||||||
normal_status(-1, "标签删除失败")
|
normal_status(-1, "项目标记删除失败")
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
puts "create version release error: #{e.message}"
|
puts "create version release error: #{e.message}"
|
||||||
|
@ -125,17 +122,27 @@ class IssueTagsController < ApplicationController
|
||||||
@user = @project.owner
|
@user = @project.owner
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_issue_permission
|
def check_issue_tags_permission
|
||||||
unless @project.member?(current_user) || current_user.admin?
|
unless @project.manager?(current_user) || current_user.admin?
|
||||||
normal_status(-1, "您没有权限")
|
return render_forbidden('你不是管理员,没有权限操作')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_issue_tag
|
def set_issue_tag
|
||||||
@issue_tag = IssueTag.find_by_id(params[:id])
|
@issue_tag = IssueTag.find_by_id(params[:id])
|
||||||
unless @issue_tag.present?
|
unless @issue_tag.present?
|
||||||
normal_status(-1, "标签不存在")
|
normal_status(-1, "项目标记不存在")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def order_name
|
||||||
|
IssueTag.column_names.include?(params[:order_name]) ? params[:order_name] : 'created_at'
|
||||||
|
end
|
||||||
|
|
||||||
|
def order_type
|
||||||
|
%w(desc asc).include?(params[:order_type]) ? params[:order_type] : 'desc'
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,29 +1,36 @@
|
||||||
class IssuesController < ApplicationController
|
class IssuesController < ApplicationController
|
||||||
before_action :require_login, except: [:index, :show, :index_chosen]
|
before_action :require_login, except: [:index, :show, :index_chosen]
|
||||||
|
before_action :require_profile_completed, only: [:create]
|
||||||
before_action :load_project
|
before_action :load_project
|
||||||
before_action :set_user
|
before_action :set_user
|
||||||
|
before_action :check_menu_authorize, except: [:index_chosen]
|
||||||
before_action :check_issue_permission
|
before_action :check_issue_permission
|
||||||
|
before_action :operate_issue_permission, only:[:create, :update, :destroy, :clean, :series_update, :copy]
|
||||||
before_action :check_project_public, only: [:index ,:show, :copy, :index_chosen, :close_issue]
|
before_action :check_project_public, only: [:index ,:show, :copy, :index_chosen, :close_issue]
|
||||||
|
|
||||||
before_action :set_issue, only: [:edit, :update, :destroy, :show, :copy, :close_issue, :lock_issue]
|
before_action :set_issue, only: [:edit, :update, :destroy, :show, :copy, :close_issue, :lock_issue]
|
||||||
before_action :check_token_enough, only: [:create, :update]
|
before_action :check_token_enough, :find_atme_receivers, only: [:create, :update]
|
||||||
|
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include TagChosenHelper
|
include TagChosenHelper
|
||||||
|
|
||||||
def index
|
def index
|
||||||
return render_not_found unless @project.has_menu_permission("issues")
|
@user_operate_issue = current_user.present? && current_user.logged? && (current_user.admin || @project.member?(current_user))
|
||||||
@user_admin_or_member = current_user.present? && current_user.logged? && (current_user.admin || @project.member?(current_user))
|
@user_admin_or_member = current_user.present? && current_user.logged? && (current_user.admin || @project.member?(current_user) || @project.is_public?)
|
||||||
issues = @project.issues.issue_issue.issue_index_includes
|
issues = @project.issues.issue_issue.issue_index_includes
|
||||||
issues = issues.where(is_private: false) unless @user_admin_or_member
|
issues = issues.where(is_private: false) unless @user_admin_or_member
|
||||||
|
|
||||||
@all_issues_size = issues.size
|
@all_issues = issues
|
||||||
@open_issues_size = issues.where.not(status_id: 5).size
|
@filter_issues = @all_issues
|
||||||
@close_issues_size = issues.where(status_id: 5).size
|
@filter_issues = @filter_issues.where.not(status_id: IssueStatus::CLOSED) if params[:status_type].to_i == IssueStatus::ADD
|
||||||
@assign_to_me_size = issues.where(assigned_to_id: current_user&.id).size
|
@filter_issues = @filter_issues.where(status_id: IssueStatus::CLOSED) if params[:status_type].to_i == IssueStatus::SOLVING
|
||||||
@my_published_size = issues.where(author_id: current_user&.id).size
|
@filter_issues = @filter_issues.where("subject LIKE ? OR description LIKE ? ", "%#{params[:search]}%", "%#{params[:search]}%") if params[:search].present?
|
||||||
|
@open_issues = @all_issues.where.not(status_id: IssueStatus::CLOSED)
|
||||||
|
@close_issues = @all_issues.where(status_id: IssueStatus::CLOSED)
|
||||||
scopes = Issues::ListQueryService.call(issues,params.delete_if{|k,v| v.blank?}, "Issue")
|
scopes = Issues::ListQueryService.call(issues,params.delete_if{|k,v| v.blank?}, "Issue")
|
||||||
@issues_size = scopes.size
|
@issues_size = scopes.size
|
||||||
|
@assign_to_me = scopes.where(assigned_to_id: current_user&.id)
|
||||||
|
@my_published = scopes.where(author_id: current_user&.id)
|
||||||
@issues = paginate(scopes)
|
@issues = paginate(scopes)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -105,6 +112,8 @@ class IssuesController < ApplicationController
|
||||||
Issues::CreateForm.new({subject:issue_params[:subject]}).validate!
|
Issues::CreateForm.new({subject:issue_params[:subject]}).validate!
|
||||||
@issue = Issue.new(issue_params)
|
@issue = Issue.new(issue_params)
|
||||||
if @issue.save!
|
if @issue.save!
|
||||||
|
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if Site.has_notice_menu?
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) if Site.has_notice_menu?
|
||||||
if params[:attachment_ids].present?
|
if params[:attachment_ids].present?
|
||||||
params[:attachment_ids].each do |id|
|
params[:attachment_ids].each do |id|
|
||||||
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
||||||
|
@ -117,9 +126,15 @@ class IssuesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if params[:issue_tag_ids].present?
|
if params[:issue_tag_ids].present?
|
||||||
params[:issue_tag_ids].each do |tag|
|
if params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size > 1
|
||||||
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
return normal_status(-1, "最多只能创建一个标记。")
|
||||||
end
|
elsif params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size == 1
|
||||||
|
params[:issue_tag_ids].each do |tag|
|
||||||
|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return normal_status(-1, "请输入正确的标记。")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if params[:assigned_to_id].present?
|
if params[:assigned_to_id].present?
|
||||||
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
|
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
|
||||||
|
@ -135,6 +150,12 @@ class IssuesController < ApplicationController
|
||||||
|
|
||||||
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||||
|
|
||||||
|
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) if params[:status_id].to_i == 5
|
||||||
|
|
||||||
|
|
||||||
|
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||||
|
AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0
|
||||||
|
|
||||||
# author: zxh
|
# author: zxh
|
||||||
# 扣除发起人的token
|
# 扣除发起人的token
|
||||||
blockchain_result = Blockchain::CreateIssue.call(user_id: @issue.author_id, project_id: @issue.project_id, token_num: @issue.blockchain_token_num)
|
blockchain_result = Blockchain::CreateIssue.call(user_id: @issue.author_id, project_id: @issue.project_id, token_num: @issue.blockchain_token_num)
|
||||||
|
@ -153,6 +174,7 @@ class IssuesController < ApplicationController
|
||||||
render json: {status: 0, message: "创建成功", id: @issue.id}
|
render json: {status: 0, message: "创建成功", id: @issue.id}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
render json: {status: 0, message: "创建成功", id: @issue.id}
|
||||||
else
|
else
|
||||||
normal_status(-1, "创建失败")
|
normal_status(-1, "创建失败")
|
||||||
end
|
end
|
||||||
|
@ -170,11 +192,19 @@ class IssuesController < ApplicationController
|
||||||
def update
|
def update
|
||||||
last_token = @issue.token
|
last_token = @issue.token
|
||||||
last_status_id = @issue.status_id
|
last_status_id = @issue.status_id
|
||||||
if params[:issue_tag_ids].present? && !@issue&.issue_tags_relates.where(issue_tag_id: params[:issue_tag_ids]).exists?
|
@issue&.issue_tags_relates&.destroy_all if params[:issue_tag_ids].blank?
|
||||||
@issue&.issue_tags_relates&.destroy_all
|
if params[:issue_tag_ids].present?
|
||||||
params[:issue_tag_ids].each do |tag|
|
if params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size > 1
|
||||||
IssueTagsRelate.create(issue_id: @issue.id, issue_tag_id: tag)
|
return normal_status(-1, "最多只能创建一个标记。")
|
||||||
end
|
elsif params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size == 1
|
||||||
|
@issue&.issue_tags_relates&.destroy_all
|
||||||
|
params[:issue_tag_ids].each do |tag|
|
||||||
|
next if tag == [""]
|
||||||
|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return normal_status(-1, "请输入正确的标记。")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
issue_files = params[:attachment_ids]
|
issue_files = params[:attachment_ids]
|
||||||
|
@ -214,9 +244,29 @@ class IssuesController < ApplicationController
|
||||||
issue_params = issue_send_params(params).except(:issue_classify, :author_id, :project_id)
|
issue_params = issue_send_params(params).except(:issue_classify, :author_id, :project_id)
|
||||||
Issues::UpdateForm.new({subject:issue_params[:subject]}).validate!
|
Issues::UpdateForm.new({subject:issue_params[:subject]}).validate!
|
||||||
if @issue.update_attributes(issue_params)
|
if @issue.update_attributes(issue_params)
|
||||||
|
if @issue&.pull_request.present?
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @issue&.pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value)) if Site.has_notice_menu?
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @issue&.pull_request&.id ) if @issue.previous_changes[:assigned_to_id].present? && Site.has_notice_menu?
|
||||||
|
else
|
||||||
|
previous_changes = @issue.previous_changes.slice(:status_id, :assigned_to_id, :tracker_id, :priority_id, :fixed_version_id, :done_ratio, :issue_tags_value, :branch_name)
|
||||||
|
if @issue.previous_changes[:start_date].present?
|
||||||
|
previous_changes.merge!(start_date: [@issue.previous_changes[:start_date][0].to_s, @issue.previous_changes[:start_date][1].to_s])
|
||||||
|
end
|
||||||
|
if @issue.previous_changes[:due_date].present?
|
||||||
|
previous_changes.merge!(due_date: [@issue.previous_changes[:due_date][0].to_s, @issue.previous_changes[:due_date][1].to_s])
|
||||||
|
end
|
||||||
|
if @issue.previous_changes[:status_id].present? && @issue.previous_changes[:status_id][1] == 5
|
||||||
|
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE)
|
||||||
|
end
|
||||||
|
if @issue.previous_changes[:status_id].present? && @issue.previous_changes[:status_id][0] == 5
|
||||||
|
@issue.project_trends.where(action_type: ProjectTrend::CLOSE).destroy_all
|
||||||
|
end
|
||||||
|
SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_changes) if Site.has_notice_menu?
|
||||||
|
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if @issue.previous_changes[:assigned_to_id].present? && Site.has_notice_menu?
|
||||||
|
end
|
||||||
if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时
|
if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时
|
||||||
@issue.issue_times.update_all(end_time: Time.now)
|
@issue.issue_times.update_all(end_time: Time.now)
|
||||||
@issue.update_closed_issues_count_in_project!
|
# @issue.update_closed_issues_count_in_project!
|
||||||
if @issue.issue_type.to_s == "2" && last_status_id != 5
|
if @issue.issue_type.to_s == "2" && last_status_id != 5
|
||||||
if @issue.assigned_to_id.present? && last_status_id == 3 #只有当用户完成100%时,才给token
|
if @issue.assigned_to_id.present? && last_status_id == 3 #只有当用户完成100%时,才给token
|
||||||
post_to_chain("add", @issue.token, @issue.get_assign_user.try(:login))
|
post_to_chain("add", @issue.token, @issue.get_assign_user.try(:login))
|
||||||
|
@ -232,7 +282,11 @@ class IssuesController < ApplicationController
|
||||||
change_type = change_token > 0 ? "add" : "minus"
|
change_type = change_token > 0 ? "add" : "minus"
|
||||||
post_to_chain(change_type, change_token.abs, current_user.try(:login))
|
post_to_chain(change_type, change_token.abs, current_user.try(:login))
|
||||||
end
|
end
|
||||||
@issue.create_journal_detail(change_files, issue_files, issue_file_ids, current_user&.id)
|
@issue.create_journal_detail(change_files, issue_files, issue_file_ids, current_user&.id) if @issue.previous_changes.present?
|
||||||
|
|
||||||
|
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||||
|
AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0
|
||||||
|
|
||||||
normal_status(0, "更新成功")
|
normal_status(0, "更新成功")
|
||||||
else
|
else
|
||||||
normal_status(-1, "更新失败")
|
normal_status(-1, "更新失败")
|
||||||
|
@ -244,7 +298,7 @@ class IssuesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@user_permission = current_user.present? && current_user.logged? && (!@issue.is_lock || @project.member?(current_user) || current_user.admin? || @issue.user == current_user)
|
@user_permission = current_user.present? && current_user.logged? && (@project.member?(current_user) || current_user.admin? || @issue.user == current_user)
|
||||||
@issue_attachments = @issue.attachments
|
@issue_attachments = @issue.attachments
|
||||||
@issue_user = @issue.user
|
@issue_user = @issue.user
|
||||||
@issue_assign_to = @issue.get_assign_user
|
@issue_assign_to = @issue.get_assign_user
|
||||||
|
@ -265,6 +319,7 @@ class IssuesController < ApplicationController
|
||||||
status_id = @issue.status_id
|
status_id = @issue.status_id
|
||||||
token = @issue.token
|
token = @issue.token
|
||||||
login = @issue.user.try(:login)
|
login = @issue.user.try(:login)
|
||||||
|
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigned_to_id, @issue.author_id) if Site.has_notice_menu?
|
||||||
if @issue.destroy
|
if @issue.destroy
|
||||||
if issue_type == "2" && status_id != 5
|
if issue_type == "2" && status_id != 5
|
||||||
post_to_chain("add", token, login)
|
post_to_chain("add", token, login)
|
||||||
|
@ -284,8 +339,12 @@ class IssuesController < ApplicationController
|
||||||
def clean
|
def clean
|
||||||
#批量删除,暂时只能删除未悬赏的
|
#批量删除,暂时只能删除未悬赏的
|
||||||
issue_ids = params[:ids]
|
issue_ids = params[:ids]
|
||||||
if issue_ids.present?
|
issues = Issue.where(id: issue_ids, issue_type: "1")
|
||||||
if Issue.where(id: issue_ids, issue_type: "1").destroy_all
|
if issues.present?
|
||||||
|
issues.find_each do |i|
|
||||||
|
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, i&.subject, i.assigned_to_id, i.author_id) if Site.has_notice_menu?
|
||||||
|
end
|
||||||
|
if issues.destroy_all
|
||||||
normal_status(0, "删除成功")
|
normal_status(0, "删除成功")
|
||||||
else
|
else
|
||||||
normal_status(-1, "删除失败")
|
normal_status(-1, "删除失败")
|
||||||
|
@ -315,9 +374,28 @@ class IssuesController < ApplicationController
|
||||||
# update_hash = params[:issue]
|
# update_hash = params[:issue]
|
||||||
issue_ids = params[:ids]
|
issue_ids = params[:ids]
|
||||||
if issue_ids.present?
|
if issue_ids.present?
|
||||||
|
issues = Issue.where(id: issue_ids)
|
||||||
if update_hash.blank?
|
if update_hash.blank?
|
||||||
normal_status(-1, "请选择批量更新内容")
|
normal_status(-1, "请选择批量更新内容")
|
||||||
elsif Issue.where(id: issue_ids).update_all(update_hash)
|
elsif issues&.update(update_hash)
|
||||||
|
issues.each do |i|
|
||||||
|
i.create_journal_detail(false, [], [], current_user&.id) if i.previous_changes.present?
|
||||||
|
previous_changes = i.previous_changes.slice(:status_id, :assigned_to_id, :tracker_id, :priority_id, :fixed_version_id, :done_ratio, :issue_tags_value, :branch_name)
|
||||||
|
if i.previous_changes[:start_date].present?
|
||||||
|
previous_changes.merge!(start_date: [i.previous_changes[:start_date][0].to_s, i.previous_changes[:start_date][1].to_s])
|
||||||
|
end
|
||||||
|
if i.previous_changes[:due_date].present?
|
||||||
|
previous_changes.merge!(due_date: [i.previous_changes[:due_date][0].to_s, i.previous_changes[:due_date][1].to_s])
|
||||||
|
end
|
||||||
|
if i.previous_changes[:status_id].present? && i.previous_changes[:status_id][1] == 5
|
||||||
|
i.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE)
|
||||||
|
end
|
||||||
|
if i.previous_changes[:status_id].present? && i.previous_changes[:status_id][0] == 5
|
||||||
|
i.project_trends.where(action_type: ProjectTrend::CLOSE).destroy_all
|
||||||
|
end
|
||||||
|
SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, i&.id, previous_changes) if Site.has_notice_menu?
|
||||||
|
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, i&.id) if i.previous_changes[:assigned_to_id].present? && Site.has_notice_menu?
|
||||||
|
end
|
||||||
normal_status(0, "批量更新成功")
|
normal_status(0, "批量更新成功")
|
||||||
else
|
else
|
||||||
normal_status(-1, "批量更新失败")
|
normal_status(-1, "批量更新失败")
|
||||||
|
@ -329,7 +407,10 @@ class IssuesController < ApplicationController
|
||||||
|
|
||||||
def copy
|
def copy
|
||||||
@new_issue = @issue.dup
|
@new_issue = @issue.dup
|
||||||
|
@new_issue.author_id = current_user.id
|
||||||
if @new_issue.save
|
if @new_issue.save
|
||||||
|
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @new_issue&.id) if Site.has_notice_menu?
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @new_issue&.id) if Site.has_notice_menu?
|
||||||
issue_tags = @issue.issue_tags.pluck(:id)
|
issue_tags = @issue.issue_tags.pluck(:id)
|
||||||
if issue_tags.present?
|
if issue_tags.present?
|
||||||
issue_tags.each do |tag|
|
issue_tags.each do |tag|
|
||||||
|
@ -407,25 +488,30 @@ class IssuesController < ApplicationController
|
||||||
|
|
||||||
def check_project_public
|
def check_project_public
|
||||||
unless @project.is_public || @project.member?(current_user) || current_user.admin? || (@project.user_id == current_user.id)
|
unless @project.is_public || @project.member?(current_user) || current_user.admin? || (@project.user_id == current_user.id)
|
||||||
normal_status(-1, "您没有权限")
|
return render_forbidden
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_issue
|
def set_issue
|
||||||
@issue = Issue.find_by_id(params[:id])
|
@issue = Issue.find_by_id(params[:id])
|
||||||
if @issue.blank?
|
if @issue.blank?
|
||||||
normal_status(-1, "标签不存在")
|
return render_not_found
|
||||||
elsif @issue.is_lock &&!(@project.member?(current_user) || current_user.admin?)
|
elsif !(@project.is_public || (current_user.present? && (@project.member?(current_user) || current_user&.admin? || (@project.user_id == current_user&.id))))
|
||||||
normal_status(-1, "您没有权限")
|
return render_forbidden
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_issue_permission
|
def check_issue_permission
|
||||||
unless @project.is_public || (current_user.present? && (@project.member?(current_user) || current_user&.admin? || (@project.user_id == current_user&.id)))
|
unless @project.is_public || (current_user.present? && (@project.member?(current_user) || current_user&.admin? || (@project.user_id == current_user&.id)))
|
||||||
normal_status(-1, "您没有权限")
|
return render_forbidden
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def operate_issue_permission
|
||||||
|
@issue = Issue.find_by_id(params[:id]) unless @issue.present?
|
||||||
|
return render_forbidden("您没有权限进行此操作.") unless current_user.present? && current_user.logged? && (current_user.admin? || @project.member?(current_user) || (@project.is_public && @issue.nil?) || (@project.is_public && @issue.present? && @issue.author_id == current_user.id))
|
||||||
|
end
|
||||||
|
|
||||||
def export_issues(issues)
|
def export_issues(issues)
|
||||||
@table_columns = %w(ID 类型 标题 描述 状态 指派给 优先级 标签 发布人 创建时间 里程碑 开始时间 截止时间 完成度 分类 金额 属于)
|
@table_columns = %w(ID 类型 标题 描述 状态 指派给 优先级 标签 发布人 创建时间 里程碑 开始时间 截止时间 完成度 分类 金额 属于)
|
||||||
@export_issues = []
|
@export_issues = []
|
||||||
|
@ -506,4 +592,8 @@ class IssuesController < ApplicationController
|
||||||
return normal_status(-1, "您的token值不足") if JSON.parse(response.body)["balance"].to_i < params[:token].to_i
|
return normal_status(-1, "您的token值不足") if JSON.parse(response.body)["balance"].to_i < params[:token].to_i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_menu_authorize
|
||||||
|
return render_not_found unless @project.has_menu_permission("issues")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class JournalsController < ApplicationController
|
class JournalsController < ApplicationController
|
||||||
before_action :require_login, except: [:index, :get_children_journals]
|
before_action :require_login, except: [:index, :get_children_journals]
|
||||||
|
before_action :require_profile_completed, :find_atme_receivers, only: [:create]
|
||||||
before_action :set_issue
|
before_action :set_issue
|
||||||
before_action :check_issue_permission
|
before_action :check_issue_permission
|
||||||
before_action :set_journal, only: [:destroy, :edit, :update]
|
before_action :set_journal, only: [:destroy, :edit, :update]
|
||||||
|
@ -42,6 +43,9 @@ class JournalsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||||
|
AtmeService.call(current_user, @atme_receivers, journal) if @atme_receivers.size > 0
|
||||||
|
# @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "journal")
|
||||||
|
|
||||||
# author: zxh
|
# author: zxh
|
||||||
# 调用上链API
|
# 调用上链API
|
||||||
|
@ -53,7 +57,7 @@ class JournalsController < ApplicationController
|
||||||
render json: {status: 0, message: "评论成功", id: journal.id}
|
render json: {status: 0, message: "评论成功", id: journal.id}
|
||||||
end
|
end
|
||||||
|
|
||||||
# @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "journal")
|
render :json => { status: 0, message: "评论成功", id: journal.id}
|
||||||
# normal_status(0, "评论成功")
|
# normal_status(0, "评论成功")
|
||||||
else
|
else
|
||||||
normal_status(-1, "评论失败")
|
normal_status(-1, "评论失败")
|
||||||
|
|
|
@ -23,9 +23,9 @@ class MainController < ApplicationController
|
||||||
|
|
||||||
# TODO: 这块之后需要整合,者架构重新变化,统一跳转到index后再路由分发
|
# TODO: 这块之后需要整合,者架构重新变化,统一跳转到index后再路由分发
|
||||||
if params[:path] && params[:path]&.include?("h5educoderbuild") && params[:path].split("/").first == "h5educoderbuild"
|
if params[:path] && params[:path]&.include?("h5educoderbuild") && params[:path].split("/").first == "h5educoderbuild"
|
||||||
render file: 'public/h5educoderbuild/index.html', :layout => false
|
render file: 'public/h5educoderbuild/index.html', :layout => false, :content_type=> 'text/html'
|
||||||
else
|
else
|
||||||
render file: 'public/react/build/index.html', :layout => false
|
render file: 'public/react/build/index.html', :layout => false, :content_type=> 'text/html'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,12 +2,15 @@ class MembersController < ApplicationController
|
||||||
before_action :require_login
|
before_action :require_login
|
||||||
before_action :load_project
|
before_action :load_project
|
||||||
before_action :find_user_with_id, only: %i[create remove change_role]
|
before_action :find_user_with_id, only: %i[create remove change_role]
|
||||||
before_action :operate!, except: %i[index]
|
before_action :check_user_profile_completed, only: [:create]
|
||||||
|
before_action :operate!
|
||||||
before_action :check_member_exists!, only: %i[create]
|
before_action :check_member_exists!, only: %i[create]
|
||||||
before_action :check_member_not_exists!, only: %i[remove change_role]
|
before_action :check_member_not_exists!, only: %i[remove change_role]
|
||||||
|
|
||||||
def create
|
def create
|
||||||
interactor = Projects::AddMemberInteractor.call(@project.owner, @project, @user)
|
interactor = Projects::AddMemberInteractor.call(@project.owner, @project, @user)
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu?
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectMemberJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu?
|
||||||
render_response(interactor)
|
render_response(interactor)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
@ -18,7 +21,7 @@ class MembersController < ApplicationController
|
||||||
scope = @project.members.includes(:roles, user: :user_extension)
|
scope = @project.members.includes(:roles, user: :user_extension)
|
||||||
search = params[:search].to_s.downcase
|
search = params[:search].to_s.downcase
|
||||||
role = params[:role].to_s
|
role = params[:role].to_s
|
||||||
scope = scope.joins(:user).where("LOWER(concat(users.lastname, users.firstname, users.login, users.mail)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present?
|
scope = scope.joins(:user).merge(User.like(search))
|
||||||
scope = scope.joins(:roles).where("roles.name LIKE ?", "%#{role}%") if role.present?
|
scope = scope.joins(:roles).where("roles.name LIKE ?", "%#{role}%") if role.present?
|
||||||
|
|
||||||
@total_count = scope.size
|
@total_count = scope.size
|
||||||
|
@ -27,6 +30,8 @@ class MembersController < ApplicationController
|
||||||
|
|
||||||
def remove
|
def remove
|
||||||
interactor = Projects::DeleteMemberInteractor.call(@project.owner, @project, @user)
|
interactor = Projects::DeleteMemberInteractor.call(@project.owner, @project, @user)
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectLeft', current_user.id, @user.id, @project.id) if Site.has_notice_menu?
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectMemberLeft', current_user.id, @user.id, @project.id) if Site.has_notice_menu?
|
||||||
render_response(interactor)
|
render_response(interactor)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
@ -35,6 +40,7 @@ class MembersController < ApplicationController
|
||||||
|
|
||||||
def change_role
|
def change_role
|
||||||
interactor = Projects::ChangeMemberRoleInteractor.call(@project.owner, @project, @user, params[:role])
|
interactor = Projects::ChangeMemberRoleInteractor.call(@project.owner, @project, @user, params[:role])
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectRole', current_user.id, @user.id, @project.id, message_role_name) if Site.has_notice_menu?
|
||||||
render_response(interactor)
|
render_response(interactor)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
@ -47,7 +53,7 @@ class MembersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def member_exists?
|
def member_exists?
|
||||||
@project.members.exists?(params[:user_id])
|
@project.members.exists?(user_id: params[:user_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def operate!
|
def operate!
|
||||||
|
@ -55,10 +61,24 @@ class MembersController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_member_exists!
|
def check_member_exists!
|
||||||
return render_result(1, "user_id为#{params[:user_id]}的用户已经是项目成员") if member_exists?
|
return render_error("user_id为#{params[:user_id]}的用户已经是项目成员") if member_exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_member_not_exists!
|
def check_member_not_exists!
|
||||||
return render_result(1, "user_id为#{params[:user_id]}的用户还不是项目成员") unless @project.member?(params[:user_id])
|
return render_error("user_id为#{params[:user_id]}的用户还不是项目成员") unless member_exists?
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_user_profile_completed
|
||||||
|
require_user_profile_completed(@user)
|
||||||
|
end
|
||||||
|
|
||||||
|
def message_role_name
|
||||||
|
case params[:role]
|
||||||
|
when 'Manager' then '管理员'
|
||||||
|
when 'Developer' then '开发者'
|
||||||
|
when 'Reporter' then '报告者'
|
||||||
|
else
|
||||||
|
''
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
class NoticesController < ApplicationController
|
||||||
|
|
||||||
|
def create
|
||||||
|
tip_exception("参数有误") if params["source"].blank?
|
||||||
|
user_id = params[:user_id]
|
||||||
|
|
||||||
|
if params["source"] == "CompetitionBegin"
|
||||||
|
competition_id = params[:competition_id]
|
||||||
|
SendTemplateMessageJob.perform_later('CompetitionBegin', user_id, competition_id)
|
||||||
|
elsif params["source"] == "CompetitionResult"
|
||||||
|
competition_id = params[:competition_id]
|
||||||
|
SendTemplateMessageJob.perform_later('CompetitionResult', user_id, competition_id)
|
||||||
|
elsif params["source"] == "CompetitionReview"
|
||||||
|
competition_id = params[:competition_id]
|
||||||
|
SendTemplateMessageJob.perform_later('CompetitionReview', user_id, competition_id)
|
||||||
|
else
|
||||||
|
tip_exception("#{params["source"]}未配置")
|
||||||
|
end
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
end
|
|
@ -61,6 +61,7 @@ class OauthController < ApplicationController
|
||||||
login = params[:login]
|
login = params[:login]
|
||||||
email = params[:mail]
|
email = params[:mail]
|
||||||
password = params[:password]
|
password = params[:password]
|
||||||
|
lastname = params[:lastname]
|
||||||
callback_url = params[:callback_url]
|
callback_url = params[:callback_url]
|
||||||
platform = params[:plathform] || 'educoder'
|
platform = params[:plathform] || 'educoder'
|
||||||
|
|
||||||
|
@ -72,8 +73,11 @@ class OauthController < ApplicationController
|
||||||
if result[:message].blank?
|
if result[:message].blank?
|
||||||
logger.info "[Oauth educoer] ====auto_register success"
|
logger.info "[Oauth educoer] ====auto_register success"
|
||||||
user = User.find result[:user][:id]
|
user = User.find result[:user][:id]
|
||||||
successful_authentication(user)
|
user.update_column(:lastname, params[:lastname])
|
||||||
|
autosync_register_trustie(login, password, email, lastname)
|
||||||
|
|
||||||
OpenUsers::Educoder.create!(user: user, uid: user.login)
|
OpenUsers::Educoder.create!(user: user, uid: user.login)
|
||||||
|
successful_authentication(user)
|
||||||
|
|
||||||
render json: { callback_url: callback_url }
|
render json: { callback_url: callback_url }
|
||||||
# redirect_to callback_url
|
# redirect_to callback_url
|
||||||
|
|
|
@ -5,7 +5,7 @@ class Organizations::OrganizationUsersController < Organizations::BaseController
|
||||||
def index
|
def index
|
||||||
@organization_users = @organization.organization_users.includes(:user)
|
@organization_users = @organization.organization_users.includes(:user)
|
||||||
search = params[:search].to_s.downcase
|
search = params[:search].to_s.downcase
|
||||||
@organization_users = @organization_users.joins(:user).where("LOWER(CONCAT_WS(users.lastname, users.firstname, users.login, users.mail)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present?
|
@organization_users = @organization_users.joins(:user).merge(User.like(search))
|
||||||
|
|
||||||
@organization_users = kaminari_paginate(@organization_users)
|
@organization_users = kaminari_paginate(@organization_users)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class Organizations::OrganizationsController < Organizations::BaseController
|
class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
before_action :require_login, except: [:index, :show]
|
before_action :require_login, except: [:index, :show, :recommend]
|
||||||
|
before_action :require_profile_completed, only: [:create]
|
||||||
before_action :convert_image!, only: [:create, :update]
|
before_action :convert_image!, only: [:create, :update]
|
||||||
before_action :load_organization, only: [:show, :update, :destroy]
|
before_action :load_organization, only: [:show, :update, :destroy]
|
||||||
before_action :check_user_can_edit_org, only: [:update, :destroy]
|
before_action :check_user_can_edit_org, only: [:update, :destroy]
|
||||||
|
@ -21,11 +22,13 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
@can_create_project = @organization.can_create_project?(current_user.id)
|
@can_create_project = @organization.can_create_project?(current_user.id)
|
||||||
@is_admin = can_edit_org?
|
@is_admin = can_edit_org?
|
||||||
@is_member = @organization.is_member?(current_user.id)
|
@is_member = @organization.is_member?(current_user.id)
|
||||||
|
Cache::V2::OwnerCommonService.new(@organization.id).read
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
Organizations::CreateForm.new(organization_params).validate!
|
tip_exception("无法使用以下关键词:#{organization_params[:name]},请重新命名") if ReversedKeyword.check_exists?(organization_params[:name])
|
||||||
|
Organizations::CreateForm.new(organization_params.merge(original_name: "")).validate!
|
||||||
@organization = Organizations::CreateService.call(current_user, organization_params)
|
@organization = Organizations::CreateService.call(current_user, organization_params)
|
||||||
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?
|
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?
|
||||||
end
|
end
|
||||||
|
@ -36,13 +39,14 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
Organizations::CreateForm.new(organization_params).validate!
|
Organizations::CreateForm.new(organization_params.merge(original_name: @organization.login)).validate!
|
||||||
login = @organization.login
|
login = @organization.login
|
||||||
@organization.login = organization_params[:name] if organization_params[:name].present?
|
@organization.login = organization_params[:name] if organization_params[:name].present?
|
||||||
@organization.nickname = organization_params[:nickname] if organization_params[:nickname].present?
|
@organization.nickname = organization_params[:nickname] if organization_params[:nickname].present?
|
||||||
@organization.save!
|
@organization.save!
|
||||||
@organization.organization_extension.update_attributes!(organization_params.except(:name, :nickname))
|
sync_organization_extension!
|
||||||
Gitea::Organization::UpdateService.call(@organization.gitea_token, login, @organization.reload)
|
|
||||||
|
Gitea::Organization::UpdateService.call(current_user.gitea_token, login, @organization.reload)
|
||||||
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?
|
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
@ -53,35 +57,28 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
def destroy
|
def destroy
|
||||||
tip_exception("密码不正确") unless current_user.check_password?(password)
|
tip_exception("密码不正确") unless current_user.check_password?(password)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
Gitea::Organization::DeleteService.call(@organization.gitea_token, @organization.login)
|
gitea_destroy = Gitea::Organization::DeleteService.call(current_user.gitea_token, @organization.login)
|
||||||
@organization.destroy!
|
if gitea_destroy[:status] == 204
|
||||||
|
@organization.destroy!
|
||||||
|
render_ok
|
||||||
|
elsif gitea_destroy[:status] == 500
|
||||||
|
tip_exception("当组织内含有仓库时,无法删除此组织")
|
||||||
|
else
|
||||||
|
tip_exception("")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
render_ok
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
tip_exception(e.message)
|
tip_exception(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def recommend
|
||||||
def convert_image!
|
recommend = %W(xuos Huawei_Technology openatom_foundation pkecosystem TensorLayer)
|
||||||
return unless params[:image].present?
|
|
||||||
max_size = EduSetting.get('upload_avatar_max_size') || 2 * 1024 * 1024 # 2M
|
@organizations = Organization.includes(:organization_extension).where(organization_extensions: {recommend: true}).to_a.each_slice(group_size).to_a
|
||||||
if params[:image].class == ActionDispatch::Http::UploadedFile
|
|
||||||
@image = params[:image]
|
|
||||||
render_error('请上传文件') if @image.size.zero?
|
|
||||||
render_error('文件大小超过限制') if @image.size > max_size.to_i
|
|
||||||
else
|
|
||||||
image = params[:image].to_s.strip
|
|
||||||
return render_error('请上传正确的图片') if image.blank?
|
|
||||||
@image = Util.convert_base64_image(image, max_size: max_size.to_i)
|
|
||||||
end
|
|
||||||
rescue Base64ImageConverter::Error => ex
|
|
||||||
render_error(ex.message)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def avatar_path(organization)
|
private
|
||||||
ApplicationController.helpers.disk_filename(organization.class, organization.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def organization_params
|
def organization_params
|
||||||
params.permit(:name, :description, :website, :location,
|
params.permit(:name, :description, :website, :location,
|
||||||
|
@ -89,6 +86,10 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
:max_repo_creation, :nickname)
|
:max_repo_creation, :nickname)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def group_size
|
||||||
|
params.fetch(:group_size, 4).to_i
|
||||||
|
end
|
||||||
|
|
||||||
def password
|
def password
|
||||||
params.fetch(:password, "")
|
params.fetch(:password, "")
|
||||||
end
|
end
|
||||||
|
@ -100,11 +101,25 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def sort_by
|
def sort_by
|
||||||
params.fetch(:sort_by, "created_at")
|
OrganizationExtension.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||||
end
|
end
|
||||||
|
|
||||||
def sort_direction
|
def sort_direction
|
||||||
params.fetch(:sort_direction, "desc")
|
%w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_max_repo_creation
|
||||||
|
organization_params[:max_repo_creation].blank? ? -1 : organization_params[:max_repo_creation]
|
||||||
|
end
|
||||||
|
|
||||||
|
def organization_extension_params
|
||||||
|
organization_params
|
||||||
|
.except(:name, :nickname)
|
||||||
|
.merge(max_repo_creation: set_max_repo_creation)
|
||||||
|
end
|
||||||
|
|
||||||
|
def sync_organization_extension!
|
||||||
|
@organization.organization_extension.update_attributes!(organization_extension_params)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -36,10 +36,10 @@ class Organizations::ProjectsController < Organizations::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def sort
|
def sort
|
||||||
params.fetch(:sort_by, "updated_on")
|
Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'updated_on'
|
||||||
end
|
end
|
||||||
|
|
||||||
def sort_direction
|
def sort_direction
|
||||||
params.fetch(:sort_direction, "desc")
|
%w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,6 +1,7 @@
|
||||||
class Organizations::TeamUsersController < Organizations::BaseController
|
class Organizations::TeamUsersController < Organizations::BaseController
|
||||||
before_action :load_organization, :load_team
|
before_action :load_organization, :load_team
|
||||||
before_action :load_operate_user, only: [:create, :destroy]
|
before_action :load_operate_user, only: [:create, :destroy]
|
||||||
|
before_action :check_user_profile_completed, only: [:create]
|
||||||
before_action :load_team_user, only: [:destroy]
|
before_action :load_team_user, only: [:destroy]
|
||||||
before_action :check_user_can_edit_org, only: [:create, :destroy]
|
before_action :check_user_can_edit_org, only: [:create, :destroy]
|
||||||
|
|
||||||
|
@ -8,7 +9,7 @@ class Organizations::TeamUsersController < Organizations::BaseController
|
||||||
@team_users = @team.team_users.includes(:user)
|
@team_users = @team.team_users.includes(:user)
|
||||||
|
|
||||||
search = params[:search].to_s.downcase
|
search = params[:search].to_s.downcase
|
||||||
@team_users = @team_users.joins(:user).where("LOWER(CONCAT_WS(users.lastname, users.firstname, users.login, users.mail, users.nickname)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present?
|
@team_users = @team_users.joins(:user).merge(User.like(search))
|
||||||
|
|
||||||
@team_users = kaminari_paginate(@team_users)
|
@team_users = kaminari_paginate(@team_users)
|
||||||
end
|
end
|
||||||
|
@ -17,6 +18,7 @@ class Organizations::TeamUsersController < Organizations::BaseController
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
@team_user = TeamUser.build(@organization.id, @operate_user.id, @team.id)
|
@team_user = TeamUser.build(@organization.id, @operate_user.id, @team.id)
|
||||||
@organization_user = OrganizationUser.build(@organization.id, @operate_user.id)
|
@organization_user = OrganizationUser.build(@organization.id, @operate_user.id)
|
||||||
|
SendTemplateMessageJob.perform_later('TeamJoined', @operate_user.id, @organization.id, @team.id) if Site.has_notice_menu?
|
||||||
Gitea::Organization::TeamUser::CreateService.call(@organization.gitea_token, @team.gtid, @operate_user.login)
|
Gitea::Organization::TeamUser::CreateService.call(@organization.gitea_token, @team.gtid, @operate_user.login)
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
@ -29,6 +31,12 @@ class Organizations::TeamUsersController < Organizations::BaseController
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
@team_user.destroy!
|
@team_user.destroy!
|
||||||
Gitea::Organization::TeamUser::DeleteService.call(@organization.gitea_token, @team.gtid, @operate_user.login)
|
Gitea::Organization::TeamUser::DeleteService.call(@organization.gitea_token, @team.gtid, @operate_user.login)
|
||||||
|
SendTemplateMessageJob.perform_later('TeamLeft', @operate_user.id, @organization.id, @team.id) if Site.has_notice_menu?
|
||||||
|
org_team_users = @organization.team_users.where(user_id: @operate_user.id)
|
||||||
|
unless org_team_users.present?
|
||||||
|
@organization.organization_users.find_by(user_id: @operate_user.id).destroy!
|
||||||
|
Gitea::Organization::OrganizationUser::DeleteService.call(@organization.gitea_token, @organization.login, @operate_user.login)
|
||||||
|
end
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
@ -43,6 +51,11 @@ class Organizations::TeamUsersController < Organizations::BaseController
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
@team_user.destroy!
|
@team_user.destroy!
|
||||||
Gitea::Organization::TeamUser::DeleteService.call(@organization.gitea_token, @team.gtid, current_user.login)
|
Gitea::Organization::TeamUser::DeleteService.call(@organization.gitea_token, @team.gtid, current_user.login)
|
||||||
|
org_team_users = @organization.team_users.where(user_id: current_user.id)
|
||||||
|
unless org_team_users.present?
|
||||||
|
@organization.organization_users.find_by(user_id: current_user.id).destroy!
|
||||||
|
Gitea::Organization::OrganizationUser::DeleteService.call(@organization.gitea_token, @organization.login, current_user.login)
|
||||||
|
end
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
@ -73,4 +86,8 @@ class Organizations::TeamUsersController < Organizations::BaseController
|
||||||
tip_exception("组织团队成员不存在") if @team_user.nil?
|
tip_exception("组织团队成员不存在") if @team_user.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_user_profile_completed
|
||||||
|
require_user_profile_completed(@operate_user)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -4,15 +4,24 @@ class Organizations::TeamsController < Organizations::BaseController
|
||||||
before_action :check_user_can_edit_org, only: [:create, :update, :destroy]
|
before_action :check_user_can_edit_org, only: [:create, :update, :destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
#if @organization.is_owner?(current_user) || current_user.admin?
|
|
||||||
@teams = @organization.teams
|
|
||||||
#else
|
|
||||||
# @teams = @organization.teams.joins(:team_users).where(team_users: {user_id: current_user.id})
|
|
||||||
#end
|
|
||||||
@is_admin = can_edit_org?
|
|
||||||
@teams = @teams.includes(:team_units, :team_users)
|
|
||||||
|
|
||||||
@teams = kaminari_paginate(@teams)
|
if params[:is_full].present?
|
||||||
|
if can_edit_org?
|
||||||
|
@teams = @organization.teams
|
||||||
|
else
|
||||||
|
@teams = []
|
||||||
|
end
|
||||||
|
else
|
||||||
|
#if @organization.is_owner?(current_user) || current_user.admin?
|
||||||
|
@teams = @organization.teams
|
||||||
|
#else
|
||||||
|
# @teams = @organization.teams.joins(:team_users).where(team_users: {user_id: current_user.id})
|
||||||
|
#end
|
||||||
|
@is_admin = can_edit_org?
|
||||||
|
@teams = @teams.includes(:team_units, :team_users)
|
||||||
|
|
||||||
|
@teams = kaminari_paginate(@teams)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def search
|
def search
|
||||||
|
@ -34,8 +43,12 @@ class Organizations::TeamsController < Organizations::BaseController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
Organizations::CreateTeamForm.new(team_params).validate!
|
if @organization.teams.count >= 50
|
||||||
@team = Organizations::Teams::CreateService.call(current_user, @organization, team_params)
|
return tip_exception("组织的团队数量已超过限制!")
|
||||||
|
else
|
||||||
|
Organizations::CreateTeamForm.new(team_params).validate!
|
||||||
|
@team = Organizations::Teams::CreateService.call(current_user, @organization, team_params)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class OwnersController < ApplicationController
|
class OwnersController < ApplicationController
|
||||||
before_action :require_login
|
before_action :require_login, only: [:index]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@owners = []
|
@owners = []
|
||||||
|
@ -9,4 +9,52 @@ class OwnersController < ApplicationController
|
||||||
teams: {can_create_org_project: true})
|
teams: {can_create_org_project: true})
|
||||||
.distinct
|
.distinct
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
def show
|
||||||
|
@owner = Owner.find_by(login: params[:id]) || Owner.find_by(id: params[:id])
|
||||||
|
return render_ok(type: 'User') unless @owner.present?
|
||||||
|
# 组织
|
||||||
|
if @owner.is_a?(Organization)
|
||||||
|
return render_forbidden("没有查看组织的权限") if org_limited_condition || org_privacy_condition
|
||||||
|
@can_create_project = @owner.can_create_project?(current_user.id)
|
||||||
|
@is_admin = current_user.admin? || @owner.is_owner?(current_user.id)
|
||||||
|
@is_member = @owner.is_member?(current_user.id)
|
||||||
|
# 用户
|
||||||
|
elsif @owner.is_a?(User)
|
||||||
|
#待办事项,现在未做
|
||||||
|
if User.current.admin? || User.current.login == @owner.login
|
||||||
|
@waiting_applied_messages = @owner.applied_messages.waiting
|
||||||
|
@common_applied_transfer_projects = AppliedTransferProject.where(owner_id: @owner.id).common + AppliedTransferProject.where(owner_id: Organization.joins(team_users: :team).where(team_users: {user_id: @owner.id}, teams: {authorize: %w(admin owner)} )).common
|
||||||
|
@common_applied_projects = AppliedProject.where(project_id: @owner.full_admin_projects).common
|
||||||
|
@undo_events = @waiting_applied_messages.size + @common_applied_transfer_projects.size + @common_applied_projects.size
|
||||||
|
else
|
||||||
|
@waiting_applied_messages = AppliedMessage.none
|
||||||
|
@common_applied_transfer_projects = AppliedTransferProject.none
|
||||||
|
@common_applied_projects = AppliedProject.none
|
||||||
|
@undo_events = 0
|
||||||
|
end
|
||||||
|
#用户的组织数量
|
||||||
|
# @user_composes_count = @user.composes.size
|
||||||
|
@user_composes_count = 0
|
||||||
|
user_organizations = User.current.logged? ? @owner.organizations.with_visibility(%w(common limited)) + @owner.organizations.with_visibility("privacy").joins(:team_users).where(team_users: {user_id: current_user.id}) : @owner.organizations.with_visibility("common")
|
||||||
|
@user_org_count = user_organizations.size
|
||||||
|
normal_projects = Project.members_projects(@owner.id).to_sql
|
||||||
|
org_projects = Project.joins(team_projects: [team: :team_users]).where(team_users: {user_id: @owner.id}).to_sql
|
||||||
|
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct
|
||||||
|
user_projects = User.current.logged? && (User.current.admin? || User.current.login == @owner.login) ? projects : projects.visible
|
||||||
|
@projects_common_count = user_projects.common.size
|
||||||
|
@projects_mirrior_count = user_projects.mirror.size
|
||||||
|
@projects_sync_mirrior_count = user_projects.sync_mirror.size
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def org_limited_condition
|
||||||
|
@owner.organization_extension.limited? && !current_user.logged?
|
||||||
|
end
|
||||||
|
|
||||||
|
def org_privacy_condition
|
||||||
|
return false if current_user.admin?
|
||||||
|
@owner.organization_extension.privacy? && @owner.organization_users.where(user_id: current_user.id).blank?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class PraiseTreadController < ApplicationController
|
class PraiseTreadController < ApplicationController
|
||||||
before_action :require_login, except: %i[index]
|
before_action :require_login, except: %i[index]
|
||||||
|
before_action :require_profile_completed, only: [:like]
|
||||||
before_action :find_project_with_id
|
before_action :find_project_with_id
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@ -11,6 +12,7 @@ class PraiseTreadController < ApplicationController
|
||||||
begin
|
begin
|
||||||
return normal_status(2, "你已点过赞了") if current_user.liked?(@project)
|
return normal_status(2, "你已点过赞了") if current_user.liked?(@project)
|
||||||
current_user.like!(@project)
|
current_user.like!(@project)
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectPraised', current_user.id, @project.id) if Site.has_notice_menu?
|
||||||
render_ok({praises_count: @project.praises_count, praised: current_user.liked?(@project)})
|
render_ok({praises_count: @project.praises_count, praised: current_user.liked?(@project)})
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
|
|
@ -5,6 +5,10 @@ class ProjectCategoriesController < ApplicationController
|
||||||
@project_categories = q.result(distinct: true)
|
@project_categories = q.result(distinct: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def pinned_index
|
||||||
|
@project_categories = ProjectCategory.where.not(pinned_index: 0).order(pinned_index: :desc)
|
||||||
|
end
|
||||||
|
|
||||||
def group_list
|
def group_list
|
||||||
@project_categories = ProjectCategory.where('projects_count > 0').order(projects_count: :desc)
|
@project_categories = ProjectCategory.where('projects_count > 0').order(projects_count: :desc)
|
||||||
# projects = Project.no_anomory_projects.visible
|
# projects = Project.no_anomory_projects.visible
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
class ProjectRankController < ApplicationController
|
||||||
|
# 根据时间获取热门项目
|
||||||
|
def index
|
||||||
|
$redis_cache.zunionstore("recent-days-project-rank", get_timeable_key_names)
|
||||||
|
deleted_data = $redis_cache.smembers("v2-project-rank-deleted")
|
||||||
|
$redis_cache.zrem("recent-days-project-rank", deleted_data) unless deleted_data.blank?
|
||||||
|
@project_rank = $redis_cache.zrevrange("recent-days-project-rank", 0, 4, withscores: true)
|
||||||
|
rescue Exception => e
|
||||||
|
@project_rank = []
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
# 默认显示7天的
|
||||||
|
def time
|
||||||
|
params.fetch(:time, 7).to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_timeable_key_names
|
||||||
|
names_array = []
|
||||||
|
(0...time).to_a.each do |i|
|
||||||
|
date_time_string = (Date.today - i.days).to_s
|
||||||
|
names_array << "v2-project-rank-#{date_time_string}"
|
||||||
|
end
|
||||||
|
names_array
|
||||||
|
end
|
||||||
|
end
|
|
@ -3,7 +3,7 @@ class ProjectTrendsController < ApplicationController
|
||||||
before_action :check_project_public
|
before_action :check_project_public
|
||||||
|
|
||||||
def index
|
def index
|
||||||
project_trends = @project.project_trends.includes(:user, trend: :user)
|
project_trends = @project.project_trends.preload(:user, trend: :user, project: :owner)
|
||||||
|
|
||||||
check_time = params[:time] #时间的筛选
|
check_time = params[:time] #时间的筛选
|
||||||
check_type = params[:type] #动态类型的筛选,目前已知的有 Issue, PullRequest, Version
|
check_type = params[:type] #动态类型的筛选,目前已知的有 Issue, PullRequest, Version
|
||||||
|
@ -14,20 +14,25 @@ class ProjectTrendsController < ApplicationController
|
||||||
project_trends = project_trends.where("created_at between ? and ?",(Time.now.beginning_of_day - check_time.days), Time.now.end_of_day)
|
project_trends = project_trends.where("created_at between ? and ?",(Time.now.beginning_of_day - check_time.days), Time.now.end_of_day)
|
||||||
end
|
end
|
||||||
|
|
||||||
@project_open_issues_count = project_trends.where(trend_type: "Issue", action_type: "create").size
|
|
||||||
@project_close_issues_count = project_trends.where(trend_type: "Issue", action_type: "close").size
|
@project_close_issues_count = project_trends.where(trend_type: "Issue", action_type: "close").size
|
||||||
@project_issues_count = @project_open_issues_count + @project_close_issues_count
|
@project_issues_count = project_trends.where(trend_type: "Issue", action_type: "create").size
|
||||||
|
@project_open_issues_count = @project_issues_count - @project_close_issues_count
|
||||||
@project_pr_count = project_trends.where(trend_type: "PullRequest", action_type: "close").size
|
|
||||||
@project_new_pr_count = project_trends.where(trend_type: "PullRequest", action_type: "create").size
|
|
||||||
@project_pr_all_count = @project_pr_count + @project_new_pr_count
|
|
||||||
|
|
||||||
|
@project_pr_count = project_trends.where(trend_type: "PullRequest", action_type: ["close", "merge"]).size
|
||||||
|
@project_pr_all_count = project_trends.where(trend_type: "PullRequest", action_type: "create").size
|
||||||
|
@project_new_pr_count = @project_pr_all_count - @project_pr_count
|
||||||
if check_type.present?
|
if check_type.present?
|
||||||
project_trends = project_trends.where(trend_type: check_type.to_s.strip)
|
project_trends = project_trends.where(trend_type: check_type.to_s.strip)
|
||||||
end
|
end
|
||||||
|
|
||||||
if check_status.present?
|
if check_status.present?
|
||||||
project_trends = project_trends.where(action_type: check_status.to_s.strip)
|
if check_status == "delay" || check_status == "close"
|
||||||
|
project_trends = project_trends.where(action_type: ["close", "merge"])
|
||||||
|
else
|
||||||
|
project_trends = project_trends.where(action_type: ["create"]).where.not(trend_id: project_trends.where(action_type: ["close", "merge"]).pluck(:trend_id))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
project_trends = project_trends.where(action_type: "create")
|
||||||
end
|
end
|
||||||
project_trends = project_trends.order("created_at desc")
|
project_trends = project_trends.order("created_at desc")
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
class Projects::AppliedTransferProjectsController < Projects::BaseController
|
class Projects::AppliedTransferProjectsController < Projects::BaseController
|
||||||
before_action :check_auth
|
before_action :check_auth
|
||||||
|
before_action :check_user_profile_completed, only: [:create]
|
||||||
|
|
||||||
def organizations
|
def organizations
|
||||||
@organizations = Organization.includes(:organization_extension).joins(team_users: :team).where(team_users: {user_id: current_user.id}, teams: {authorize: %w(admin owner)})
|
@organizations = Organization.includes(:organization_extension).joins(team_users: :team).where(team_users: {user_id: current_user.id}, teams: {authorize: %w(admin owner)})
|
||||||
|
@ -23,4 +24,10 @@ class Projects::AppliedTransferProjectsController < Projects::BaseController
|
||||||
def check_auth
|
def check_auth
|
||||||
return render_forbidden unless current_user.admin? ||@project.owner?(current_user)
|
return render_forbidden unless current_user.admin? ||@project.owner?(current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_user_profile_completed
|
||||||
|
@owner = Owner.find_by(login: params[:owner_name])
|
||||||
|
return if @owner.is_a?(Organization)
|
||||||
|
require_user_profile_completed(@owner)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -4,4 +4,7 @@ class Projects::BaseController < ApplicationController
|
||||||
before_action :load_project
|
before_action :load_project
|
||||||
before_action :load_repository
|
before_action :load_repository
|
||||||
|
|
||||||
|
def require_manager!
|
||||||
|
return render_forbidden('你没有权限操作') unless current_user.admin? || @project.manager?(current_user)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class Projects::MembersController < Projects::BaseController
|
||||||
|
def index
|
||||||
|
users = @project.all_collaborators.like(params[:search]).includes(:user_extension)
|
||||||
|
@users = kaminari_paginate(users)
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,4 +1,5 @@
|
||||||
class Projects::ProjectAppliesController < Projects::BaseController
|
class Projects::ProjectAppliesController < Projects::BaseController
|
||||||
|
before_action :require_profile_completed, only: [:create]
|
||||||
def create
|
def create
|
||||||
project = Projects::ApplyJoinService.call(current_user, create_params)
|
project = Projects::ApplyJoinService.call(current_user, create_params)
|
||||||
render_ok(project_id: project.id)
|
render_ok(project_id: project.id)
|
||||||
|
|
|
@ -6,7 +6,8 @@ class Projects::ProjectUnitsController < Projects::BaseController
|
||||||
def create
|
def create
|
||||||
if current_user.admin? || @project.manager?(current_user)
|
if current_user.admin? || @project.manager?(current_user)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
ProjectUnit.update_by_unit_types!(@project, unit_types)
|
before_units, after_units = ProjectUnit.update_by_unit_types!(@project, unit_types)
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, {navbar: true}) unless before_units.eql?(after_units) if Site.has_notice_menu?
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Projects::TeamsController < Projects::BaseController
|
||||||
def create
|
def create
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
@team_project = TeamProject.build(@owner.id, @operate_team.id, @project.id)
|
@team_project = TeamProject.build(@owner.id, @operate_team.id, @project.id)
|
||||||
Gitea::Organization::TeamProject::CreateService.call(@owner.gitea_token, @operate_team.gtid, @owner.login, @project.identifier)
|
Gitea::Organization::TeamProject::CreateService.call(current_user.gitea_token, @operate_team.gtid, @owner.login, @project.identifier)
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
@ -25,7 +25,7 @@ class Projects::TeamsController < Projects::BaseController
|
||||||
def destroy
|
def destroy
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
@team_project.destroy!
|
@team_project.destroy!
|
||||||
Gitea::Organization::TeamProject::DeleteService.call(@owner.gitea_token, @operate_team.gtid, @owner.login, @project.identifier)
|
Gitea::Organization::TeamProject::DeleteService.call(current_user.gitea_token, @operate_team.gtid, @owner.login, @project.identifier)
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
|
@ -0,0 +1,116 @@
|
||||||
|
class Projects::WebhooksController < Projects::BaseController
|
||||||
|
before_action :require_manager!
|
||||||
|
before_action :find_webhook, only:[:edit, :update, :destroy, :tasks, :test]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@webhooks = @project.webhooks
|
||||||
|
@webhooks = kaminari_paginate(@webhooks)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
return render_error("webhooks数量已到上限!请删除暂不使用的webhooks以进行添加操作") if @project.webhooks.size > 19
|
||||||
|
return render_error("参数错误.") unless webhook_params.present?
|
||||||
|
form = Projects::Webhooks::CreateForm.new(webhook_params)
|
||||||
|
return render json: {status: -1, message: form.errors} unless form.validate!
|
||||||
|
response = Gitea::Repository::Webhooks::CreateService.new(operating_token, @project&.owner&.login, @project&.identifier, gitea_webhooks_params).call
|
||||||
|
if response[0] == 201
|
||||||
|
@webhook = response[2]
|
||||||
|
else
|
||||||
|
render_error("创建失败.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
return render_error("参数错误.") unless webhook_params.present?
|
||||||
|
form = Projects::Webhooks::CreateForm.new(webhook_params)
|
||||||
|
return render json: {status: -1, message: form.errors} unless form.validate!
|
||||||
|
response = Gitea::Repository::Webhooks::UpdateService.call(operating_token, @project&.owner&.login, @project&.identifier, @webhook.id, gitea_webhooks_params)
|
||||||
|
if response[0] == 200
|
||||||
|
@webhook = response[2]
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error("更新失败.")
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
response = Gitea::Repository::Webhooks::DeleteService.call(operating_token, @project&.owner&.login, @project&.identifier, @webhook.id)
|
||||||
|
if response[0] == 204
|
||||||
|
@webhook = response[2]
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error("删除失败.")
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def tasks
|
||||||
|
@tasks = @webhook.tasks.where(is_delivered: true).order("delivered desc")
|
||||||
|
@tasks = kaminari_paginate(@tasks)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
response = Gitea::Repository::Webhooks::TestService.call(operating_token, @project&.owner&.login, @project&.identifier, @webhook.id)
|
||||||
|
if response[0] == 204
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error("测试推送失败.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def find_webhook
|
||||||
|
@webhook = @project.webhooks.find_by_id(params[:id])
|
||||||
|
return render_not_found if @webhook.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def webhook_params
|
||||||
|
params.require(:webhook).permit(:url, :type, :http_method, :content_type, :secret, :active, :branch_filter, events: [])
|
||||||
|
end
|
||||||
|
|
||||||
|
def webhook_type
|
||||||
|
webhook_params.fetch(:type, "gitea")
|
||||||
|
end
|
||||||
|
|
||||||
|
def webhook_branch_filter
|
||||||
|
webhook_params.fetch(:branch_filter, "*")
|
||||||
|
end
|
||||||
|
|
||||||
|
def gitea_webhooks_params
|
||||||
|
{
|
||||||
|
active: webhook_params[:active],
|
||||||
|
branch_filter: webhook_branch_filter,
|
||||||
|
config: {
|
||||||
|
content_type: webhook_params[:content_type],
|
||||||
|
url: webhook_params[:url],
|
||||||
|
http_method: webhook_params[:http_method],
|
||||||
|
secret: webhook_params[:secret]
|
||||||
|
},
|
||||||
|
events: webhook_params[:events],
|
||||||
|
type: webhook_type,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def operating_token
|
||||||
|
@project.member?(current_user) ? current_user.gitea_token : @project&.owner&.gitea_token
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,8 +4,9 @@ class ProjectsController < ApplicationController
|
||||||
include ProjectsHelper
|
include ProjectsHelper
|
||||||
include Acceleratorable
|
include Acceleratorable
|
||||||
|
|
||||||
before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users recommend about menu_list]
|
before_action :require_login, except: %i[index branches branches_slice group_type_list simple show fork_users praise_users watch_users recommend banner_recommend about menu_list]
|
||||||
before_action :load_project, except: %i[index group_type_list migrate create recommend]
|
before_action :require_profile_completed, only: [:create, :migrate]
|
||||||
|
before_action :load_repository, except: %i[index group_type_list migrate create recommend banner_recommend]
|
||||||
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
before_action :authorizate_user_can_edit_project!, only: %i[update]
|
||||||
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
before_action :project_public?, only: %i[fork_users praise_users watch_users]
|
||||||
|
|
||||||
|
@ -15,21 +16,22 @@ class ProjectsController < ApplicationController
|
||||||
menu.append(menu_hash_by_name("home"))
|
menu.append(menu_hash_by_name("home"))
|
||||||
menu.append(menu_hash_by_name("code")) if @project.has_menu_permission("code")
|
menu.append(menu_hash_by_name("code")) if @project.has_menu_permission("code")
|
||||||
menu.append(menu_hash_by_name("issues")) if @project.has_menu_permission("issues")
|
menu.append(menu_hash_by_name("issues")) if @project.has_menu_permission("issues")
|
||||||
menu.append(menu_hash_by_name("pulls")) if @project.has_menu_permission("pulls")
|
menu.append(menu_hash_by_name("pulls")) if @project.has_menu_permission("pulls") && @project.forge?
|
||||||
menu.append(menu_hash_by_name("devops")) if @project.has_menu_permission("devops")
|
menu.append(menu_hash_by_name("devops")) if @project.has_menu_permission("devops") && @project.forge?
|
||||||
menu.append(menu_hash_by_name("versions")) if @project.has_menu_permission("versions")
|
menu.append(menu_hash_by_name("versions")) if @project.has_menu_permission("versions")
|
||||||
menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources")
|
menu.append(menu_hash_by_name("wiki")) if @project.has_menu_permission("wiki") && @project.forge?
|
||||||
|
menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources") && @project.forge?
|
||||||
menu.append(menu_hash_by_name("activity"))
|
menu.append(menu_hash_by_name("activity"))
|
||||||
menu.append(menu_hash_by_name("setting")) if current_user.admin? || @project.manager?(current_user)
|
menu.append(menu_hash_by_name("settings")) if (current_user.admin? || @project.manager?(current_user)) && @project.forge?
|
||||||
|
|
||||||
render json: menu
|
render json: menu
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
scope = Projects::ListQuery.call(params)
|
scope = current_user.logged? ? Projects::ListQuery.call(params, current_user.id) : Projects::ListQuery.call(params)
|
||||||
|
|
||||||
# @projects = kaminari_paginate(scope)
|
@projects = kaminari_paginate(scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units))
|
||||||
@projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units)
|
# @projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units)
|
||||||
|
|
||||||
category_id = params[:category_id]
|
category_id = params[:category_id]
|
||||||
@total_count =
|
@total_count =
|
||||||
|
@ -57,7 +59,7 @@ class ProjectsController < ApplicationController
|
||||||
Projects::MigrateForm.new(mirror_params).validate!
|
Projects::MigrateForm.new(mirror_params).validate!
|
||||||
|
|
||||||
@project =
|
@project =
|
||||||
if enable_accelerator?(mirror_params[:clone_addr])
|
if EduSetting.get("mirror_address").to_s.include?("github") && enable_accelerator?(mirror_params[:clone_addr])
|
||||||
source_clone_url = mirror_params[:clone_addr]
|
source_clone_url = mirror_params[:clone_addr]
|
||||||
uid_logger("########## 已动加速器 ##########")
|
uid_logger("########## 已动加速器 ##########")
|
||||||
result = Gitea::Accelerator::MigrateService.call(mirror_params)
|
result = Gitea::Accelerator::MigrateService.call(mirror_params)
|
||||||
|
@ -69,6 +71,11 @@ class ProjectsController < ApplicationController
|
||||||
else
|
else
|
||||||
Projects::MigrateService.call(current_user, mirror_params)
|
Projects::MigrateService.call(current_user, mirror_params)
|
||||||
end
|
end
|
||||||
|
elsif EduSetting.get("mirror_address").to_s.include?("cnpmjs") && mirror_params[:clone_addr].include?("github.com")
|
||||||
|
source_clone_url = mirror_params[:clone_addr]
|
||||||
|
clone_url = source_clone_url.gsub('github.com', 'github.com.cnpmjs.org')
|
||||||
|
uid_logger("########## 更改clone_addr ##########")
|
||||||
|
Projects::MigrateService.call(current_user, mirror_params.merge(source_clone_url: source_clone_url, clone_addr: clone_url))
|
||||||
else
|
else
|
||||||
Projects::MigrateService.call(current_user, mirror_params)
|
Projects::MigrateService.call(current_user, mirror_params)
|
||||||
end
|
end
|
||||||
|
@ -80,8 +87,16 @@ class ProjectsController < ApplicationController
|
||||||
def branches
|
def branches
|
||||||
return @branches = [] unless @project.forge?
|
return @branches = [] unless @project.forge?
|
||||||
|
|
||||||
result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier)
|
# result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier)
|
||||||
@branches = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
result = Gitea::Repository::Branches::ListNameService.call(@owner, @project.identifier)
|
||||||
|
@branches = result.is_a?(Hash) ? (result.key?(:status) ? [] : result["branch_name"]) : result
|
||||||
|
end
|
||||||
|
|
||||||
|
def branches_slice
|
||||||
|
return @branches = [] unless @project.forge?
|
||||||
|
|
||||||
|
slice_result = Gitea::Repository::Branches::ListSliceService.call(@owner, @project.identifier)
|
||||||
|
@branches_slice = slice_result.is_a?(Hash) && slice_result.key?(:status) ? [] : slice_result
|
||||||
end
|
end
|
||||||
|
|
||||||
def group_type_list
|
def group_type_list
|
||||||
|
@ -106,20 +121,37 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
Projects::UpdateForm.new(project_params).validate!
|
# TODO:
|
||||||
private = params[:private] || false
|
# 临时特殊处理修改website、lesson_url操作方法
|
||||||
|
if project_params.has_key?("website")
|
||||||
new_project_params = project_params.except(:private).merge(is_public: !private)
|
@project.update(project_params)
|
||||||
@project.update_attributes!(new_project_params)
|
elsif project_params.has_key?("default_branch")
|
||||||
gitea_params = {
|
@project.update(project_params)
|
||||||
private: private,
|
gitea_params = {
|
||||||
default_branch: @project.default_branch,
|
default_branch: @project.default_branch
|
||||||
website: @project.website
|
}
|
||||||
}
|
|
||||||
if [true, false].include? private
|
|
||||||
Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params)
|
Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params)
|
||||||
@project.repository.update_column(:hidden, private)
|
else
|
||||||
|
validate_params = project_params.slice(:name, :description,
|
||||||
|
:project_category_id, :project_language_id, :private, :identifier)
|
||||||
|
|
||||||
|
Projects::UpdateForm.new(validate_params.merge(user_id: @project.user_id, project_identifier: @project.identifier)).validate!
|
||||||
|
|
||||||
|
private = @project.forked_from_project.present? ? !@project.forked_from_project.is_public : params[:private] || false
|
||||||
|
|
||||||
|
new_project_params = project_params.except(:private).merge(is_public: !private)
|
||||||
|
@project.update_attributes!(new_project_params)
|
||||||
|
@project.forked_projects.update_all(is_public: @project.is_public)
|
||||||
|
gitea_params = {
|
||||||
|
private: private,
|
||||||
|
default_branch: @project.default_branch,
|
||||||
|
website: @project.website,
|
||||||
|
name: @project.identifier
|
||||||
|
}
|
||||||
|
gitea_repo = Gitea::Repository::UpdateService.call(@owner, @project&.repository&.identifier, gitea_params)
|
||||||
|
@project.repository.update_attributes({hidden: gitea_repo["private"], identifier: gitea_repo["name"]})
|
||||||
end
|
end
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, @project.previous_changes.slice(:name, :description, :project_category_id, :project_language_id, :is_public, :identifier)) if Site.has_notice_menu?
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
@ -134,6 +166,7 @@ class ProjectsController < ApplicationController
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
Gitea::Repository::DeleteService.new(@project.owner, @project.identifier).call
|
Gitea::Repository::DeleteService.new(@project.owner, @project.identifier).call
|
||||||
@project.destroy!
|
@project.destroy!
|
||||||
|
@project.forked_projects.update_all(forked_from_project_id: nil)
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -163,11 +196,17 @@ class ProjectsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def simple
|
def simple
|
||||||
|
# 为了缓存活跃项目的基本信息,后续删除
|
||||||
|
Cache::V2::ProjectCommonService.new(@project.id).read
|
||||||
json_response(@project, current_user)
|
json_response(@project, current_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def recommend
|
def recommend
|
||||||
@projects = Project.recommend.includes(:repository, :project_category, :owner).order(id: :desc).limit(5)
|
@projects = Project.recommend.includes(:repository, :project_category, :owner).order(visits: :desc)
|
||||||
|
end
|
||||||
|
|
||||||
|
def banner_recommend
|
||||||
|
@projects = Project.recommend.where.not(recommend_index: 0).includes(:project_category, :owner, :project_language).order(recommend_index: :desc)
|
||||||
end
|
end
|
||||||
|
|
||||||
def about
|
def about
|
||||||
|
@ -201,7 +240,7 @@ class ProjectsController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
def project_params
|
def project_params
|
||||||
params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url,
|
params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url, :default_branch, :identifier,
|
||||||
:project_category_id, :project_language_id, :license_id, :ignore_id, :private,
|
:project_category_id, :project_language_id, :license_id, :ignore_id, :private,
|
||||||
:blockchain, :blockchain_token_all, :blockchain_init_token)
|
:blockchain, :blockchain_token_all, :blockchain_init_token)
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,64 @@
|
||||||
|
class PublicKeysController < ApplicationController
|
||||||
|
before_action :require_login
|
||||||
|
before_action :find_public_key, only: [:destroy]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@public_keys = current_user.public_keys
|
||||||
|
@public_keys = kaminari_paginate(@public_keys)
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
return render_error("参数错误") if public_key_params.blank?
|
||||||
|
return render_ok({status: 10002, message: "请输入密钥"}) if public_key_params[:key].blank?
|
||||||
|
return render_ok({status: 10001, message: "请输入标题"}) if public_key_params[:title].blank?
|
||||||
|
@gitea_response = Gitea::User::Keys::CreateService.call(current_user.gitea_token, public_key_params)
|
||||||
|
if @gitea_response[0] == 201
|
||||||
|
@public_key = @gitea_response[2]
|
||||||
|
else
|
||||||
|
return render_error("创建ssh key失败") if @gitea_response[2].blank?
|
||||||
|
return render_ok({status: 10002, message: "密钥格式不正确"}) if @gitea_response[2]["message"].starts_with?("Invalid key content")
|
||||||
|
exist_public_key = Gitea::PublicKey.find_by(content: public_key_params[:key])
|
||||||
|
return render_ok({status: 10002, message: "密钥已被占用"}) if @gitea_response[2]["message"].starts_with?("Key content has been used as non-deploy key") && exist_public_key.present? && exist_public_key&.owner_id != current_user.gitea_uid
|
||||||
|
return render_ok({status: 10002, message: "密钥已存在,请勿重复添加"}) if @gitea_response[2]["message"].starts_with?("Key content has been used as non-deploy key")
|
||||||
|
@public_key = nil
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
return render_not_found unless @public_key.present?
|
||||||
|
result = Gitea::User::Keys::DeleteService.call(current_user.gitea_token, @public_key.id)
|
||||||
|
if result[0] == 204
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def page
|
||||||
|
params[:page].to_i.zero? ? 1 : params[:page].to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def limit
|
||||||
|
limit = params[:limit] || params[:per_page]
|
||||||
|
limit = (limit.to_i.zero? || limit.to_i > 15) ? 15 : limit.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def public_key_params
|
||||||
|
params.require(:public_key).permit(:key, :title)
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_public_key
|
||||||
|
@public_key = current_user.public_keys.find_by_id(params[:id])
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,22 +1,27 @@
|
||||||
class PullRequestsController < ApplicationController
|
class PullRequestsController < ApplicationController
|
||||||
before_action :require_login, except: [:index, :show, :files, :commits]
|
before_action :require_login, except: [:index, :show, :files, :commits]
|
||||||
|
before_action :require_profile_completed, only: [:create]
|
||||||
before_action :load_repository
|
before_action :load_repository
|
||||||
|
before_action :check_menu_authorize
|
||||||
before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge,:get_branches,:create_merge_infos, :files, :commits]
|
before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge,:get_branches,:create_merge_infos, :files, :commits]
|
||||||
before_action :load_pull_request, only: [:files, :commits]
|
before_action :load_pull_request, only: [:files, :commits]
|
||||||
|
before_action :find_atme_receivers, only: [:create, :update]
|
||||||
include TagChosenHelper
|
include TagChosenHelper
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
return render_not_found unless @project.has_menu_permission("pulls")
|
|
||||||
# @issues = Gitea::PullRequest::ListService.new(@user,@repository.try(:identifier)).call #通过gitea获取
|
# @issues = Gitea::PullRequest::ListService.new(@user,@repository.try(:identifier)).call #通过gitea获取
|
||||||
issues = @project.issues.issue_pull_request.issue_index_includes.includes(pull_request: :user)
|
issues = @project.issues.issue_pull_request.issue_index_includes.includes(pull_request: :user)
|
||||||
issues = issues.where(is_private: false) unless current_user.present? && (current_user.admin? || @project.member?(current_user))
|
issues = issues.where(is_private: false) unless current_user.present? && (current_user.admin? || @project.member?(current_user))
|
||||||
@all_issues_size = issues.size
|
@all_issues = issues.distinct
|
||||||
@open_issues_size = issues.joins(:pull_request).where(pull_requests: {status: 0}).size
|
@filter_issues = @all_issues
|
||||||
@close_issues_size = issues.joins(:pull_request).where(pull_requests: {status: 2}).size
|
@filter_issues = @filter_issues.where("subject LIKE ? OR description LIKE ? ", "%#{params[:search]}%", "%#{params[:search]}%") if params[:search].present?
|
||||||
@merged_issues_size = issues.joins(:pull_request).where(pull_requests: {status: 1}).size
|
@open_issues = @filter_issues.joins(:pull_request).where(pull_requests: {status: PullRequest::OPEN})
|
||||||
|
@close_issues = @filter_issues.joins(:pull_request).where(pull_requests: {status: PullRequest::CLOSED})
|
||||||
|
@merged_issues = @filter_issues.joins(:pull_request).where(pull_requests: {status: PullRequest::MERGED})
|
||||||
@user_admin_or_member = current_user.present? && (current_user.admin || @project.member?(current_user))
|
@user_admin_or_member = current_user.present? && (current_user.admin || @project.member?(current_user))
|
||||||
|
@user_admin_or_developer = current_user.present? && (current_user.admin || @project.all_developers.include?(current_user))
|
||||||
|
|
||||||
scopes = Issues::ListQueryService.call(issues,params.delete_if{|k,v| v.blank?}, "PullRequest")
|
scopes = Issues::ListQueryService.call(issues,params.delete_if{|k,v| v.blank?}, "PullRequest")
|
||||||
@issues_size = scopes.size
|
@issues_size = scopes.size
|
||||||
|
@ -51,10 +56,15 @@ class PullRequestsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
# return normal_status(-1, "您不是目标分支开发者,没有权限,请联系目标分支作者.") unless @project.operator?(current_user)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
@pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params)
|
@pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params)
|
||||||
if @gitea_pull_request[:status] == :success
|
if @gitea_pull_request[:status] == :success
|
||||||
@pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"])
|
@pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"], @gitea_pull_request[:body]["id"])
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id) if Site.has_notice_menu?
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectPullRequest', current_user.id, @pull_request&.id) if Site.has_notice_menu?
|
||||||
|
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||||
|
AtmeService.call(current_user, @atme_receivers, @pull_request) if @atme_receivers.size > 0
|
||||||
|
|
||||||
# author: zxh
|
# author: zxh
|
||||||
# 调用上链API
|
# 调用上链API
|
||||||
|
@ -65,51 +75,70 @@ class PullRequestsController < ApplicationController
|
||||||
else
|
else
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
render_error("create pull request error: #{@gitea_pull_request[:status]}")
|
render_error("create pull request error: #{@gitea_pull_request[:status]}")
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue => e
|
||||||
|
normal_status(-1, e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
@fork_project_user_name = @project&.fork_project&.owner.try(:show_real_name)
|
@fork_project_user_name = @pull_request&.fork_project&.owner.try(:show_real_name)
|
||||||
@fork_project_user = @project&.fork_project&.owner.try(:login)
|
@fork_project_user = @pull_request&.fork_project&.owner.try(:login)
|
||||||
@fork_project_identifier = @project&.fork_project&.repository.try(:identifier)
|
@fork_project_identifier = @pull_request&.fork_project&.repository.try(:identifier)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
return render_forbidden("你没有权限操作.") unless @project.operator?(current_user)
|
||||||
if params[:title].nil?
|
if params[:title].nil?
|
||||||
normal_status(-1, "名称不能为空")
|
normal_status(-1, "名称不能为空")
|
||||||
elsif params[:issue_tag_ids].nil?
|
elsif params[:issue_tag_ids].nil?
|
||||||
normal_status(-1, "标签不能为空")
|
normal_status(-1, "标记不能为空")
|
||||||
else
|
else
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
|
return normal_status(-1, "title不能超过255个字符") if params[:title].length > 255
|
||||||
merge_params
|
merge_params
|
||||||
|
|
||||||
|
@issue&.issue_tags_relates&.destroy_all if params[:issue_tag_ids].blank?
|
||||||
if params[:issue_tag_ids].present? && !@issue&.issue_tags_relates.where(issue_tag_id: params[:issue_tag_ids]).exists?
|
if params[:issue_tag_ids].present? && !@issue&.issue_tags_relates.where(issue_tag_id: params[:issue_tag_ids]).exists?
|
||||||
@issue&.issue_tags_relates&.destroy_all
|
if params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size > 1
|
||||||
params[:issue_tag_ids].each do |tag|
|
return normal_status(-1, "最多只能创建一个标记。")
|
||||||
IssueTagsRelate.create(issue_id: @issue.id, issue_tag_id: tag)
|
elsif params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size == 1
|
||||||
end
|
@issue&.issue_tags_relates&.destroy_all
|
||||||
|
params[:issue_tag_ids].each do |tag|
|
||||||
|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return normal_status(-1, "请输入正确的标记。")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if @issue.update_attributes(@issue_params)
|
if @issue.update_attributes(@issue_params)
|
||||||
if @pull_request.update_attributes(@local_params.compact)
|
if @pull_request.update_attributes(@local_params.compact)
|
||||||
gitea_pull = Gitea::PullRequest::UpdateService.call(@owner.login, @repository.identifier,
|
gitea_pull = Gitea::PullRequest::UpdateService.call(@owner.login, @repository.identifier,
|
||||||
@pull_request.gpid, @requests_params, current_user.gitea_token)
|
@pull_request.gitea_number, @requests_params, current_user.gitea_token)
|
||||||
|
|
||||||
if gitea_pull[:status] === :success
|
if gitea_pull[:status] === :success
|
||||||
if params[:issue_tag_ids].present?
|
if params[:issue_tag_ids].present?
|
||||||
params[:issue_tag_ids].each do |tag|
|
if params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size > 1
|
||||||
IssueTagsRelate.create(issue_id: @issue.id, issue_tag_id: tag)
|
return normal_status(-1, "最多只能创建一个标记。")
|
||||||
end
|
elsif params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size == 1
|
||||||
|
@issue&.issue_tags_relates&.destroy_all
|
||||||
|
params[:issue_tag_ids].each do |tag|
|
||||||
|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return normal_status(-1, "请输入正确的标记。")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if params[:status_id].to_i == 5
|
if params[:status_id].to_i == 5
|
||||||
@issue.issue_times.update_all(end_time: Time.now)
|
@issue.issue_times.update_all(end_time: Time.now)
|
||||||
end
|
end
|
||||||
|
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||||
|
AtmeService.call(current_user, @atme_receivers, @pull_request) if @atme_receivers.size > 0
|
||||||
normal_status(0, "PullRequest更新成功")
|
normal_status(0, "PullRequest更新成功")
|
||||||
else
|
else
|
||||||
normal_status(-1, "PullRequest更新失败")
|
normal_status(-1, "PullRequest更新失败")
|
||||||
|
@ -122,6 +151,8 @@ class PullRequestsController < ApplicationController
|
||||||
normal_status(-1, e.message)
|
normal_status(-1, e.message)
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
end
|
end
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value)) if Site.has_notice_menu?
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id ) if @issue.previous_changes[:assigned_to_id].present? && Site.has_notice_menu?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -131,6 +162,7 @@ class PullRequestsController < ApplicationController
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user)
|
colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user)
|
||||||
|
<<<<<<< HEAD
|
||||||
colsed === true ? normal_status(1, "已拒绝") : normal_status(-1, '合并失败')
|
colsed === true ? normal_status(1, "已拒绝") : normal_status(-1, '合并失败')
|
||||||
# author: zxh
|
# author: zxh
|
||||||
# 调用上链API
|
# 调用上链API
|
||||||
|
@ -139,6 +171,14 @@ class PullRequestsController < ApplicationController
|
||||||
normal_status(-1, "拒绝失败")
|
normal_status(-1, "拒绝失败")
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
else
|
else
|
||||||
|
=======
|
||||||
|
if colsed === true
|
||||||
|
@pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::CLOSE)
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id) if Site.has_notice_menu?
|
||||||
|
normal_status(1, "已拒绝")
|
||||||
|
else
|
||||||
|
normal_status(-1, '合并失败')
|
||||||
|
>>>>>>> upstream/master
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
normal_status(-1, e.message)
|
normal_status(-1, e.message)
|
||||||
|
@ -154,7 +194,8 @@ class PullRequestsController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@issue_user = @issue.user
|
@issue_user = @issue.user
|
||||||
@issue_assign_to = @issue.get_assign_user
|
@issue_assign_to = @issue.get_assign_user
|
||||||
|
@gitea_pull = Gitea::PullRequest::GetService.call(@owner.login,
|
||||||
|
@repository.identifier, @pull_request.gitea_number, current_user&.gitea_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pr_merge
|
def pr_merge
|
||||||
|
@ -165,11 +206,20 @@ class PullRequestsController < ApplicationController
|
||||||
else
|
else
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
result = PullRequests::MergeService.call(@owner, @repository, @pull_request, current_user, params)
|
@gitea_pull = Gitea::PullRequest::GetService.call(@owner.login, @repository.identifier, @pull_request.gitea_number, current_user&.gitea_token)
|
||||||
|
|
||||||
if result.status == 200 && @pull_request.merge!
|
if @gitea_pull["merged_by"].present?
|
||||||
@pull_request.project_trend_status!
|
success_condition = true
|
||||||
|
else
|
||||||
|
result = PullRequests::MergeService.call(@owner, @repository, @pull_request, current_user, params)
|
||||||
|
success_condition = result.status == 200
|
||||||
|
end
|
||||||
|
|
||||||
|
if success_condition && @pull_request.merge!
|
||||||
|
# @pull_request.project_trend_status!
|
||||||
|
@pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::MERGE)
|
||||||
@issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id)
|
@issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id)
|
||||||
|
<<<<<<< HEAD
|
||||||
|
|
||||||
# author: zxh
|
# author: zxh
|
||||||
# 调用上链API
|
# 调用上链API
|
||||||
|
@ -216,6 +266,10 @@ class PullRequestsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
=======
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestMerged', current_user.id, @pull_request.id) if Site.has_notice_menu?
|
||||||
|
normal_status(1, "合并成功")
|
||||||
|
>>>>>>> upstream/master
|
||||||
else
|
else
|
||||||
normal_status(-1, result.message)
|
normal_status(-1, result.message)
|
||||||
end
|
end
|
||||||
|
@ -231,7 +285,7 @@ class PullRequestsController < ApplicationController
|
||||||
def check_can_merge
|
def check_can_merge
|
||||||
target_head = params[:head] #源分支
|
target_head = params[:head] #源分支
|
||||||
target_base = params[:base] #目标分支
|
target_base = params[:base] #目标分支
|
||||||
is_original = params[:is_original]
|
is_original = params[:is_original] || false
|
||||||
if target_head.blank? || target_base.blank?
|
if target_head.blank? || target_base.blank?
|
||||||
normal_status(-2, "请选择分支")
|
normal_status(-2, "请选择分支")
|
||||||
elsif target_head === target_base && !is_original
|
elsif target_head === target_base && !is_original
|
||||||
|
@ -241,7 +295,7 @@ class PullRequestsController < ApplicationController
|
||||||
if can_merge.present?
|
if can_merge.present?
|
||||||
render json: {
|
render json: {
|
||||||
status: -2,
|
status: -2,
|
||||||
message: "在这些分支之间的合并请求已存在:<a href='/projects/#{@owner.login}/#{@project.identifier}/pulls/#{can_merge.first.id}/Messagecount''>#{can_merge.first.try(:title)}</a>",
|
message: "在这些分支之间的合并请求已存在:<a href='/#{@owner.login}/#{@project.identifier}/pulls/#{can_merge.first.id}''>#{can_merge.first.try(:title)}</a>",
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
normal_status(0, "可以合并")
|
normal_status(0, "可以合并")
|
||||||
|
@ -251,22 +305,22 @@ class PullRequestsController < ApplicationController
|
||||||
|
|
||||||
|
|
||||||
def files
|
def files
|
||||||
@files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gpid, current_user&.gitea_token)
|
@files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token)
|
||||||
# render json: @files_result
|
# render json: @files_result
|
||||||
end
|
end
|
||||||
|
|
||||||
def commits
|
def commits
|
||||||
@commits_result = Gitea::PullRequest::CommitsService.call(@owner.login, @project.identifier, @pull_request.gpid, current_user&.gitea_token)
|
@commits_result = Gitea::PullRequest::CommitsService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token)
|
||||||
# render json: @commits_result
|
# render json: @commits_result
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def load_pull_request
|
def load_pull_request
|
||||||
@pull_request = PullRequest.find params[:id]
|
@pull_request = @project.pull_requests.where(gitea_number: params[:id]).where.not(id: params[:id]).take || PullRequest.find_by_id(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_pull_request
|
def find_pull_request
|
||||||
@pull_request = PullRequest.find_by_id(params[:id])
|
@pull_request = @project.pull_requests.where(gitea_number: params[:id]).where.not(id: params[:id]).take || PullRequest.find_by_id(params[:id])
|
||||||
@issue = @pull_request&.issue
|
@issue = @pull_request&.issue
|
||||||
if @pull_request.blank?
|
if @pull_request.blank?
|
||||||
normal_status(-1, "合并请求不存在")
|
normal_status(-1, "合并请求不存在")
|
||||||
|
@ -290,12 +344,12 @@ class PullRequestsController < ApplicationController
|
||||||
base: params[:base], #目标分支
|
base: params[:base], #目标分支
|
||||||
milestone: 0, #里程碑,未与本地的里程碑关联
|
milestone: 0, #里程碑,未与本地的里程碑关联
|
||||||
}
|
}
|
||||||
|
assignee_login = User.find_by_id(params[:assigned_to_id])&.login
|
||||||
@requests_params = @local_params.merge({
|
@requests_params = @local_params.merge({
|
||||||
assignee: current_user.try(:login),
|
|
||||||
# assignees: ["#{params[:assigned_login].to_s}"],
|
# assignees: ["#{params[:assigned_login].to_s}"],
|
||||||
assignees: ["#{current_user.try(:login).to_s}"],
|
assignees: ["#{assignee_login.to_s}"],
|
||||||
labels: params[:issue_tag_ids],
|
labels: params[:issue_tag_ids]
|
||||||
due_date: Time.now
|
# due_date: Time.now
|
||||||
})
|
})
|
||||||
@issue_params = {
|
@issue_params = {
|
||||||
author_id: current_user.id,
|
author_id: current_user.id,
|
||||||
|
@ -305,11 +359,15 @@ class PullRequestsController < ApplicationController
|
||||||
assigned_to_id: params[:assigned_to_id],
|
assigned_to_id: params[:assigned_to_id],
|
||||||
fixed_version_id: params[:fixed_version_id],
|
fixed_version_id: params[:fixed_version_id],
|
||||||
issue_tags_value: params[:issue_tag_ids].present? ? params[:issue_tag_ids].join(",") : "",
|
issue_tags_value: params[:issue_tag_ids].present? ? params[:issue_tag_ids].join(",") : "",
|
||||||
priority_id: params[:priority_id] || "2",
|
priority_id: params[:priority_id],
|
||||||
issue_classify: "pull_request",
|
issue_classify: "pull_request",
|
||||||
issue_type: params[:issue_type] || "1",
|
issue_type: params[:issue_type] || "1",
|
||||||
tracker_id: 2,
|
tracker_id: 2,
|
||||||
status_id: 1,
|
status_id: 1,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_menu_authorize
|
||||||
|
return render_not_found unless @project.has_menu_permission("pulls")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
class RepositoriesController < ApplicationController
|
class RepositoriesController < ApplicationController
|
||||||
|
include RepositoriesHelper
|
||||||
include ApplicationHelper
|
include ApplicationHelper
|
||||||
include OperateProjectAbilityAble
|
include OperateProjectAbilityAble
|
||||||
include Repository::LanguagesPercentagable
|
include Repository::LanguagesPercentagable
|
||||||
|
|
||||||
before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror]
|
before_action :require_login, only: %i[edit update create_file update_file delete_file sync_mirror]
|
||||||
|
before_action :require_profile_completed, only: [:create_file]
|
||||||
before_action :load_repository
|
before_action :load_repository
|
||||||
before_action :authorizate!, except: [:sync_mirror, :tags, :commit]
|
before_action :authorizate!, except: [:sync_mirror, :tags, :commit, :archive]
|
||||||
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
|
before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror]
|
||||||
before_action :get_ref, only: %i[entries sub_entries top_counts file]
|
before_action :get_ref, only: %i[entries sub_entries top_counts file archive]
|
||||||
before_action :get_latest_commit, only: %i[entries sub_entries top_counts]
|
before_action :get_latest_commit, only: %i[entries sub_entries top_counts]
|
||||||
before_action :get_statistics, only: %i[top_counts]
|
before_action :get_statistics, only: %i[top_counts]
|
||||||
|
|
||||||
|
@ -46,7 +48,7 @@ class RepositoriesController < ApplicationController
|
||||||
|
|
||||||
def entries
|
def entries
|
||||||
@project.increment!(:visits)
|
@project.increment!(:visits)
|
||||||
|
CacheAsyncSetJob.perform_later("project_common_service", {visits: 1}, @project.id)
|
||||||
if @project.educoder?
|
if @project.educoder?
|
||||||
@entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder.repo_name)
|
@entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder.repo_name)
|
||||||
else
|
else
|
||||||
|
@ -69,18 +71,35 @@ class RepositoriesController < ApplicationController
|
||||||
logger.info "######### sub_entries: #{@sub_entries}"
|
logger.info "######### sub_entries: #{@sub_entries}"
|
||||||
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
|
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
|
||||||
|
|
||||||
tmp_entries = [{
|
tmp_entries = {
|
||||||
"content" => @sub_entries['data']['content'],
|
"content" => @sub_entries['data']['content'],
|
||||||
"type" => "blob"
|
"type" => "blob"
|
||||||
}]
|
}
|
||||||
@sub_entries = {
|
@sub_entries = {
|
||||||
"trees"=>tmp_entries,
|
"trees"=>tmp_entries,
|
||||||
"commits" => [{}]
|
"commits" => [{}]
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri})
|
begin
|
||||||
|
@sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri})
|
||||||
|
if @sub_entries.blank? || @sub_entries['status'].to_i === -1
|
||||||
|
@sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri)
|
||||||
|
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
|
||||||
|
tmp_entries = {
|
||||||
|
"content" => @sub_entries['data']['content'],
|
||||||
|
"type" => "blob"
|
||||||
|
}
|
||||||
|
@sub_entries = {
|
||||||
|
"trees"=>tmp_entries,
|
||||||
|
"commits" => [{}]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
return render_error('该文件暂未开放,敬请期待.')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
|
||||||
interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, file_path_uri, ref: @ref)
|
interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, file_path_uri, ref: @ref)
|
||||||
if interactor.success?
|
if interactor.success?
|
||||||
result = interactor.result
|
result = interactor.result
|
||||||
|
@ -92,14 +111,33 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def commits
|
def commits
|
||||||
@hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier,
|
if @project.educoder?
|
||||||
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
@commits = Educoder::Repository::Commits::ListService.call(@project&.project_educoder&.repo_name)
|
||||||
|
else
|
||||||
|
if params[:filepath].present?
|
||||||
|
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
||||||
|
@hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri,
|
||||||
|
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
||||||
|
else
|
||||||
|
@hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier,
|
||||||
|
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def commits_slice
|
||||||
|
@hash_commit = Gitea::Repository::Commits::ListSliceService.call(@owner.login, @project.identifier,
|
||||||
|
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token)
|
||||||
|
end
|
||||||
|
|
||||||
def commit
|
def commit
|
||||||
@sha = params[:sha]
|
@sha = params[:sha]
|
||||||
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token)
|
if @project.educoder?
|
||||||
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true})
|
return render_error('暂未开放,敬请期待.')
|
||||||
|
else
|
||||||
|
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token)
|
||||||
|
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags
|
def tags
|
||||||
|
@ -109,7 +147,14 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def contributors
|
def contributors
|
||||||
@contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier)
|
if params[:filepath].present? || @project.educoder?
|
||||||
|
@contributors = []
|
||||||
|
else
|
||||||
|
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier)
|
||||||
|
@contributors = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
@contributors = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
@ -172,14 +217,49 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def readme
|
def readme
|
||||||
result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token)
|
if params[:filepath].present?
|
||||||
|
result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], current_user&.gitea_token)
|
||||||
|
else
|
||||||
|
result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token)
|
||||||
|
end
|
||||||
|
@path = Gitea.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/"
|
||||||
@readme = result[:status] === :success ? result[:body] : nil
|
@readme = result[:status] === :success ? result[:body] : nil
|
||||||
render json: @readme
|
@readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
||||||
|
render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha")
|
||||||
|
rescue
|
||||||
|
render json: nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def languages
|
def languages
|
||||||
render json: languages_precentagable
|
if @project.educoder?
|
||||||
|
render json: {}
|
||||||
|
else
|
||||||
|
render json: languages_precentagable
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def archive
|
||||||
|
domain = Gitea.gitea_config[:domain]
|
||||||
|
api_url = Gitea.gitea_config[:base_url]
|
||||||
|
archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{CGI.escape(params[:archive])}"
|
||||||
|
|
||||||
|
file_path = [domain, api_url, archive_url].join
|
||||||
|
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") if @repository.hidden?
|
||||||
|
|
||||||
|
return render_not_found if !request.format.zip? && !request.format.gzip?
|
||||||
|
|
||||||
|
redirect_to file_path
|
||||||
|
end
|
||||||
|
|
||||||
|
def raw
|
||||||
|
domain = Gitea.gitea_config[:domain]
|
||||||
|
api_url = Gitea.gitea_config[:base_url]
|
||||||
|
|
||||||
|
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{CGI.escape(params[:filepath])}?ref=#{CGI.escape(params[:ref])}"
|
||||||
|
file_path = [domain, api_url, url].join
|
||||||
|
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&")
|
||||||
|
|
||||||
|
redirect_to file_path
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -202,8 +282,14 @@ class RepositoriesController < ApplicationController
|
||||||
|
|
||||||
# TODO 获取最新commit信息
|
# TODO 获取最新commit信息
|
||||||
def project_commits
|
def project_commits
|
||||||
Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
|
if params[:filepath].present?
|
||||||
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
||||||
|
Gitea::Repository::Commits::FileListService.new(@project.owner.login, @project.identifier, file_path_uri,
|
||||||
|
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
||||||
|
else
|
||||||
|
Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier,
|
||||||
|
sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_statistics
|
def get_statistics
|
||||||
|
@ -256,7 +342,7 @@ class RepositoriesController < ApplicationController
|
||||||
|
|
||||||
# uploadPushInfo
|
# uploadPushInfo
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_new_pr(params)
|
def create_new_pr(params)
|
||||||
if params[:new_branch].present? && params[:new_branch] != params[:branch]
|
if params[:new_branch].present? && params[:new_branch] != params[:branch]
|
||||||
local_params = {
|
local_params = {
|
||||||
|
|
|
@ -5,6 +5,7 @@ class SettingsController < ApplicationController
|
||||||
get_common_menu
|
get_common_menu
|
||||||
get_personal_menu
|
get_personal_menu
|
||||||
get_third_party
|
get_third_party
|
||||||
|
get_top_system_notification
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -47,6 +48,10 @@ class SettingsController < ApplicationController
|
||||||
url: EducoderOauth.oauth_url
|
url: EducoderOauth.oauth_url
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_top_system_notification
|
||||||
|
@top_system_notification = SystemNotification.is_top.first
|
||||||
|
end
|
||||||
|
|
||||||
def get_site_url(key, value)
|
def get_site_url(key, value)
|
||||||
key.to_s === "url" ? append_http(reset_site_url(value)) : reset_site_url(value)
|
key.to_s === "url" ? append_http(reset_site_url(value)) : reset_site_url(value)
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
class TemplateMessageSettingsController < ApplicationController
|
||||||
|
before_action :require_login
|
||||||
|
|
||||||
|
def index
|
||||||
|
@group_settings = TemplateMessageSetting.group(:type).count
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,9 @@
|
||||||
|
class TopicsController < ApplicationController
|
||||||
|
|
||||||
|
def index
|
||||||
|
return render_not_found("请输入正确的数据类型") unless params[:topic_type].present?
|
||||||
|
scope = Topic.with_single_type(params[:topic_type])
|
||||||
|
@topics = kaminari_paginate(scope)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -0,0 +1,24 @@
|
||||||
|
class UserRankController < ApplicationController
|
||||||
|
# 根据时间获取热门开发者
|
||||||
|
def index
|
||||||
|
$redis_cache.zunionstore("recent-days-user-rank", get_timeable_key_names)
|
||||||
|
@user_rank = $redis_cache.zrevrange("recent-days-user-rank", 0, 3, withscores: true)
|
||||||
|
rescue Exception => e
|
||||||
|
@user_rank = []
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
# 默认显示7天的
|
||||||
|
def time
|
||||||
|
params.fetch(:time, 7).to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_timeable_key_names
|
||||||
|
names_array = []
|
||||||
|
(0...time).to_a.each do |i|
|
||||||
|
date_time_string = (Date.today - i.days).to_s
|
||||||
|
names_array << "v2-user-rank-#{date_time_string}"
|
||||||
|
end
|
||||||
|
names_array
|
||||||
|
end
|
||||||
|
end
|
|
@ -9,7 +9,7 @@ class Users::AppliedMessagesController < Users::BaseController
|
||||||
|
|
||||||
private
|
private
|
||||||
def check_auth
|
def check_auth
|
||||||
return render_forbidden unless observed_logged_user?
|
return render_forbidden unless current_user.admin? || observed_logged_user?
|
||||||
end
|
end
|
||||||
|
|
||||||
def view_messages
|
def view_messages
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
class Users::AppliedProjectsController < Users::BaseController
|
||||||
|
before_action :check_auth
|
||||||
|
before_action :find_applied_project, except: [:index]
|
||||||
|
before_action :find_project, except: [:index]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@applied_projects = AppliedProject.where(project_id: observed_user.full_admin_projects)
|
||||||
|
@applied_projects = paginate @applied_projects.order("created_at desc")
|
||||||
|
end
|
||||||
|
|
||||||
|
# 接受申请
|
||||||
|
def accept
|
||||||
|
@applied_project = Projects::AcceptJoinService.call(current_user, @applied_project)
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
# 拒绝申请
|
||||||
|
def refuse
|
||||||
|
@applied_project = Projects::RefuseJoinService.call(current_user, @applied_project)
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def check_auth
|
||||||
|
return render_forbidden unless current_user.admin? || observed_logged_user?
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_applied_project
|
||||||
|
@applied_project = AppliedProject.find_by_id params[:id]
|
||||||
|
end
|
||||||
|
|
||||||
|
def find_project
|
||||||
|
@project = @applied_project.project
|
||||||
|
end
|
||||||
|
end
|
|
@ -28,7 +28,7 @@ class Users::AppliedTransferProjectsController < Users::BaseController
|
||||||
|
|
||||||
private
|
private
|
||||||
def check_auth
|
def check_auth
|
||||||
return render_forbidden unless observed_logged_user?
|
return render_forbidden unless current_user.admin? || observed_logged_user?
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_applied_transfer_project
|
def find_applied_transfer_project
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
class Users::BanksController < Users::BaseController
|
class Users::BanksController < Users::BaseController
|
||||||
before_action :params_filter
|
before_action :params_filter
|
||||||
def index
|
def index
|
||||||
order = params[:order] || "updated_at"
|
order = CourseList.column_names.include?(params[:order]) ? params[:order] : "updated_at"
|
||||||
sort = params[:sort] || "desc"
|
sort = %w(desc asc).includes?(params[:sort]) ? params[:sort] : "desc"
|
||||||
@banks = @object_type.classify.constantize.where(@object_filter)
|
@banks = @object_type.classify.constantize.where(@object_filter)
|
||||||
@course_lists = CourseList.where(id: @banks.pluck(:course_list_id))
|
@course_lists = CourseList.where(id: @banks.pluck(:course_list_id))
|
||||||
@banks = @banks.where(course_list_id: params[:tag_id]) unless params[:tag_id].blank?
|
@banks = @banks.where(course_list_id: params[:tag_id]) unless params[:tag_id].blank?
|
||||||
|
|
|
@ -5,7 +5,7 @@ class Users::BaseController < ApplicationController
|
||||||
helper_method :observed_logged_user?, :observed_user
|
helper_method :observed_logged_user?, :observed_user
|
||||||
|
|
||||||
def observed_user
|
def observed_user
|
||||||
@_observed_user ||= (User.find_by_id(params[:user_id]) || User.find_by_login(params[:user_id]))
|
@_observed_user ||= (User.find_by_login(params[:user_id]) || User.find_by_id(params[:user_id]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def observed_logged_user?
|
def observed_logged_user?
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
class Users::HeadmapsController < Users::BaseController
|
||||||
|
def index
|
||||||
|
result = Gitea::User::HeadmapService.call(observed_user.login, start_stamp, end_stamp)
|
||||||
|
@headmaps = result[2].blank? ? [] : result[2]
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def start_stamp
|
||||||
|
if params[:year].present?
|
||||||
|
Date.new(params[:year], 1).to_time.to_i
|
||||||
|
else
|
||||||
|
Date.today.to_time.to_i - 365*24*60*60
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def end_stamp
|
||||||
|
if params[:year].present?
|
||||||
|
Date.new(params[:year], 1).to_time.to_i + 365*24*60*60
|
||||||
|
else
|
||||||
|
Date.today.to_time.to_i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,45 @@
|
||||||
|
class Users::IsPinnedProjectsController < Users::BaseController
|
||||||
|
before_action :private_user_resources!, only: [:pin]
|
||||||
|
def index
|
||||||
|
@is_pinned_projects = observed_user.pinned_projects.order(position: :desc, created_at: :asc).includes(project: [:project_category, :project_language, :repository]).order(position: :desc)
|
||||||
|
@is_pinned_projects = kaminari_paginate(@is_pinned_projects)
|
||||||
|
end
|
||||||
|
|
||||||
|
def pin
|
||||||
|
observed_user.is_pinned_project_ids = is_pinned_project_ids
|
||||||
|
render_ok
|
||||||
|
rescue ActiveRecord::RecordNotFound => e
|
||||||
|
render_not_found
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
@pinned_project = PinnedProject.find_by_id(params[:id])
|
||||||
|
@pinned_project.attributes = pinned_project_params
|
||||||
|
if @pinned_project.save
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def is_pinned_project_ids
|
||||||
|
if params[:is_pinned_project_ids].present?
|
||||||
|
return params[:is_pinned_project_ids].select{|id| observed_user.full_member_projects.visible.pluck(:id).include?(id.to_i) }
|
||||||
|
end
|
||||||
|
if params[:is_pinned_project_id].present?
|
||||||
|
return observed_user.is_pinned_project_ids unless observed_user.full_member_projects.visible.pluck(:id).include?(params[:is_pinned_project_id].to_i)
|
||||||
|
return observed_user.is_pinned_project_ids.include?(params[:is_pinned_project_id].to_i) ? observed_user.is_pinned_project_ids : observed_user.is_pinned_project_ids.push(params[:is_pinned_project_id].to_i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def pinned_project_params
|
||||||
|
params.require(:pinned_project).permit(:position)
|
||||||
|
end
|
||||||
|
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue