forked from Gitlink/forgeplus
Compare commits
67 Commits
master
...
dev_hh_ver
Author | SHA1 | Date |
---|---|---|
|
36bae71947 | |
|
c283c7ed58 | |
|
4cf8588343 | |
|
e75fad98f8 | |
|
bc37c59f00 | |
|
a6a745da93 | |
|
5bef80ee58 | |
|
f9bcc7e02b | |
|
d35faf3935 | |
|
8d7dc9cb60 | |
|
248d78d8c1 | |
|
f632424f13 | |
|
95ede63220 | |
|
8fac294d04 | |
|
d67c12beba | |
|
a7e4b85352 | |
![]() |
2ac2920399 | |
![]() |
230b934de4 | |
|
e0bedf175f | |
|
c9a263e03c | |
![]() |
2bd15d9746 | |
|
fc9588fb63 | |
|
e611b519ab | |
|
3dd3944ebd | |
|
f417bf3308 | |
|
9c7c914d12 | |
|
b088befae7 | |
|
d3636e686b | |
|
88d98f0ac4 | |
|
db6aa954b1 | |
|
04a611a4aa | |
|
9ecea83506 | |
|
82a9907fdc | |
|
c56c98fd6e | |
|
2948ad2033 | |
|
fc611140cf | |
|
fcb5f58b69 | |
|
0f38a130f3 | |
|
fc54632a08 | |
|
5963af5c7b | |
|
c1f2f7f6e2 | |
|
271699daf1 | |
|
98da7ea34d | |
|
645e4a3586 | |
|
7beca24a05 | |
|
d1368c7612 | |
|
28e762810e | |
|
0f60d0adc9 | |
|
e634317675 | |
|
6b1a0a96c6 | |
|
298859bd10 | |
|
d4d412ab40 | |
|
57d1a1474e | |
|
055b7dbac5 | |
|
30aad87e5a | |
|
aecd68fe9a | |
|
998a6828d9 | |
|
12c04d02e5 | |
|
d6ef3d8aa3 | |
|
c7a89d1660 | |
|
1939c0d33f | |
![]() |
561b9efd92 | |
![]() |
6c0b87fdd1 | |
![]() |
5d309d1dc4 | |
![]() |
89c230c362 | |
![]() |
d4156a5582 | |
![]() |
ee8cbb8553 |
|
@ -36,12 +36,12 @@ public/react/yarn.lock
|
|||
/.idea/*
|
||||
|
||||
# Ignore react node_modules
|
||||
public/system/*
|
||||
/public/react/.cache
|
||||
/public/react/node_modules/
|
||||
/public/react/config/stats.json
|
||||
/public/react/stats.json
|
||||
/public/react/.idea/*
|
||||
/public/react/build/*
|
||||
/public/h5build
|
||||
/public/npm-debug.log
|
||||
|
||||
|
@ -72,8 +72,7 @@ vendor/bundle/
|
|||
/log
|
||||
/public/admin
|
||||
/mysql_data
|
||||
/public/repo/
|
||||
/coverage
|
||||
|
||||
|
||||
.generators
|
||||
.rakeTasks
|
||||
|
@ -81,7 +80,5 @@ db/bak/
|
|||
docker/
|
||||
educoder.sql
|
||||
redis_data/
|
||||
dump.rdb
|
||||
.tags*
|
||||
ceshi_user.xlsx
|
||||
public/trace_task_results
|
||||
Dockerfile
|
||||
dump.rdb
|
|
@ -0,0 +1,529 @@
|
|||
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);
|
|
@ -1,22 +0,0 @@
|
|||
kind: pipeline
|
||||
name: default
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: arm64
|
||||
|
||||
steps:
|
||||
- name: install
|
||||
image: ruby:2.4.5
|
||||
commands:
|
||||
- gem install bundler
|
||||
- bundle -v
|
||||
- bundle install --jobs=1 --retry=1
|
||||
|
||||
- name: test
|
||||
image: ruby:2.4.5
|
||||
volumes:
|
||||
- name: bundle
|
||||
path: /usr/local/bundle
|
||||
commands:
|
||||
- rake
|
129
CHANGELOG.md
129
CHANGELOG.md
|
@ -1,129 +0,0 @@
|
|||
# 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
|
||||
|
||||
* BUGFIXES
|
||||
* Fix 解决疑修标题过长导致的排版问题(45469)
|
||||
* Fix 解决合并请求详情页面排版错误的问题(45457)
|
||||
* FIX 解决转移仓库界面专有名词描述错误的问题(45455)
|
||||
* Fix 解决markdown格式文件自动生成数字排序的问题(45454)
|
||||
* Fix 解决镜像项目源地址不显示的问题(45403)
|
||||
* Fix 解决镜像项目导航显示错误问题(45398)
|
||||
* Fix 解决其他相关bug
|
||||
|
||||
* ENHANCEMENTS
|
||||
* UPDATE 用户注册时,账号和密码正则匹配调整(45336) (45318) (45290)
|
||||
* ADD 创建组织各属性添加规则匹配功能(45313) (45289)
|
||||
* ADD 创建团建各属性添加规则匹配功能(45334) (45325) (45287)
|
||||
* ADD 仓库转移功能(45017) (45015)
|
||||
|
||||
## [v3.0.2](https://forgeplus.trustie.net/projects/jasder/forgeplus/releases) - 2021-04-23
|
||||
|
||||
* BUGFIXES
|
||||
* Fix 解决部分用户头像不显示问题
|
||||
* Fix 解决代码库模块中最左侧目录中的文件定位加载不准确的问题
|
||||
* FIX 解决团队管理页面中项目链接错误问题
|
||||
* Fix 解决markdown格式文件显示问题
|
||||
* Fix 解决组织名下创建项目报错的问题
|
||||
* Fix 解决组织名下的项目,创建issue报错的问题
|
||||
* Fix 解决组织名下创建团队提示信息信息显示错误问题
|
||||
* Fix 解决点击组织图片时,链接加载错误问题
|
||||
* Fix 修复查询版本库信息安全漏洞
|
||||
* Fix 解决修复团队成员操作访问组织仓库报403错误的问题
|
||||
* Fix 解决owners团队成员对仓库添加成功失败的问题
|
||||
|
||||
* ENHANCEMENTS
|
||||
* ADD 自动生产用户头像功能
|
||||
* ADD 创建组织支持中文名称
|
||||
* ADD 创建团建支持中文名称
|
||||
* ADD 组织名称统一显示中文名
|
||||
* ADD 团队名称统一显示中文名
|
||||
* ADD 用户头像悬浮时展示相关信息
|
||||
* ADD 项目详情页添加实践课程链接入口
|
||||
* ADD README文件页面添加添加目录导航功能
|
||||
* UPDATE 升级改版底部footer信息
|
||||
* UPDATE 升级用户操作版本库权限
|
||||
|
||||
## [v3.0.1](https://forgeplus.trustie.net/projects/jasder/forgeplus/releases) - 2021-03-19
|
||||
|
||||
* BUGFIXES
|
||||
* Fix pull reqeust模块中用户头像显示问题
|
||||
* Fix 解决issue模块中,指派用户的问题
|
||||
* Fix 解决合并请求失败的后显示message信息不正确
|
||||
* Fix 代码目录页面,readme文件提供单独的api
|
||||
|
||||
* ENHANCEMENTS
|
||||
* 重构项目详情页面
|
||||
|
||||
## [v3.0.0](https://forgeplus.trustie.net/projects/jasder/forgeplus/releases) - 2020-12-29
|
||||
|
||||
* BUGFIXES
|
||||
* Fix pull reqeust的访问权限问题 (#14156) (#14171)
|
||||
* Fix 部分页面访问403的问题
|
||||
* Fix 合并请求失败的问题
|
||||
* Fix 代码目录页面,文件夹和文件图片不显示的问题
|
||||
* Fix Issue列表中按‘负责人’过滤筛选时,部分项目成员不在搜索范围没的问题
|
||||
* Fix 项目更新时间不同步的问题, 添加了定时任务
|
||||
* ENHANCEMENTS
|
||||
* 提升获取版本库目录代码查询速度 (#43296)
|
||||
* tag 列表慢查询速度问题 (#43332)
|
||||
* API builder 模版中 render partial builder的性能问题
|
33
Dockerfile
33
Dockerfile
|
@ -1,33 +0,0 @@
|
|||
FROM ubuntu:18.04
|
||||
|
||||
RUN apt update
|
||||
|
||||
RUN apt install -y openssl libssl-dev imagemagick git ruby-dev nodejs libmariadb-dev libmysqlclient-dev shared-mime-info libpq-dev libxml2-dev libxslt-dev
|
||||
RUN DEBIAN_FRONTEND="noninteractive" apt -y install tzdata
|
||||
RUN ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
|
||||
|
||||
WORKDIR /home/app/gitlink
|
||||
|
||||
ADD ./ /home/app/gitlink
|
||||
|
||||
RUN gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
|
||||
|
||||
RUN gem update --system
|
||||
|
||||
RUN gem install bundler
|
||||
RUN gem install rake
|
||||
|
||||
RUN rm -rf Gemfile.lock
|
||||
|
||||
#RUN cp config/configuration.yml.example config/configuration.yml
|
||||
#RUN cp config/database.yml.example config/database.yml
|
||||
#RUN touch config/redis.yml
|
||||
#RUN touch config/elasticsearch.yml
|
||||
|
||||
RUN bundle install
|
||||
|
||||
EXPOSE 4000
|
||||
RUN rails s -p 4000 -b '0.0.0.0'
|
||||
|
||||
|
||||
|
280
Gemfile
280
Gemfile
|
@ -1,150 +1,130 @@
|
|||
# source 'https://gems.ruby-china.com'
|
||||
source 'https://mirrors.cloud.tencent.com/rubygems/'
|
||||
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
||||
|
||||
gem 'rails', '~> 5.2.0'
|
||||
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
|
||||
gem 'puma', '~> 3.11'
|
||||
gem 'sass-rails', '~> 5.0'
|
||||
gem 'uglifier', '>= 1.3.0'
|
||||
|
||||
# gem 'coffee-rails', '~> 4.2'
|
||||
gem 'turbolinks', '~> 5'
|
||||
gem 'jbuilder', '~> 2.5'
|
||||
gem 'groupdate', '~> 4.1.0'
|
||||
gem 'chartkick'
|
||||
gem 'grape-entity', '~> 0.7.1'
|
||||
gem 'kaminari', '~> 1.1', '>= 1.1.1'
|
||||
|
||||
gem 'bootsnap', '>= 1.1.0', require: false
|
||||
|
||||
gem 'chinese_pinyin'
|
||||
|
||||
gem 'rack-cors'
|
||||
gem 'redis-rails'
|
||||
gem 'roo-xls'
|
||||
gem 'simple_xlsx_reader'
|
||||
|
||||
gem 'rubyzip'
|
||||
|
||||
gem 'spreadsheet'
|
||||
gem 'ruby-ole'
|
||||
# 导出为xlsx
|
||||
gem 'axlsx', '~> 3.0.0.pre'
|
||||
gem 'axlsx_rails', '~> 0.5.2'
|
||||
|
||||
gem 'oauth2'
|
||||
#导出为pdf
|
||||
gem 'pdfkit'
|
||||
gem 'wkhtmltopdf-binary'
|
||||
# gem 'request_store'
|
||||
#gem 'iconv'
|
||||
# markdown 转html
|
||||
gem 'redcarpet', '~> 3.4'
|
||||
|
||||
gem 'rqrcode', '~> 0.10.1'
|
||||
gem 'rqrcode_png'
|
||||
|
||||
gem 'acts-as-taggable-on', '~> 6.0'
|
||||
|
||||
# a tree structure
|
||||
gem 'ancestry'
|
||||
gem 'acts_as_list'
|
||||
gem 'omniauth-cas'
|
||||
|
||||
# profiler Middleware
|
||||
gem 'rack-mini-profiler'
|
||||
|
||||
# object-based searching
|
||||
gem 'ransack'
|
||||
|
||||
group :development, :test do
|
||||
gem 'rspec-rails', '~> 3.8'
|
||||
gem 'rails-controller-testing'
|
||||
end
|
||||
|
||||
group :development do
|
||||
gem 'prettier'
|
||||
gem 'rubocop', '~> 0.52.0'
|
||||
gem 'solargraph', '~> 0.38.0'
|
||||
gem 'awesome_print'
|
||||
gem 'web-console', '>= 3.3.0'
|
||||
gem 'listen', '>= 3.0.5', '< 3.2'
|
||||
gem 'spring'
|
||||
gem 'spring-watcher-listen', '~> 2.0.0'
|
||||
gem "annotate", "~> 2.6.0"
|
||||
end
|
||||
|
||||
group :test do
|
||||
gem 'capybara', '>= 2.15', '< 4.0'
|
||||
gem 'selenium-webdriver'
|
||||
gem 'chromedriver-helper'
|
||||
gem 'simplecov', '~>0.12.0', require: false
|
||||
end
|
||||
|
||||
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
||||
|
||||
#编码检测
|
||||
gem 'rchardet', '~> 1.8'
|
||||
|
||||
# http client
|
||||
gem 'faraday', '~> 0.15.4'
|
||||
|
||||
# view
|
||||
gem 'active_decorator'
|
||||
gem 'bootstrap', '~> 4.3.1'
|
||||
gem 'jquery-rails'
|
||||
gem 'simple_form'
|
||||
gem 'font-awesome-sass', '4.7.0'
|
||||
|
||||
# i18n
|
||||
gem 'rails-i18n', '~> 5.1'
|
||||
|
||||
# job
|
||||
gem 'sidekiq',"5.2.8"
|
||||
gem 'sinatra'
|
||||
gem "sidekiq-cron", "1.2.0"
|
||||
gem 'whenever'
|
||||
gem 'sidekiq_schedulable'
|
||||
|
||||
# batch insert
|
||||
gem 'bulk_insert'
|
||||
|
||||
# elasticsearch
|
||||
gem 'searchkick'
|
||||
|
||||
gem 'aasm'
|
||||
gem 'enumerize'
|
||||
|
||||
gem 'diffy'
|
||||
|
||||
gem 'deep_cloneable', '~> 3.0.0'
|
||||
|
||||
# oauth2
|
||||
gem 'omniauth', '~> 1.9.0'
|
||||
gem 'omniauth-oauth2', '~> 1.6.0'
|
||||
gem "omniauth-github"
|
||||
gem "omniauth-rails_csrf_protection"
|
||||
gem 'omniauth-gitee', '~> 1.0.0'
|
||||
gem "omniauth-wechat-oauth2"
|
||||
|
||||
# global var
|
||||
gem 'request_store'
|
||||
|
||||
# 敏感词汇
|
||||
gem 'harmonious_dictionary', '~> 0.0.1'
|
||||
|
||||
gem 'parallel', '~> 1.19', '>= 1.19.1'
|
||||
|
||||
# log
|
||||
gem 'multi_logger'
|
||||
|
||||
gem 'letter_avatar'
|
||||
|
||||
gem 'jwt'
|
||||
|
||||
gem 'doorkeeper'
|
||||
|
||||
gem 'doorkeeper-jwt'
|
||||
|
||||
gem 'gitea-client', '~> 0.11.1'
|
||||
source 'https://gems.ruby-china.com'
|
||||
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
||||
|
||||
ruby '2.3.7'
|
||||
|
||||
gem 'rails', '~> 5.2.0'
|
||||
gem 'mysql2', '>= 0.4.4', '< 0.6.0'
|
||||
gem 'puma', '~> 3.11'
|
||||
gem 'sass-rails', '~> 5.0'
|
||||
gem 'uglifier', '>= 1.3.0'
|
||||
|
||||
# gem 'coffee-rails', '~> 4.2'
|
||||
gem 'turbolinks', '~> 5'
|
||||
gem 'jbuilder', '~> 2.5'
|
||||
gem 'groupdate', '~> 4.1.0'
|
||||
gem 'chartkick'
|
||||
gem 'grape-entity', '~> 0.7.1'
|
||||
gem 'kaminari', '~> 1.1', '>= 1.1.1'
|
||||
|
||||
gem 'bootsnap', '>= 1.1.0', require: false
|
||||
|
||||
gem 'gitlab', path: 'lib/gitlab-cli'
|
||||
|
||||
gem 'chinese_pinyin'
|
||||
|
||||
gem 'rack-cors'
|
||||
gem 'redis-rails'
|
||||
gem 'roo-xls'
|
||||
gem 'simple_xlsx_reader'
|
||||
|
||||
gem 'rubyzip'
|
||||
|
||||
gem 'spreadsheet'
|
||||
gem 'ruby-ole'
|
||||
# 导出为xlsx
|
||||
gem 'axlsx', '~> 3.0.0.pre'
|
||||
gem 'axlsx_rails', '~> 0.5.2'
|
||||
|
||||
gem 'oauth2'
|
||||
#导出为pdf
|
||||
gem 'pdfkit'
|
||||
gem 'wkhtmltopdf-binary'
|
||||
# gem 'request_store'
|
||||
#gem 'iconv'
|
||||
# markdown 转html
|
||||
gem 'redcarpet', '~> 3.4'
|
||||
|
||||
gem 'rqrcode', '~> 0.10.1'
|
||||
gem 'rqrcode_png'
|
||||
|
||||
gem 'acts-as-taggable-on', '~> 6.0'
|
||||
|
||||
# a tree structure
|
||||
gem 'ancestry'
|
||||
gem 'acts_as_list'
|
||||
gem 'omniauth-cas'
|
||||
|
||||
# profiler Middleware
|
||||
gem 'rack-mini-profiler'
|
||||
|
||||
# object-based searching
|
||||
gem 'ransack'
|
||||
|
||||
group :development, :test do
|
||||
gem 'rspec-rails', '~> 3.8'
|
||||
end
|
||||
|
||||
group :development do
|
||||
gem 'prettier'
|
||||
gem 'rubocop', '~> 0.52.0'
|
||||
gem 'solargraph', '~> 0.38.0'
|
||||
gem 'awesome_print'
|
||||
gem 'web-console', '>= 3.3.0'
|
||||
gem 'listen', '>= 3.0.5', '< 3.2'
|
||||
gem 'spring'
|
||||
gem 'spring-watcher-listen', '~> 2.0.0'
|
||||
end
|
||||
|
||||
group :test do
|
||||
gem 'capybara', '>= 2.15', '< 4.0'
|
||||
gem 'selenium-webdriver'
|
||||
gem 'chromedriver-helper'
|
||||
end
|
||||
|
||||
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
|
||||
|
||||
#编码检测
|
||||
gem 'rchardet', '~> 1.8'
|
||||
|
||||
# http client
|
||||
gem 'faraday', '~> 0.15.4'
|
||||
|
||||
# view
|
||||
gem 'active_decorator'
|
||||
gem 'bootstrap', '~> 4.3.1'
|
||||
gem 'jquery-rails'
|
||||
gem 'simple_form'
|
||||
gem 'font-awesome-sass', '4.7.0'
|
||||
|
||||
# i18n
|
||||
gem 'rails-i18n', '~> 5.1'
|
||||
|
||||
# job
|
||||
gem 'sidekiq'
|
||||
gem 'sinatra'
|
||||
|
||||
# batch insert
|
||||
gem 'bulk_insert'
|
||||
|
||||
# elasticsearch
|
||||
gem 'searchkick'
|
||||
|
||||
gem 'aasm'
|
||||
gem 'enumerize'
|
||||
|
||||
gem 'diffy'
|
||||
|
||||
gem 'deep_cloneable', '~> 3.0.0'
|
||||
|
||||
# oauth2
|
||||
gem 'omniauth', '~> 1.9.0'
|
||||
gem 'omniauth-oauth2', '~> 1.6.0'
|
||||
|
||||
# global var
|
||||
gem 'request_store'
|
||||
|
||||
# 敏感词汇
|
||||
gem 'harmonious_dictionary', '~> 0.0.1'
|
||||
|
||||
gem 'parallel', '~> 1.19', '>= 1.19.1'
|
||||
|
|
68
Gemfile.lock
68
Gemfile.lock
|
@ -1,3 +1,10 @@
|
|||
PATH
|
||||
remote: lib/gitlab-cli
|
||||
specs:
|
||||
gitlab (3.2.0)
|
||||
httparty
|
||||
terminal-table
|
||||
|
||||
GEM
|
||||
remote: https://gems.ruby-china.com/
|
||||
specs:
|
||||
|
@ -54,9 +61,6 @@ GEM
|
|||
public_suffix (>= 2.0.2, < 5.0)
|
||||
ancestry (3.0.7)
|
||||
activerecord (>= 3.2.0)
|
||||
annotate (2.6.5)
|
||||
activerecord (>= 2.3.0)
|
||||
rake (>= 0.8.7)
|
||||
archive-zip (0.12.0)
|
||||
io-like (~> 0.3.0)
|
||||
arel (9.0.0)
|
||||
|
@ -106,12 +110,6 @@ GEM
|
|||
activerecord (>= 3.1.0, < 7)
|
||||
diff-lcs (1.3)
|
||||
diffy (3.3.0)
|
||||
domain_name (0.5.20190701)
|
||||
unf (>= 0.0.5, < 1.0.0)
|
||||
doorkeeper (5.5.1)
|
||||
railties (>= 5)
|
||||
doorkeeper-jwt (0.4.1)
|
||||
jwt (>= 2.1)
|
||||
e2mmap (0.1.0)
|
||||
elasticsearch (7.5.0)
|
||||
elasticsearch-api (= 7.5.0)
|
||||
|
@ -124,19 +122,12 @@ GEM
|
|||
enumerize (2.3.1)
|
||||
activesupport (>= 3.2)
|
||||
erubi (1.9.0)
|
||||
et-orbi (1.2.4)
|
||||
tzinfo
|
||||
execjs (2.7.0)
|
||||
faraday (0.15.4)
|
||||
multipart-post (>= 1.2, < 3)
|
||||
ffi (1.12.2)
|
||||
font-awesome-sass (4.7.0)
|
||||
sass (>= 3.2)
|
||||
fugit (1.4.1)
|
||||
et-orbi (~> 1.1, >= 1.1.8)
|
||||
raabro (~> 1.4)
|
||||
gitea-client (0.10.5)
|
||||
rest-client (~> 2.1.0)
|
||||
globalid (0.4.2)
|
||||
activesupport (>= 4.2.0)
|
||||
grape-entity (0.7.1)
|
||||
|
@ -147,9 +138,9 @@ GEM
|
|||
harmonious_dictionary (0.0.1)
|
||||
hashie (3.6.0)
|
||||
htmlentities (4.3.4)
|
||||
http-accept (1.7.0)
|
||||
http-cookie (1.0.5)
|
||||
domain_name (~> 0.5)
|
||||
httparty (0.18.0)
|
||||
mime-types (~> 3.0)
|
||||
multi_xml (>= 0.5.2)
|
||||
i18n (1.8.2)
|
||||
concurrent-ruby (~> 1.0)
|
||||
io-like (0.3.1)
|
||||
|
@ -173,7 +164,6 @@ GEM
|
|||
activerecord
|
||||
kaminari-core (= 1.2.0)
|
||||
kaminari-core (1.2.0)
|
||||
letter_avatar (0.3.8)
|
||||
listen (3.1.5)
|
||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||
rb-inotify (~> 0.9, >= 0.9.7)
|
||||
|
@ -187,12 +177,10 @@ GEM
|
|||
mimemagic (~> 0.3.2)
|
||||
maruku (0.7.3)
|
||||
method_source (0.9.2)
|
||||
mime-types (3.4.1)
|
||||
mime-types (3.3.1)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2022.0105)
|
||||
mimemagic (0.3.10)
|
||||
nokogiri (~> 1)
|
||||
rake
|
||||
mime-types-data (3.2019.1009)
|
||||
mimemagic (0.3.4)
|
||||
mini_mime (1.0.2)
|
||||
mini_portile2 (2.4.0)
|
||||
minitest (5.14.0)
|
||||
|
@ -203,7 +191,6 @@ GEM
|
|||
mustermann (1.1.1)
|
||||
ruby2_keywords (~> 0.0.1)
|
||||
mysql2 (0.5.3)
|
||||
netrc (0.11.0)
|
||||
nio4r (2.5.2)
|
||||
nokogiri (1.10.8)
|
||||
mini_portile2 (~> 2.4.0)
|
||||
|
@ -234,7 +221,6 @@ GEM
|
|||
prettier (0.18.2)
|
||||
public_suffix (4.0.3)
|
||||
puma (3.12.2)
|
||||
raabro (1.4.0)
|
||||
rack (2.0.9)
|
||||
rack-cors (1.1.1)
|
||||
rack (>= 2.0.0)
|
||||
|
@ -303,11 +289,6 @@ GEM
|
|||
regexp_parser (1.7.0)
|
||||
request_store (1.5.0)
|
||||
rack (>= 1.4)
|
||||
rest-client (2.1.0)
|
||||
http-accept (>= 1.7.0, < 2.0)
|
||||
http-cookie (>= 1.0.2, < 2.0)
|
||||
mime-types (>= 1.16, < 4.0)
|
||||
netrc (~> 0.8)
|
||||
reverse_markdown (1.4.0)
|
||||
nokogiri
|
||||
roo (2.8.3)
|
||||
|
@ -382,9 +363,6 @@ GEM
|
|||
rack (< 2.1.0)
|
||||
rack-protection (>= 1.5.0)
|
||||
redis (>= 3.3.5, < 5)
|
||||
sidekiq-cron (1.2.0)
|
||||
fugit (~> 1.1)
|
||||
sidekiq (>= 4.2.1)
|
||||
simple_form (5.0.2)
|
||||
actionpack (>= 5.0)
|
||||
activemodel (>= 5.0)
|
||||
|
@ -424,6 +402,8 @@ GEM
|
|||
actionpack (>= 4.0)
|
||||
activesupport (>= 4.0)
|
||||
sprockets (>= 3.0.0)
|
||||
terminal-table (1.8.0)
|
||||
unicode-display_width (~> 1.1, >= 1.1.1)
|
||||
thor (1.0.1)
|
||||
thread_safe (0.3.6)
|
||||
tilt (2.0.10)
|
||||
|
@ -434,9 +414,6 @@ GEM
|
|||
thread_safe (~> 0.1)
|
||||
uglifier (4.2.0)
|
||||
execjs (>= 0.3.0, < 3)
|
||||
unf (0.1.4)
|
||||
unf_ext
|
||||
unf_ext (0.0.8.2)
|
||||
unicode-display_width (1.6.1)
|
||||
web-console (3.7.0)
|
||||
actionview (>= 5.0)
|
||||
|
@ -460,7 +437,6 @@ DEPENDENCIES
|
|||
acts-as-taggable-on (~> 6.0)
|
||||
acts_as_list
|
||||
ancestry
|
||||
annotate (~> 2.6.0)
|
||||
awesome_print
|
||||
axlsx (~> 3.0.0.pre)
|
||||
axlsx_rails (~> 0.5.2)
|
||||
|
@ -473,20 +449,16 @@ DEPENDENCIES
|
|||
chromedriver-helper
|
||||
deep_cloneable (~> 3.0.0)
|
||||
diffy
|
||||
doorkeeper
|
||||
doorkeeper-jwt
|
||||
enumerize
|
||||
faraday (~> 0.15.4)
|
||||
font-awesome-sass (= 4.7.0)
|
||||
gitea-client (~> 0.10.2)
|
||||
gitlab!
|
||||
grape-entity (~> 0.7.1)
|
||||
groupdate (~> 4.1.0)
|
||||
harmonious_dictionary (~> 0.0.1)
|
||||
jbuilder (~> 2.5)
|
||||
jquery-rails
|
||||
jwt
|
||||
kaminari (~> 1.1, >= 1.1.1)
|
||||
letter_avatar
|
||||
listen (>= 3.0.5, < 3.2)
|
||||
mysql2 (>= 0.4.4, < 0.6.0)
|
||||
oauth2
|
||||
|
@ -516,8 +488,7 @@ DEPENDENCIES
|
|||
sass-rails (~> 5.0)
|
||||
searchkick
|
||||
selenium-webdriver
|
||||
sidekiq (= 5.2.8)
|
||||
sidekiq-cron (= 1.2.0)
|
||||
sidekiq
|
||||
simple_form
|
||||
simple_xlsx_reader
|
||||
sinatra
|
||||
|
@ -531,5 +502,8 @@ DEPENDENCIES
|
|||
web-console (>= 3.3.0)
|
||||
wkhtmltopdf-binary
|
||||
|
||||
RUBY VERSION
|
||||
ruby 2.3.7p456
|
||||
|
||||
BUNDLED WITH
|
||||
2.2.3
|
||||
2.1.4
|
||||
|
|
137
LICENSE
137
LICENSE
|
@ -1,124 +1,21 @@
|
|||
木兰宽松许可证, 第2版
|
||||
MIT License
|
||||
|
||||
2020年1月 http://license.coscl.org.cn/MulanPSL2
|
||||
Copyright (c) [year] [fullname]
|
||||
|
||||
您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
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:
|
||||
|
||||
0. 定义
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of 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.
|
||||
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.
|
||||
|
|
5105
api_document.md
5105
api_document.md
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 2.8 KiB |
|
@ -1,137 +1,101 @@
|
|||
//= require rails-ujs
|
||||
//= require activestorage
|
||||
//= require turbolinks
|
||||
//= require jquery3
|
||||
//= require popper
|
||||
//= require bootstrap-sprockets
|
||||
//= require jquery.validate.min
|
||||
//= require additional-methods.min
|
||||
//= require bootstrap-notify
|
||||
//= require jquery.cookie.min
|
||||
//= require select2
|
||||
//= require moment.min
|
||||
//= require jquery.cxselect
|
||||
//= require bootstrap-datepicker
|
||||
//= require bootstrap-datetimepicker
|
||||
//= require bootstrap.viewer
|
||||
//= require bootstrap/bootstrap-toggle
|
||||
//= require jquery.mloading
|
||||
//= require jquery-confirm.min
|
||||
//= require common
|
||||
|
||||
//= require echarts
|
||||
//= require codemirror/lib/codemirror
|
||||
//= require codemirror/mode/shell/shell
|
||||
//= require editormd/editormd
|
||||
//= require editormd/languages/zh-tw
|
||||
//= require dragula/dragula
|
||||
|
||||
//= require_tree ./i18n
|
||||
//= require_tree ./admins
|
||||
|
||||
|
||||
$.ajaxSetup({
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
|
||||
}
|
||||
});
|
||||
|
||||
// ******** select2 global config ********
|
||||
$.fn.select2.defaults.set('theme', 'bootstrap4');
|
||||
$.fn.select2.defaults.set('language', 'zh-CN');
|
||||
|
||||
Turbolinks.setProgressBarDelay(200);
|
||||
|
||||
$.notifyDefaults({
|
||||
type: 'success',
|
||||
z_index: 9999,
|
||||
delay: 2000
|
||||
});
|
||||
|
||||
function show_success_flash(){
|
||||
$.notify({
|
||||
message: '操作成功'
|
||||
},{
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on('turbolinks:load', function(){
|
||||
$('[data-toggle="tooltip"]').tooltip({ trigger : 'hover' });
|
||||
$('[data-toggle="popover"]').popover();
|
||||
|
||||
// 图片查看大图
|
||||
$('img.preview-image').bootstrapViewer();
|
||||
|
||||
// flash alert提示框自动关闭
|
||||
if($('.admin-alert-container .alert').length > 0){
|
||||
setTimeout(function(){
|
||||
$('.admin-alert-container .alert:not(.alert-danger)').alert('close');
|
||||
}, 2000);
|
||||
setTimeout(function(){
|
||||
$('.admin-alert-container .alert.alert-danger').alert('close');
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("turbolinks:before-cache", function () {
|
||||
$('[data-toggle="tooltip"]').tooltip('hide');
|
||||
$('[data-toggle="popover"]').popover('hide');
|
||||
});
|
||||
// var progressBar = new Turbolinks.ProgressBar();
|
||||
|
||||
// $(document).on('ajax:send', function(event){
|
||||
// console.log('ajax send', event);
|
||||
// progressBar.setValue(0)
|
||||
// progressBar.show()
|
||||
// });
|
||||
//
|
||||
// $(document).on('ajax:complete', function(event){
|
||||
// console.log('ajax complete', event);
|
||||
// progressBar.setValue(1)
|
||||
// progressBar.hide() // 分页时不触发,奇怪
|
||||
// });
|
||||
// $(document).on('ajax:success', function(event){
|
||||
// console.log('ajax success', event);
|
||||
// });
|
||||
// $(document).on('ajax:error', function(event){
|
||||
// console.log('ajax error', event);
|
||||
// });
|
||||
|
||||
$(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 {
|
||||
}
|
||||
});
|
||||
})
|
||||
//= require rails-ujs
|
||||
//= require activestorage
|
||||
//= require turbolinks
|
||||
//= require jquery3
|
||||
//= require popper
|
||||
//= require bootstrap-sprockets
|
||||
//= require jquery.validate.min
|
||||
//= require additional-methods.min
|
||||
//= require bootstrap-notify
|
||||
//= require jquery.cookie.min
|
||||
//= require select2
|
||||
//= require moment.min
|
||||
//= require jquery.cxselect
|
||||
//= require bootstrap-datepicker
|
||||
//= require bootstrap-datetimepicker
|
||||
//= require bootstrap.viewer
|
||||
//= require jquery.mloading
|
||||
//= require jquery-confirm.min
|
||||
//= require common
|
||||
|
||||
//= require echarts
|
||||
//= require codemirror/lib/codemirror
|
||||
//= require codemirror/mode/shell/shell
|
||||
//= require editormd/editormd
|
||||
//= require editormd/languages/zh-tw
|
||||
//= require dragula/dragula
|
||||
|
||||
//= require_tree ./i18n
|
||||
//= require_tree ./admins
|
||||
|
||||
|
||||
$.ajaxSetup({
|
||||
beforeSend: function(xhr) {
|
||||
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
|
||||
}
|
||||
});
|
||||
|
||||
// ******** select2 global config ********
|
||||
$.fn.select2.defaults.set('theme', 'bootstrap4');
|
||||
$.fn.select2.defaults.set('language', 'zh-CN');
|
||||
|
||||
Turbolinks.setProgressBarDelay(200);
|
||||
|
||||
$.notifyDefaults({
|
||||
type: 'success',
|
||||
z_index: 9999,
|
||||
delay: 2000
|
||||
});
|
||||
|
||||
function show_success_flash(){
|
||||
$.notify({
|
||||
message: '操作成功'
|
||||
},{
|
||||
type: 'success'
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on('turbolinks:load', function(){
|
||||
$('[data-toggle="tooltip"]').tooltip({ trigger : 'hover' });
|
||||
$('[data-toggle="popover"]').popover();
|
||||
|
||||
// 图片查看大图
|
||||
$('img.preview-image').bootstrapViewer();
|
||||
|
||||
// flash alert提示框自动关闭
|
||||
if($('.admin-alert-container .alert').length > 0){
|
||||
setTimeout(function(){
|
||||
$('.admin-alert-container .alert:not(.alert-danger)').alert('close');
|
||||
}, 2000);
|
||||
setTimeout(function(){
|
||||
$('.admin-alert-container .alert.alert-danger').alert('close');
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on("turbolinks:before-cache", function () {
|
||||
$('[data-toggle="tooltip"]').tooltip('hide');
|
||||
$('[data-toggle="popover"]').popover('hide');
|
||||
});
|
||||
// var progressBar = new Turbolinks.ProgressBar();
|
||||
|
||||
// $(document).on('ajax:send', function(event){
|
||||
// console.log('ajax send', event);
|
||||
// progressBar.setValue(0)
|
||||
// progressBar.show()
|
||||
// });
|
||||
//
|
||||
// $(document).on('ajax:complete', function(event){
|
||||
// console.log('ajax complete', event);
|
||||
// progressBar.setValue(1)
|
||||
// progressBar.hide() // 分页时不触发,奇怪
|
||||
// });
|
||||
// $(document).on('ajax:success', function(event){
|
||||
// console.log('ajax success', event);
|
||||
// });
|
||||
// $(document).on('ajax:error', function(event){
|
||||
// console.log('ajax error', event);
|
||||
// });
|
||||
|
||||
$(function () {
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
$(document).on('turbolinks:load', function() {
|
||||
if ($('body.admins-courses-index-page').length > 0) {
|
||||
var searchContainer = $(".course-list-form");
|
||||
var searchForm = $("form.search-form",searchContainer);
|
||||
let searchContainer = $(".course-list-form");
|
||||
let searchForm = $("form.search-form",searchContainer);
|
||||
|
||||
searchContainer.on('change', '.course-homepage-show', function(){
|
||||
searchForm.find('input[type="submit"]').trigger('click');
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -1,141 +0,0 @@
|
|||
/*
|
||||
* @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("")
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
})
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* @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,15 +1,7 @@
|
|||
/*
|
||||
* @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() {
|
||||
if ($('body.admins-shixun-settings-index-page').length > 0) {
|
||||
var searchContainer = $(".shixun-settings-list-form");
|
||||
var searchForm = $("form.search-form",searchContainer);
|
||||
let searchContainer = $(".shixun-settings-list-form");
|
||||
let searchForm = $("form.search-form",searchContainer);
|
||||
|
||||
searchContainer.on('change', '.shixun-settings-select', function(){
|
||||
searchForm.find('input[type="submit"]').trigger('click');
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
/*
|
||||
* @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("√")
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
})
|
|
@ -1,180 +0,0 @@
|
|||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap-toggle.js v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
|
||||
|
||||
+function ($) {
|
||||
'use strict';
|
||||
|
||||
// TOGGLE PUBLIC CLASS DEFINITION
|
||||
// ==============================
|
||||
|
||||
var Toggle = function (element, options) {
|
||||
this.$element = $(element)
|
||||
this.options = $.extend({}, this.defaults(), options)
|
||||
this.render()
|
||||
}
|
||||
|
||||
Toggle.VERSION = '2.2.0'
|
||||
|
||||
Toggle.DEFAULTS = {
|
||||
on: 'On',
|
||||
off: 'Off',
|
||||
onstyle: 'primary',
|
||||
offstyle: 'default',
|
||||
size: 'normal',
|
||||
style: '',
|
||||
width: null,
|
||||
height: null
|
||||
}
|
||||
|
||||
Toggle.prototype.defaults = function() {
|
||||
return {
|
||||
on: this.$element.attr('data-on') || Toggle.DEFAULTS.on,
|
||||
off: this.$element.attr('data-off') || Toggle.DEFAULTS.off,
|
||||
onstyle: this.$element.attr('data-onstyle') || Toggle.DEFAULTS.onstyle,
|
||||
offstyle: this.$element.attr('data-offstyle') || Toggle.DEFAULTS.offstyle,
|
||||
size: this.$element.attr('data-size') || Toggle.DEFAULTS.size,
|
||||
style: this.$element.attr('data-style') || Toggle.DEFAULTS.style,
|
||||
width: this.$element.attr('data-width') || Toggle.DEFAULTS.width,
|
||||
height: this.$element.attr('data-height') || Toggle.DEFAULTS.height
|
||||
}
|
||||
}
|
||||
|
||||
Toggle.prototype.render = function () {
|
||||
this._onstyle = 'btn-' + this.options.onstyle
|
||||
this._offstyle = 'btn-' + this.options.offstyle
|
||||
var size = this.options.size === 'large' ? 'btn-lg'
|
||||
: this.options.size === 'small' ? 'btn-sm'
|
||||
: this.options.size === 'mini' ? 'btn-xs'
|
||||
: ''
|
||||
var $toggleOn = $('<label class="btn">').html(this.options.on)
|
||||
.addClass(this._onstyle + ' ' + size)
|
||||
var $toggleOff = $('<label class="btn">').html(this.options.off)
|
||||
.addClass(this._offstyle + ' ' + size + ' active')
|
||||
var $toggleHandle = $('<span class="toggle-handle btn btn-default">')
|
||||
.addClass(size)
|
||||
var $toggleGroup = $('<div class="toggle-group">')
|
||||
.append($toggleOn, $toggleOff, $toggleHandle)
|
||||
var $toggle = $('<div class="toggle btn" data-toggle="toggle">')
|
||||
.addClass( this.$element.prop('checked') ? this._onstyle : this._offstyle+' off' )
|
||||
.addClass(size).addClass(this.options.style)
|
||||
|
||||
this.$element.wrap($toggle)
|
||||
$.extend(this, {
|
||||
$toggle: this.$element.parent(),
|
||||
$toggleOn: $toggleOn,
|
||||
$toggleOff: $toggleOff,
|
||||
$toggleGroup: $toggleGroup
|
||||
})
|
||||
this.$toggle.append($toggleGroup)
|
||||
|
||||
var width = this.options.width || Math.max($toggleOn.outerWidth(), $toggleOff.outerWidth())+($toggleHandle.outerWidth()/2)
|
||||
var height = this.options.height || Math.max($toggleOn.outerHeight(), $toggleOff.outerHeight())
|
||||
$toggleOn.addClass('toggle-on')
|
||||
$toggleOff.addClass('toggle-off')
|
||||
this.$toggle.css({ width: width, height: height })
|
||||
if (this.options.height) {
|
||||
$toggleOn.css('line-height', $toggleOn.height() + 'px')
|
||||
$toggleOff.css('line-height', $toggleOff.height() + 'px')
|
||||
}
|
||||
this.update(true)
|
||||
this.trigger(true)
|
||||
}
|
||||
|
||||
Toggle.prototype.toggle = function () {
|
||||
if (this.$element.prop('checked')) this.off()
|
||||
else this.on()
|
||||
}
|
||||
|
||||
Toggle.prototype.on = function (silent) {
|
||||
if (this.$element.prop('disabled')) return false
|
||||
this.$toggle.removeClass(this._offstyle + ' off').addClass(this._onstyle)
|
||||
this.$element.prop('checked', true)
|
||||
if (!silent) this.trigger()
|
||||
}
|
||||
|
||||
Toggle.prototype.off = function (silent) {
|
||||
if (this.$element.prop('disabled')) return false
|
||||
this.$toggle.removeClass(this._onstyle).addClass(this._offstyle + ' off')
|
||||
this.$element.prop('checked', false)
|
||||
if (!silent) this.trigger()
|
||||
}
|
||||
|
||||
Toggle.prototype.enable = function () {
|
||||
this.$toggle.removeAttr('disabled')
|
||||
this.$element.prop('disabled', false)
|
||||
}
|
||||
|
||||
Toggle.prototype.disable = function () {
|
||||
this.$toggle.attr('disabled', 'disabled')
|
||||
this.$element.prop('disabled', true)
|
||||
}
|
||||
|
||||
Toggle.prototype.update = function (silent) {
|
||||
if (this.$element.prop('disabled')) this.disable()
|
||||
else this.enable()
|
||||
if (this.$element.prop('checked')) this.on(silent)
|
||||
else this.off(silent)
|
||||
}
|
||||
|
||||
Toggle.prototype.trigger = function (silent) {
|
||||
this.$element.off('change.bs.toggle')
|
||||
if (!silent) this.$element.change()
|
||||
this.$element.on('change.bs.toggle', $.proxy(function() {
|
||||
this.update()
|
||||
}, this))
|
||||
}
|
||||
|
||||
Toggle.prototype.destroy = function() {
|
||||
this.$element.off('change.bs.toggle')
|
||||
this.$toggleGroup.remove()
|
||||
this.$element.removeData('bs.toggle')
|
||||
this.$element.unwrap()
|
||||
}
|
||||
|
||||
// TOGGLE PLUGIN DEFINITION
|
||||
// ========================
|
||||
|
||||
function Plugin(option) {
|
||||
return this.each(function () {
|
||||
var $this = $(this)
|
||||
var data = $this.data('bs.toggle')
|
||||
var options = typeof option == 'object' && option
|
||||
|
||||
if (!data) $this.data('bs.toggle', (data = new Toggle(this, options)))
|
||||
if (typeof option == 'string' && data[option]) data[option]()
|
||||
})
|
||||
}
|
||||
|
||||
var old = $.fn.bootstrapToggle
|
||||
|
||||
$.fn.bootstrapToggle = Plugin
|
||||
$.fn.bootstrapToggle.Constructor = Toggle
|
||||
|
||||
// TOGGLE NO CONFLICT
|
||||
// ==================
|
||||
|
||||
$.fn.toggle.noConflict = function () {
|
||||
$.fn.bootstrapToggle = old
|
||||
return this
|
||||
}
|
||||
|
||||
// TOGGLE DATA-API
|
||||
// ===============
|
||||
|
||||
$(function() {
|
||||
$('input[type=checkbox][data-toggle^=toggle]').bootstrapToggle()
|
||||
})
|
||||
|
||||
$(document).on('click.bs.toggle', 'div[data-toggle^=toggle]', function(e) {
|
||||
var $checkbox = $(this).find('input[type=checkbox]')
|
||||
$checkbox.bootstrapToggle('toggle')
|
||||
e.preventDefault()
|
||||
})
|
||||
|
||||
}(jQuery);
|
|
@ -1,9 +0,0 @@
|
|||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap-toggle.js v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.toggle"),f="object"==typeof b&&b;e||d.data("bs.toggle",e=new c(this,f)),"string"==typeof b&&e[b]&&e[b]()})}var c=function(b,c){this.$element=a(b),this.options=a.extend({},this.defaults(),c),this.render()};c.VERSION="2.2.0",c.DEFAULTS={on:"On",off:"Off",onstyle:"primary",offstyle:"default",size:"normal",style:"",width:null,height:null},c.prototype.defaults=function(){return{on:this.$element.attr("data-on")||c.DEFAULTS.on,off:this.$element.attr("data-off")||c.DEFAULTS.off,onstyle:this.$element.attr("data-onstyle")||c.DEFAULTS.onstyle,offstyle:this.$element.attr("data-offstyle")||c.DEFAULTS.offstyle,size:this.$element.attr("data-size")||c.DEFAULTS.size,style:this.$element.attr("data-style")||c.DEFAULTS.style,width:this.$element.attr("data-width")||c.DEFAULTS.width,height:this.$element.attr("data-height")||c.DEFAULTS.height}},c.prototype.render=function(){this._onstyle="btn-"+this.options.onstyle,this._offstyle="btn-"+this.options.offstyle;var b="large"===this.options.size?"btn-lg":"small"===this.options.size?"btn-sm":"mini"===this.options.size?"btn-xs":"",c=a('<label class="btn">').html(this.options.on).addClass(this._onstyle+" "+b),d=a('<label class="btn">').html(this.options.off).addClass(this._offstyle+" "+b+" active"),e=a('<span class="toggle-handle btn btn-default">').addClass(b),f=a('<div class="toggle-group">').append(c,d,e),g=a('<div class="toggle btn" data-toggle="toggle">').addClass(this.$element.prop("checked")?this._onstyle:this._offstyle+" off").addClass(b).addClass(this.options.style);this.$element.wrap(g),a.extend(this,{$toggle:this.$element.parent(),$toggleOn:c,$toggleOff:d,$toggleGroup:f}),this.$toggle.append(f);var h=this.options.width||Math.max(c.outerWidth(),d.outerWidth())+e.outerWidth()/2,i=this.options.height||Math.max(c.outerHeight(),d.outerHeight());c.addClass("toggle-on"),d.addClass("toggle-off"),this.$toggle.css({width:h,height:i}),this.options.height&&(c.css("line-height",c.height()+"px"),d.css("line-height",d.height()+"px")),this.update(!0),this.trigger(!0)},c.prototype.toggle=function(){this.$element.prop("checked")?this.off():this.on()},c.prototype.on=function(a){return this.$element.prop("disabled")?!1:(this.$toggle.removeClass(this._offstyle+" off").addClass(this._onstyle),this.$element.prop("checked",!0),void(a||this.trigger()))},c.prototype.off=function(a){return this.$element.prop("disabled")?!1:(this.$toggle.removeClass(this._onstyle).addClass(this._offstyle+" off"),this.$element.prop("checked",!1),void(a||this.trigger()))},c.prototype.enable=function(){this.$toggle.removeAttr("disabled"),this.$element.prop("disabled",!1)},c.prototype.disable=function(){this.$toggle.attr("disabled","disabled"),this.$element.prop("disabled",!0)},c.prototype.update=function(a){this.$element.prop("disabled")?this.disable():this.enable(),this.$element.prop("checked")?this.on(a):this.off(a)},c.prototype.trigger=function(b){this.$element.off("change.bs.toggle"),b||this.$element.change(),this.$element.on("change.bs.toggle",a.proxy(function(){this.update()},this))},c.prototype.destroy=function(){this.$element.off("change.bs.toggle"),this.$toggleGroup.remove(),this.$element.removeData("bs.toggle"),this.$element.unwrap()};var d=a.fn.bootstrapToggle;a.fn.bootstrapToggle=b,a.fn.bootstrapToggle.Constructor=c,a.fn.toggle.noConflict=function(){return a.fn.bootstrapToggle=d,this},a(function(){a("input[type=checkbox][data-toggle^=toggle]").bootstrapToggle()}),a(document).on("click.bs.toggle","div[data-toggle^=toggle]",function(b){var c=a(this).find("input[type=checkbox]");c.bootstrapToggle("toggle"),b.preventDefault()})}(jQuery);
|
||||
//# sourceMappingURL=bootstrap-toggle.min.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"bootstrap-toggle.min.js","sources":["bootstrap-toggle.js"],"names":["$","Plugin","option","this","each","$this","data","options","Toggle","element","$element","extend","defaults","render","VERSION","DEFAULTS","on","off","onstyle","offstyle","size","style","width","height","prototype","attr","_onstyle","_offstyle","$toggleOn","html","addClass","$toggleOff","$toggleHandle","$toggleGroup","append","$toggle","prop","wrap","parent","Math","max","outerWidth","outerHeight","css","update","trigger","toggle","silent","removeClass","enable","removeAttr","disable","change","proxy","destroy","remove","removeData","unwrap","old","fn","bootstrapToggle","Constructor","noConflict","document","e","$checkbox","find","preventDefault","jQuery"],"mappings":";;;;;;;CASE,SAAUA,GACV,YAoID,SAASC,GAAOC,GACf,MAAOC,MAAKC,KAAK,WAChB,GAAIC,GAAUL,EAAEG,MACZG,EAAUD,EAAMC,KAAK,aACrBC,EAA2B,gBAAVL,IAAsBA,CAEtCI,IAAMD,EAAMC,KAAK,YAAcA,EAAO,GAAIE,GAAOL,KAAMI,IACvC,gBAAVL,IAAsBI,EAAKJ,IAASI,EAAKJ,OAtItD,GAAIM,GAAS,SAAUC,EAASF,GAC/BJ,KAAKO,SAAYV,EAAES,GACnBN,KAAKI,QAAYP,EAAEW,UAAWR,KAAKS,WAAYL,GAC/CJ,KAAKU,SAGNL,GAAOM,QAAW,QAElBN,EAAOO,UACNC,GAAI,KACJC,IAAK,MACLC,QAAS,UACTC,SAAU,UACVC,KAAM,SACNC,MAAO,GACPC,MAAO,KACPC,OAAQ,MAGTf,EAAOgB,UAAUZ,SAAW,WAC3B,OACCI,GAAIb,KAAKO,SAASe,KAAK,YAAcjB,EAAOO,SAASC,GACrDC,IAAKd,KAAKO,SAASe,KAAK,aAAejB,EAAOO,SAASE,IACvDC,QAASf,KAAKO,SAASe,KAAK,iBAAmBjB,EAAOO,SAASG,QAC/DC,SAAUhB,KAAKO,SAASe,KAAK,kBAAoBjB,EAAOO,SAASI,SACjEC,KAAMjB,KAAKO,SAASe,KAAK,cAAgBjB,EAAOO,SAASK,KACzDC,MAAOlB,KAAKO,SAASe,KAAK,eAAiBjB,EAAOO,SAASM,MAC3DC,MAAOnB,KAAKO,SAASe,KAAK,eAAiBjB,EAAOO,SAASO,MAC3DC,OAAQpB,KAAKO,SAASe,KAAK,gBAAkBjB,EAAOO,SAASQ,SAI/Df,EAAOgB,UAAUX,OAAS,WACzBV,KAAKuB,SAAW,OAASvB,KAAKI,QAAQW,QACtCf,KAAKwB,UAAY,OAASxB,KAAKI,QAAQY,QACvC,IAAIC,GAA6B,UAAtBjB,KAAKI,QAAQa,KAAmB,SAClB,UAAtBjB,KAAKI,QAAQa,KAAmB,SACV,SAAtBjB,KAAKI,QAAQa,KAAkB,SAC/B,GACCQ,EAAY5B,EAAE,uBAAuB6B,KAAK1B,KAAKI,QAAQS,IACzDc,SAAS3B,KAAKuB,SAAW,IAAMN,GAC7BW,EAAa/B,EAAE,uBAAuB6B,KAAK1B,KAAKI,QAAQU,KAC1Da,SAAS3B,KAAKwB,UAAY,IAAMP,EAAO,WACrCY,EAAgBhC,EAAE,gDACpB8B,SAASV,GACPa,EAAejC,EAAE,8BACnBkC,OAAON,EAAWG,EAAYC,GAC5BG,EAAUnC,EAAE,iDACd8B,SAAU3B,KAAKO,SAAS0B,KAAK,WAAajC,KAAKuB,SAAWvB,KAAKwB,UAAU,QACzEG,SAASV,GAAMU,SAAS3B,KAAKI,QAAQc,MAEvClB,MAAKO,SAAS2B,KAAKF,GACnBnC,EAAEW,OAAOR,MACRgC,QAAShC,KAAKO,SAAS4B,SACvBV,UAAWA,EACXG,WAAYA,EACZE,aAAcA,IAEf9B,KAAKgC,QAAQD,OAAOD,EAEpB,IAAIX,GAAQnB,KAAKI,QAAQe,OAASiB,KAAKC,IAAIZ,EAAUa,aAAcV,EAAWU,cAAeT,EAAcS,aAAa,EACpHlB,EAASpB,KAAKI,QAAQgB,QAAUgB,KAAKC,IAAIZ,EAAUc,cAAeX,EAAWW,cACjFd,GAAUE,SAAS,aACnBC,EAAWD,SAAS,cACpB3B,KAAKgC,QAAQQ,KAAMrB,MAAOA,EAAOC,OAAQA,IACrCpB,KAAKI,QAAQgB,SAChBK,EAAUe,IAAI,cAAef,EAAUL,SAAW,MAClDQ,EAAWY,IAAI,cAAeZ,EAAWR,SAAW,OAErDpB,KAAKyC,QAAO,GACZzC,KAAK0C,SAAQ,IAGdrC,EAAOgB,UAAUsB,OAAS,WACrB3C,KAAKO,SAAS0B,KAAK,WAAYjC,KAAKc,MACnCd,KAAKa,MAGXR,EAAOgB,UAAUR,GAAK,SAAU+B,GAC/B,MAAI5C,MAAKO,SAAS0B,KAAK,aAAoB,GAC3CjC,KAAKgC,QAAQa,YAAY7C,KAAKwB,UAAY,QAAQG,SAAS3B,KAAKuB,UAChEvB,KAAKO,SAAS0B,KAAK,WAAW,QACzBW,GAAQ5C,KAAK0C,aAGnBrC,EAAOgB,UAAUP,IAAM,SAAU8B,GAChC,MAAI5C,MAAKO,SAAS0B,KAAK,aAAoB,GAC3CjC,KAAKgC,QAAQa,YAAY7C,KAAKuB,UAAUI,SAAS3B,KAAKwB,UAAY,QAClExB,KAAKO,SAAS0B,KAAK,WAAW,QACzBW,GAAQ5C,KAAK0C,aAGnBrC,EAAOgB,UAAUyB,OAAS,WACzB9C,KAAKgC,QAAQe,WAAW,YACxB/C,KAAKO,SAAS0B,KAAK,YAAY,IAGhC5B,EAAOgB,UAAU2B,QAAU,WAC1BhD,KAAKgC,QAAQV,KAAK,WAAY,YAC9BtB,KAAKO,SAAS0B,KAAK,YAAY,IAGhC5B,EAAOgB,UAAUoB,OAAS,SAAUG,GAC/B5C,KAAKO,SAAS0B,KAAK,YAAajC,KAAKgD,UACpChD,KAAK8C,SACN9C,KAAKO,SAAS0B,KAAK,WAAYjC,KAAKa,GAAG+B,GACtC5C,KAAKc,IAAI8B,IAGfvC,EAAOgB,UAAUqB,QAAU,SAAUE,GACpC5C,KAAKO,SAASO,IAAI,oBACb8B,GAAQ5C,KAAKO,SAAS0C,SAC3BjD,KAAKO,SAASM,GAAG,mBAAoBhB,EAAEqD,MAAM,WAC5ClD,KAAKyC,UACHzC,QAGJK,EAAOgB,UAAU8B,QAAU,WAC1BnD,KAAKO,SAASO,IAAI,oBAClBd,KAAK8B,aAAasB,SAClBpD,KAAKO,SAAS8C,WAAW,aACzBrD,KAAKO,SAAS+C,SAiBf,IAAIC,GAAM1D,EAAE2D,GAAGC,eAEf5D,GAAE2D,GAAGC,gBAA8B3D,EACnCD,EAAE2D,GAAGC,gBAAgBC,YAAcrD,EAKnCR,EAAE2D,GAAGb,OAAOgB,WAAa,WAExB,MADA9D,GAAE2D,GAAGC,gBAAkBF,EAChBvD,MAMRH,EAAE,WACDA,EAAE,6CAA6C4D,oBAGhD5D,EAAE+D,UAAU/C,GAAG,kBAAmB,2BAA4B,SAASgD,GACtE,GAAIC,GAAYjE,EAAEG,MAAM+D,KAAK,uBAC7BD,GAAUL,gBAAgB,UAC1BI,EAAEG,oBAGFC"}
|
|
@ -1,180 +0,0 @@
|
|||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap2-toggle.js v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
|
||||
|
||||
+function ($) {
|
||||
'use strict';
|
||||
|
||||
// TOGGLE PUBLIC CLASS DEFINITION
|
||||
// ==============================
|
||||
|
||||
var Toggle = function (element, options) {
|
||||
this.$element = $(element)
|
||||
this.options = $.extend({}, this.defaults(), options)
|
||||
this.render()
|
||||
}
|
||||
|
||||
Toggle.VERSION = '2.2.0'
|
||||
|
||||
Toggle.DEFAULTS = {
|
||||
on: 'On',
|
||||
off: 'Off',
|
||||
onstyle: 'primary',
|
||||
offstyle: 'default',
|
||||
size: 'normal',
|
||||
style: '',
|
||||
width: null,
|
||||
height: null
|
||||
}
|
||||
|
||||
Toggle.prototype.defaults = function() {
|
||||
return {
|
||||
on: this.$element.attr('data-on') || Toggle.DEFAULTS.on,
|
||||
off: this.$element.attr('data-off') || Toggle.DEFAULTS.off,
|
||||
onstyle: this.$element.attr('data-onstyle') || Toggle.DEFAULTS.onstyle,
|
||||
offstyle: this.$element.attr('data-offstyle') || Toggle.DEFAULTS.offstyle,
|
||||
size: this.$element.attr('data-size') || Toggle.DEFAULTS.size,
|
||||
style: this.$element.attr('data-style') || Toggle.DEFAULTS.style,
|
||||
width: this.$element.attr('data-width') || Toggle.DEFAULTS.width,
|
||||
height: this.$element.attr('data-height') || Toggle.DEFAULTS.height
|
||||
}
|
||||
}
|
||||
|
||||
Toggle.prototype.render = function () {
|
||||
this._onstyle = 'btn-' + this.options.onstyle
|
||||
this._offstyle = 'btn-' + this.options.offstyle
|
||||
var size = this.options.size === 'large' ? 'btn-large'
|
||||
: this.options.size === 'small' ? 'btn-small'
|
||||
: this.options.size === 'mini' ? 'btn-mini'
|
||||
: ''
|
||||
var $toggleOn = $('<label class="btn">').html(this.options.on)
|
||||
.addClass(this._onstyle + ' ' + size)
|
||||
var $toggleOff = $('<label class="btn">').html(this.options.off)
|
||||
.addClass(this._offstyle + ' ' + size + ' active')
|
||||
var $toggleHandle = $('<span class="toggle-handle btn btn-default">')
|
||||
.addClass(size)
|
||||
var $toggleGroup = $('<div class="toggle-group">')
|
||||
.append($toggleOn, $toggleOff, $toggleHandle)
|
||||
var $toggle = $('<div class="toggle btn" data-toggle="toggle">')
|
||||
.addClass( this.$element.prop('checked') ? this._onstyle : this._offstyle+' off' )
|
||||
.addClass(size).addClass(this.options.style)
|
||||
|
||||
this.$element.wrap($toggle)
|
||||
$.extend(this, {
|
||||
$toggle: this.$element.parent(),
|
||||
$toggleOn: $toggleOn,
|
||||
$toggleOff: $toggleOff,
|
||||
$toggleGroup: $toggleGroup
|
||||
})
|
||||
this.$toggle.append($toggleGroup)
|
||||
|
||||
var width = this.options.width || Math.max($toggleOn.width(), $toggleOff.width())+($toggleHandle.outerWidth()/2)
|
||||
var height = this.options.height || Math.max($toggleOn.height(), $toggleOff.height())
|
||||
$toggleOn.addClass('toggle-on')
|
||||
$toggleOff.addClass('toggle-off')
|
||||
this.$toggle.css({ width: width, height: height })
|
||||
if (this.options.height) {
|
||||
$toggleOn.css('line-height', $toggleOn.height() + 'px')
|
||||
$toggleOff.css('line-height', $toggleOff.height() + 'px')
|
||||
}
|
||||
this.update(true)
|
||||
this.trigger(true)
|
||||
}
|
||||
|
||||
Toggle.prototype.toggle = function () {
|
||||
if (this.$element.prop('checked')) this.off()
|
||||
else this.on()
|
||||
}
|
||||
|
||||
Toggle.prototype.on = function (silent) {
|
||||
if (this.$element.prop('disabled')) return false
|
||||
this.$toggle.removeClass(this._offstyle + ' off').addClass(this._onstyle)
|
||||
this.$element.prop('checked', true)
|
||||
if (!silent) this.trigger()
|
||||
}
|
||||
|
||||
Toggle.prototype.off = function (silent) {
|
||||
if (this.$element.prop('disabled')) return false
|
||||
this.$toggle.removeClass(this._onstyle).addClass(this._offstyle + ' off')
|
||||
this.$element.prop('checked', false)
|
||||
if (!silent) this.trigger()
|
||||
}
|
||||
|
||||
Toggle.prototype.enable = function () {
|
||||
this.$toggle.removeAttr('disabled')
|
||||
this.$element.prop('disabled', false)
|
||||
}
|
||||
|
||||
Toggle.prototype.disable = function () {
|
||||
this.$toggle.attr('disabled', 'disabled')
|
||||
this.$element.prop('disabled', true)
|
||||
}
|
||||
|
||||
Toggle.prototype.update = function (silent) {
|
||||
if (this.$element.prop('disabled')) this.disable()
|
||||
else this.enable()
|
||||
if (this.$element.prop('checked')) this.on(silent)
|
||||
else this.off(silent)
|
||||
}
|
||||
|
||||
Toggle.prototype.trigger = function (silent) {
|
||||
this.$element.off('change.bs.toggle')
|
||||
if (!silent) this.$element.change()
|
||||
this.$element.on('change.bs.toggle', $.proxy(function() {
|
||||
this.update()
|
||||
}, this))
|
||||
}
|
||||
|
||||
Toggle.prototype.destroy = function() {
|
||||
this.$element.off('change.bs.toggle')
|
||||
this.$toggleGroup.remove()
|
||||
this.$element.removeData('bs.toggle')
|
||||
this.$element.unwrap()
|
||||
}
|
||||
|
||||
// TOGGLE PLUGIN DEFINITION
|
||||
// ========================
|
||||
|
||||
function Plugin(option) {
|
||||
return this.each(function () {
|
||||
var $this = $(this)
|
||||
var data = $this.data('bs.toggle')
|
||||
var options = typeof option == 'object' && option
|
||||
|
||||
if (!data) $this.data('bs.toggle', (data = new Toggle(this, options)))
|
||||
if (typeof option == 'string' && data[option]) data[option]()
|
||||
})
|
||||
}
|
||||
|
||||
var old = $.fn.bootstrapToggle
|
||||
|
||||
$.fn.bootstrapToggle = Plugin
|
||||
$.fn.bootstrapToggle.Constructor = Toggle
|
||||
|
||||
// TOGGLE NO CONFLICT
|
||||
// ==================
|
||||
|
||||
$.fn.toggle.noConflict = function () {
|
||||
$.fn.bootstrapToggle = old
|
||||
return this
|
||||
}
|
||||
|
||||
// TOGGLE DATA-API
|
||||
// ===============
|
||||
|
||||
$(function() {
|
||||
$('input[type=checkbox][data-toggle^=toggle]').bootstrapToggle()
|
||||
})
|
||||
|
||||
$(document).on('click.bs.toggle', 'div[data-toggle^=toggle]', function(e) {
|
||||
var $checkbox = $(this).find('input[type=checkbox]')
|
||||
$checkbox.bootstrapToggle('toggle')
|
||||
e.preventDefault()
|
||||
})
|
||||
|
||||
}(jQuery);
|
|
@ -1,9 +0,0 @@
|
|||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap2-toggle.js v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
+function(a){"use strict";function b(b){return this.each(function(){var d=a(this),e=d.data("bs.toggle"),f="object"==typeof b&&b;e||d.data("bs.toggle",e=new c(this,f)),"string"==typeof b&&e[b]&&e[b]()})}var c=function(b,c){this.$element=a(b),this.options=a.extend({},this.defaults(),c),this.render()};c.VERSION="2.2.0",c.DEFAULTS={on:"On",off:"Off",onstyle:"primary",offstyle:"default",size:"normal",style:"",width:null,height:null},c.prototype.defaults=function(){return{on:this.$element.attr("data-on")||c.DEFAULTS.on,off:this.$element.attr("data-off")||c.DEFAULTS.off,onstyle:this.$element.attr("data-onstyle")||c.DEFAULTS.onstyle,offstyle:this.$element.attr("data-offstyle")||c.DEFAULTS.offstyle,size:this.$element.attr("data-size")||c.DEFAULTS.size,style:this.$element.attr("data-style")||c.DEFAULTS.style,width:this.$element.attr("data-width")||c.DEFAULTS.width,height:this.$element.attr("data-height")||c.DEFAULTS.height}},c.prototype.render=function(){this._onstyle="btn-"+this.options.onstyle,this._offstyle="btn-"+this.options.offstyle;var b="large"===this.options.size?"btn-large":"small"===this.options.size?"btn-small":"mini"===this.options.size?"btn-mini":"",c=a('<label class="btn">').html(this.options.on).addClass(this._onstyle+" "+b),d=a('<label class="btn">').html(this.options.off).addClass(this._offstyle+" "+b+" active"),e=a('<span class="toggle-handle btn btn-default">').addClass(b),f=a('<div class="toggle-group">').append(c,d,e),g=a('<div class="toggle btn" data-toggle="toggle">').addClass(this.$element.prop("checked")?this._onstyle:this._offstyle+" off").addClass(b).addClass(this.options.style);this.$element.wrap(g),a.extend(this,{$toggle:this.$element.parent(),$toggleOn:c,$toggleOff:d,$toggleGroup:f}),this.$toggle.append(f);var h=this.options.width||Math.max(c.width(),d.width())+e.outerWidth()/2,i=this.options.height||Math.max(c.height(),d.height());c.addClass("toggle-on"),d.addClass("toggle-off"),this.$toggle.css({width:h,height:i}),this.options.height&&(c.css("line-height",c.height()+"px"),d.css("line-height",d.height()+"px")),this.update(!0),this.trigger(!0)},c.prototype.toggle=function(){this.$element.prop("checked")?this.off():this.on()},c.prototype.on=function(a){return this.$element.prop("disabled")?!1:(this.$toggle.removeClass(this._offstyle+" off").addClass(this._onstyle),this.$element.prop("checked",!0),void(a||this.trigger()))},c.prototype.off=function(a){return this.$element.prop("disabled")?!1:(this.$toggle.removeClass(this._onstyle).addClass(this._offstyle+" off"),this.$element.prop("checked",!1),void(a||this.trigger()))},c.prototype.enable=function(){this.$toggle.removeAttr("disabled"),this.$element.prop("disabled",!1)},c.prototype.disable=function(){this.$toggle.attr("disabled","disabled"),this.$element.prop("disabled",!0)},c.prototype.update=function(a){this.$element.prop("disabled")?this.disable():this.enable(),this.$element.prop("checked")?this.on(a):this.off(a)},c.prototype.trigger=function(b){this.$element.off("change.bs.toggle"),b||this.$element.change(),this.$element.on("change.bs.toggle",a.proxy(function(){this.update()},this))},c.prototype.destroy=function(){this.$element.off("change.bs.toggle"),this.$toggleGroup.remove(),this.$element.removeData("bs.toggle"),this.$element.unwrap()};var d=a.fn.bootstrapToggle;a.fn.bootstrapToggle=b,a.fn.bootstrapToggle.Constructor=c,a.fn.toggle.noConflict=function(){return a.fn.bootstrapToggle=d,this},a(function(){a("input[type=checkbox][data-toggle^=toggle]").bootstrapToggle()}),a(document).on("click.bs.toggle","div[data-toggle^=toggle]",function(b){var c=a(this).find("input[type=checkbox]");c.bootstrapToggle("toggle"),b.preventDefault()})}(jQuery);
|
||||
//# sourceMappingURL=bootstrap2-toggle.min.js.map
|
|
@ -1 +0,0 @@
|
|||
{"version":3,"file":"bootstrap2-toggle.min.js","sources":["bootstrap2-toggle.js"],"names":["$","Plugin","option","this","each","$this","data","options","Toggle","element","$element","extend","defaults","render","VERSION","DEFAULTS","on","off","onstyle","offstyle","size","style","width","height","prototype","attr","_onstyle","_offstyle","$toggleOn","html","addClass","$toggleOff","$toggleHandle","$toggleGroup","append","$toggle","prop","wrap","parent","Math","max","outerWidth","css","update","trigger","toggle","silent","removeClass","enable","removeAttr","disable","change","proxy","destroy","remove","removeData","unwrap","old","fn","bootstrapToggle","Constructor","noConflict","document","e","$checkbox","find","preventDefault","jQuery"],"mappings":";;;;;;;CASE,SAAUA,GACV,YAoID,SAASC,GAAOC,GACf,MAAOC,MAAKC,KAAK,WAChB,GAAIC,GAAUL,EAAEG,MACZG,EAAUD,EAAMC,KAAK,aACrBC,EAA2B,gBAAVL,IAAsBA,CAEtCI,IAAMD,EAAMC,KAAK,YAAcA,EAAO,GAAIE,GAAOL,KAAMI,IACvC,gBAAVL,IAAsBI,EAAKJ,IAASI,EAAKJ,OAtItD,GAAIM,GAAS,SAAUC,EAASF,GAC/BJ,KAAKO,SAAYV,EAAES,GACnBN,KAAKI,QAAYP,EAAEW,UAAWR,KAAKS,WAAYL,GAC/CJ,KAAKU,SAGNL,GAAOM,QAAW,QAElBN,EAAOO,UACNC,GAAI,KACJC,IAAK,MACLC,QAAS,UACTC,SAAU,UACVC,KAAM,SACNC,MAAO,GACPC,MAAO,KACPC,OAAQ,MAGTf,EAAOgB,UAAUZ,SAAW,WAC3B,OACCI,GAAIb,KAAKO,SAASe,KAAK,YAAcjB,EAAOO,SAASC,GACrDC,IAAKd,KAAKO,SAASe,KAAK,aAAejB,EAAOO,SAASE,IACvDC,QAASf,KAAKO,SAASe,KAAK,iBAAmBjB,EAAOO,SAASG,QAC/DC,SAAUhB,KAAKO,SAASe,KAAK,kBAAoBjB,EAAOO,SAASI,SACjEC,KAAMjB,KAAKO,SAASe,KAAK,cAAgBjB,EAAOO,SAASK,KACzDC,MAAOlB,KAAKO,SAASe,KAAK,eAAiBjB,EAAOO,SAASM,MAC3DC,MAAOnB,KAAKO,SAASe,KAAK,eAAiBjB,EAAOO,SAASO,MAC3DC,OAAQpB,KAAKO,SAASe,KAAK,gBAAkBjB,EAAOO,SAASQ,SAI/Df,EAAOgB,UAAUX,OAAS,WACzBV,KAAKuB,SAAW,OAASvB,KAAKI,QAAQW,QACtCf,KAAKwB,UAAY,OAASxB,KAAKI,QAAQY,QACvC,IAAIC,GAA6B,UAAtBjB,KAAKI,QAAQa,KAAmB,YAClB,UAAtBjB,KAAKI,QAAQa,KAAmB,YACV,SAAtBjB,KAAKI,QAAQa,KAAkB,WAC/B,GACCQ,EAAY5B,EAAE,uBAAuB6B,KAAK1B,KAAKI,QAAQS,IACzDc,SAAS3B,KAAKuB,SAAW,IAAMN,GAC7BW,EAAa/B,EAAE,uBAAuB6B,KAAK1B,KAAKI,QAAQU,KAC1Da,SAAS3B,KAAKwB,UAAY,IAAMP,EAAO,WACrCY,EAAgBhC,EAAE,gDACpB8B,SAASV,GACPa,EAAejC,EAAE,8BACnBkC,OAAON,EAAWG,EAAYC,GAC5BG,EAAUnC,EAAE,iDACd8B,SAAU3B,KAAKO,SAAS0B,KAAK,WAAajC,KAAKuB,SAAWvB,KAAKwB,UAAU,QACzEG,SAASV,GAAMU,SAAS3B,KAAKI,QAAQc,MAEvClB,MAAKO,SAAS2B,KAAKF,GACnBnC,EAAEW,OAAOR,MACRgC,QAAShC,KAAKO,SAAS4B,SACvBV,UAAWA,EACXG,WAAYA,EACZE,aAAcA,IAEf9B,KAAKgC,QAAQD,OAAOD,EAEpB,IAAIX,GAAQnB,KAAKI,QAAQe,OAASiB,KAAKC,IAAIZ,EAAUN,QAASS,EAAWT,SAAUU,EAAcS,aAAa,EAC1GlB,EAASpB,KAAKI,QAAQgB,QAAUgB,KAAKC,IAAIZ,EAAUL,SAAUQ,EAAWR,SAC5EK,GAAUE,SAAS,aACnBC,EAAWD,SAAS,cACpB3B,KAAKgC,QAAQO,KAAMpB,MAAOA,EAAOC,OAAQA,IACrCpB,KAAKI,QAAQgB,SAChBK,EAAUc,IAAI,cAAed,EAAUL,SAAW,MAClDQ,EAAWW,IAAI,cAAeX,EAAWR,SAAW,OAErDpB,KAAKwC,QAAO,GACZxC,KAAKyC,SAAQ,IAGdpC,EAAOgB,UAAUqB,OAAS,WACrB1C,KAAKO,SAAS0B,KAAK,WAAYjC,KAAKc,MACnCd,KAAKa,MAGXR,EAAOgB,UAAUR,GAAK,SAAU8B,GAC/B,MAAI3C,MAAKO,SAAS0B,KAAK,aAAoB,GAC3CjC,KAAKgC,QAAQY,YAAY5C,KAAKwB,UAAY,QAAQG,SAAS3B,KAAKuB,UAChEvB,KAAKO,SAAS0B,KAAK,WAAW,QACzBU,GAAQ3C,KAAKyC,aAGnBpC,EAAOgB,UAAUP,IAAM,SAAU6B,GAChC,MAAI3C,MAAKO,SAAS0B,KAAK,aAAoB,GAC3CjC,KAAKgC,QAAQY,YAAY5C,KAAKuB,UAAUI,SAAS3B,KAAKwB,UAAY,QAClExB,KAAKO,SAAS0B,KAAK,WAAW,QACzBU,GAAQ3C,KAAKyC,aAGnBpC,EAAOgB,UAAUwB,OAAS,WACzB7C,KAAKgC,QAAQc,WAAW,YACxB9C,KAAKO,SAAS0B,KAAK,YAAY,IAGhC5B,EAAOgB,UAAU0B,QAAU,WAC1B/C,KAAKgC,QAAQV,KAAK,WAAY,YAC9BtB,KAAKO,SAAS0B,KAAK,YAAY,IAGhC5B,EAAOgB,UAAUmB,OAAS,SAAUG,GAC/B3C,KAAKO,SAAS0B,KAAK,YAAajC,KAAK+C,UACpC/C,KAAK6C,SACN7C,KAAKO,SAAS0B,KAAK,WAAYjC,KAAKa,GAAG8B,GACtC3C,KAAKc,IAAI6B,IAGftC,EAAOgB,UAAUoB,QAAU,SAAUE,GACpC3C,KAAKO,SAASO,IAAI,oBACb6B,GAAQ3C,KAAKO,SAASyC,SAC3BhD,KAAKO,SAASM,GAAG,mBAAoBhB,EAAEoD,MAAM,WAC5CjD,KAAKwC,UACHxC,QAGJK,EAAOgB,UAAU6B,QAAU,WAC1BlD,KAAKO,SAASO,IAAI,oBAClBd,KAAK8B,aAAaqB,SAClBnD,KAAKO,SAAS6C,WAAW,aACzBpD,KAAKO,SAAS8C,SAiBf,IAAIC,GAAMzD,EAAE0D,GAAGC,eAEf3D,GAAE0D,GAAGC,gBAA8B1D,EACnCD,EAAE0D,GAAGC,gBAAgBC,YAAcpD,EAKnCR,EAAE0D,GAAGb,OAAOgB,WAAa,WAExB,MADA7D,GAAE0D,GAAGC,gBAAkBF,EAChBtD,MAMRH,EAAE,WACDA,EAAE,6CAA6C2D,oBAGhD3D,EAAE8D,UAAU9C,GAAG,kBAAmB,2BAA4B,SAAS+C,GACtE,GAAIC,GAAYhE,EAAEG,MAAM8D,KAAK,uBAC7BD,GAAUL,gBAAgB,UAC1BI,EAAEG,oBAGFC"}
|
|
@ -1,2 +0,0 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -1,2 +0,0 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -1,2 +0,0 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -1,2 +0,0 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -1,2 +0,0 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -8,7 +8,6 @@
|
|||
@import "jquery.mloading";
|
||||
@import "jquery-confirm.min";
|
||||
@import "bootstrap-datetimepicker.min";
|
||||
@import "bootstrap/bootstrap-toggle.min";
|
||||
|
||||
@import "codemirror/lib/codemirror";
|
||||
@import "editormd/css/editormd.min";
|
||||
|
@ -59,159 +58,3 @@ input.form-control {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
.table th, .table td {
|
||||
padding: 0.75rem 0.1rem;
|
||||
vertical-align: top;
|
||||
border-top: 1px solid #dee2e6;
|
||||
}
|
||||
|
||||
.table .thead-light th{
|
||||
white-space: nowrap;
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
// 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/
|
|
@ -1,83 +0,0 @@
|
|||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap-toggle.css v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
|
||||
|
||||
.checkbox label .toggle,
|
||||
.checkbox-inline .toggle {
|
||||
margin-left: -20px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.toggle {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
.toggle input[type="checkbox"] {
|
||||
display: none;
|
||||
}
|
||||
.toggle-group {
|
||||
position: absolute;
|
||||
width: 200%;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
transition: left 0.35s;
|
||||
-webkit-transition: left 0.35s;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
.toggle.off .toggle-group {
|
||||
left: -100%;
|
||||
}
|
||||
.toggle-on {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 50%;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
.toggle-off {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
.toggle-handle {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
height: 100%;
|
||||
width: 0px;
|
||||
border-width: 0 1px;
|
||||
}
|
||||
|
||||
.toggle.btn { min-width: 59px; min-height: 34px; }
|
||||
.toggle-on.btn { padding-right: 24px; }
|
||||
.toggle-off.btn { padding-left: 24px; }
|
||||
|
||||
.toggle.btn-lg { min-width: 79px; min-height: 45px; }
|
||||
.toggle-on.btn-lg { padding-right: 31px; }
|
||||
.toggle-off.btn-lg { padding-left: 31px; }
|
||||
.toggle-handle.btn-lg { width: 40px; }
|
||||
|
||||
.toggle.btn-sm { min-width: 50px; min-height: 30px;}
|
||||
.toggle-on.btn-sm { padding-right: 20px; }
|
||||
.toggle-off.btn-sm { padding-left: 20px; }
|
||||
|
||||
.toggle.btn-xs { min-width: 35px; min-height: 22px;}
|
||||
.toggle-on.btn-xs { padding-right: 12px; }
|
||||
.toggle-off.btn-xs { padding-left: 12px; }
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap-toggle.css v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
.checkbox label .toggle,.checkbox-inline .toggle{margin-left:-20px;margin-right:5px}
|
||||
.toggle{position:relative;overflow:hidden}
|
||||
.toggle input[type=checkbox]{display:none}
|
||||
.toggle-group{position:absolute;width:200%;top:0;bottom:0;left:0;transition:left .35s;-webkit-transition:left .35s;-moz-user-select:none;-webkit-user-select:none}
|
||||
.toggle.off .toggle-group{left:-100%}
|
||||
.toggle-on{position:absolute;top:0;bottom:0;left:0;right:50%;margin:0;border:0;border-radius:0}
|
||||
.toggle-off{position:absolute;top:0;bottom:0;left:50%;right:0;margin:0;border:0;border-radius:0}
|
||||
.toggle-handle{position:relative;margin:0 auto;padding-top:0;padding-bottom:0;height:100%;width:0;border-width:0 1px}
|
||||
.toggle.btn{min-width:59px;min-height:34px}
|
||||
.toggle-on.btn{padding-right:24px}
|
||||
.toggle-off.btn{padding-left:24px}
|
||||
.toggle.btn-lg{min-width:79px;min-height:45px}
|
||||
.toggle-on.btn-lg{padding-right:31px}
|
||||
.toggle-off.btn-lg{padding-left:31px}
|
||||
.toggle-handle.btn-lg{width:40px}
|
||||
.toggle.btn-sm{min-width:50px;min-height:30px}
|
||||
.toggle-on.btn-sm{padding-right:20px}
|
||||
.toggle-off.btn-sm{padding-left:20px}
|
||||
.toggle.btn-xs{min-width:35px;min-height:22px}
|
||||
.toggle-on.btn-xs{padding-right:12px}
|
||||
.toggle-off.btn-xs{padding-left:12px}
|
|
@ -1,85 +0,0 @@
|
|||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap2-toggle.css v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
|
||||
|
||||
label.checkbox .toggle,
|
||||
label.checkbox.inline .toggle {
|
||||
margin-left: -20px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
.toggle {
|
||||
min-width: 40px;
|
||||
height: 20px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
.toggle input[type="checkbox"] {
|
||||
display: none;
|
||||
}
|
||||
.toggle-group {
|
||||
position: absolute;
|
||||
width: 200%;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
transition: left 0.35s;
|
||||
-webkit-transition: left 0.35s;
|
||||
-moz-user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
.toggle.off .toggle-group {
|
||||
left: -100%;
|
||||
}
|
||||
.toggle-on {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 50%;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
.toggle-off {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 50%;
|
||||
right: 0;
|
||||
margin: 0;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
}
|
||||
.toggle-handle {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
height: 100%;
|
||||
width: 0px;
|
||||
border-width: 0 1px;
|
||||
}
|
||||
.toggle-handle.btn-mini {
|
||||
top: -1px;
|
||||
}
|
||||
.toggle.btn { min-width: 30px; }
|
||||
.toggle-on.btn { padding-right: 24px; }
|
||||
.toggle-off.btn { padding-left: 24px; }
|
||||
|
||||
.toggle.btn-large { min-width: 40px; }
|
||||
.toggle-on.btn-large { padding-right: 35px; }
|
||||
.toggle-off.btn-large { padding-left: 35px; }
|
||||
|
||||
.toggle.btn-small { min-width: 25px; }
|
||||
.toggle-on.btn-small { padding-right: 20px; }
|
||||
.toggle-off.btn-small { padding-left: 20px; }
|
||||
|
||||
.toggle.btn-mini { min-width: 20px; }
|
||||
.toggle-on.btn-mini { padding-right: 12px; }
|
||||
.toggle-off.btn-mini { padding-left: 12px; }
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/*! ========================================================================
|
||||
* Bootstrap Toggle: bootstrap2-toggle.css v2.2.0
|
||||
* http://www.bootstraptoggle.com
|
||||
* ========================================================================
|
||||
* Copyright 2014 Min Hur, The New York Times Company
|
||||
* Licensed under MIT
|
||||
* ======================================================================== */
|
||||
label.checkbox .toggle,label.checkbox.inline .toggle{margin-left:-20px;margin-right:5px}
|
||||
.toggle{min-width:40px;height:20px;position:relative;overflow:hidden}
|
||||
.toggle input[type=checkbox]{display:none}
|
||||
.toggle-group{position:absolute;width:200%;top:0;bottom:0;left:0;transition:left .35s;-webkit-transition:left .35s;-moz-user-select:none;-webkit-user-select:none}
|
||||
.toggle.off .toggle-group{left:-100%}
|
||||
.toggle-on{position:absolute;top:0;bottom:0;left:0;right:50%;margin:0;border:0;border-radius:0}
|
||||
.toggle-off{position:absolute;top:0;bottom:0;left:50%;right:0;margin:0;border:0;border-radius:0}
|
||||
.toggle-handle{position:relative;margin:0 auto;padding-top:0;padding-bottom:0;height:100%;width:0;border-width:0 1px}
|
||||
.toggle-handle.btn-mini{top:-1px}
|
||||
.toggle.btn{min-width:30px}
|
||||
.toggle-on.btn{padding-right:24px}
|
||||
.toggle-off.btn{padding-left:24px}
|
||||
.toggle.btn-large{min-width:40px}
|
||||
.toggle-on.btn-large{padding-right:35px}
|
||||
.toggle-off.btn-large{padding-left:35px}
|
||||
.toggle.btn-small{min-width:25px}
|
||||
.toggle-on.btn-small{padding-right:20px}
|
||||
.toggle-off.btn-small{padding-left:20px}
|
||||
.toggle.btn-mini{min-width:20px}
|
||||
.toggle-on.btn-mini{padding-right:12px}
|
||||
.toggle-off.btn-mini{padding-left:12px}
|
|
@ -1,3 +0,0 @@
|
|||
// 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,3 +0,0 @@
|
|||
// Place all the styles related to the log controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -1,84 +0,0 @@
|
|||
body {
|
||||
background-color: #fff;
|
||||
color: #333;
|
||||
margin: 33px;
|
||||
font-family: verdana, arial, helvetica, sans-serif;
|
||||
font-size: 13px;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
p, ol, ul, td {
|
||||
font-family: verdana, arial, helvetica, sans-serif;
|
||||
font-size: 13px;
|
||||
line-height: 18px;
|
||||
}
|
||||
|
||||
pre {
|
||||
background-color: #eee;
|
||||
padding: 10px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #000;
|
||||
|
||||
&:visited {
|
||||
color: #666;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
color: #fff;
|
||||
background-color: #000;
|
||||
}
|
||||
}
|
||||
|
||||
th {
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
||||
td {
|
||||
padding: 0 5px 7px;
|
||||
}
|
||||
|
||||
div {
|
||||
&.field, &.actions {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
#notice {
|
||||
color: green;
|
||||
}
|
||||
|
||||
.field_with_errors {
|
||||
padding: 2px;
|
||||
background-color: red;
|
||||
display: table;
|
||||
}
|
||||
|
||||
#error_explanation {
|
||||
width: 450px;
|
||||
border: 2px solid red;
|
||||
padding: 7px 7px 0;
|
||||
margin-bottom: 20px;
|
||||
background-color: #f0f0f0;
|
||||
|
||||
h2 {
|
||||
text-align: left;
|
||||
font-weight: bold;
|
||||
padding: 5px 5px 5px 15px;
|
||||
font-size: 12px;
|
||||
margin: -7px -7px 0;
|
||||
background-color: #c00;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
ul li {
|
||||
font-size: 12px;
|
||||
list-style: square;
|
||||
}
|
||||
}
|
||||
|
||||
label {
|
||||
display: block;
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
// Place all the styles related to the SponsorTiers controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -1,3 +0,0 @@
|
|||
// Place all the styles related to the Sponsorships controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -1,3 +0,0 @@
|
|||
// Place all the styles related to the Wallets controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -1,421 +1,349 @@
|
|||
class AccountsController < ApplicationController
|
||||
before_action :require_login, only: [:login_check, :simple_update]
|
||||
include ApplicationHelper
|
||||
|
||||
#skip_before_action :check_account, :only => [:logout]
|
||||
|
||||
def simple_update
|
||||
simple_update_params.merge!(username: params[:username]&.gsub(/\s+/, ""))
|
||||
simple_update_params.merge!(email: params[:email]&.gsub(/\s+/, ""))
|
||||
simple_update_params.merge!(platform: (params[:platform] || 'forge')&.gsub(/\s+/, ""))
|
||||
Register::RemoteForm.new(simple_update_params).validate!
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
result = auto_update(current_user, simple_update_params)
|
||||
if result[:message].blank?
|
||||
render_ok
|
||||
else
|
||||
render_error(result[:message])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
render json: session
|
||||
end
|
||||
|
||||
# 其他平台同步注册的用户
|
||||
def remote_register
|
||||
Register::RemoteForm.new(remote_register_params).validate!
|
||||
username = params[:username]&.gsub(/\s+/, "")
|
||||
tip_exception("无法使用以下关键词:#{username},请重新命名") if ReversedKeyword.check_exists?(username)
|
||||
email = params[:email]&.gsub(/\s+/, "")
|
||||
password = params[:password]
|
||||
platform = (params[:platform] || 'forge')&.gsub(/\s+/, "")
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
result = autologin_register(username, email, password, platform)
|
||||
if result[:message].blank?
|
||||
render_ok({user: result[:user]})
|
||||
else
|
||||
render_error(result[:message])
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(-1, e.message)
|
||||
end
|
||||
|
||||
# 其他平台修改用户的信息,这边同步修改
|
||||
def remote_update
|
||||
ActiveRecord::Base.transaction do
|
||||
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)
|
||||
|
||||
if u.present?
|
||||
ue = u.user_extension
|
||||
u.login = user_params["login"] if user_params["login"]
|
||||
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.location = user_extension_params["location"]
|
||||
ue.location_city = user_extension_params["location_city"]
|
||||
ue.identity = user_extension_params["identity"]
|
||||
ue.technical_title = user_extension_params["technical_title"]
|
||||
ue.student_id = user_extension_params["student_id"]
|
||||
ue.description = user_extension_params["description"]
|
||||
ue.save!
|
||||
u.save!
|
||||
|
||||
sync_params = {}
|
||||
|
||||
if (user_params["mail"] && user_params["mail"] != user_mail)
|
||||
sync_params = sync_params.merge(email: user_params["mail"])
|
||||
end
|
||||
|
||||
if sync_params.present?
|
||||
interactor = Gitea::User::UpdateInteractor.call(u.login, sync_params)
|
||||
if interactor.success?
|
||||
render_ok
|
||||
else
|
||||
render_error(interactor.error)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(-1, e.message)
|
||||
end
|
||||
|
||||
# 其他平台同步登录
|
||||
def remote_login
|
||||
@user = User.try_to_login(params[:login], params[:password])
|
||||
if @user
|
||||
successful_authentication(@user)
|
||||
render_ok({user: {id: @user.id, token: @user.gitea_token}})
|
||||
else
|
||||
render_error("用户不存在")
|
||||
end
|
||||
end
|
||||
|
||||
#修改密码
|
||||
def remote_password
|
||||
@user = User.find_by(login: params[:login])
|
||||
return render_error("未找到相关用户!") if @user.blank?
|
||||
|
||||
sync_params = {
|
||||
password: params[:password].to_s,
|
||||
email: @user.mail,
|
||||
login_name: @user.login,
|
||||
source_id: 0
|
||||
}
|
||||
|
||||
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
||||
if interactor.success?
|
||||
@user.update_attribute(:password, params[:password])
|
||||
render_ok
|
||||
else
|
||||
render_error(interactor.error)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
# 用户注册
|
||||
# 注意:用户注册需要兼顾本地版,本地版是不需要验证码及激活码以及使用授权的,注册完成即可使用
|
||||
# params[:login] 邮箱或者手机号
|
||||
# params[:namespace] 登录名
|
||||
# params[:code] 验证码
|
||||
# code_type 1:注册手机验证码 8:邮箱注册验证码
|
||||
# 本地forge注册入口需要重新更改逻辑
|
||||
def register
|
||||
# type只可能是1或者8
|
||||
user = nil
|
||||
begin
|
||||
Register::Form.new(register_params).validate!
|
||||
|
||||
user = Users::RegisterService.call(register_params)
|
||||
user.mail = "#{user.login}@example.org" if user.mail.blank?
|
||||
password = register_params[:password].strip
|
||||
|
||||
# gitea用户注册, email, username, password
|
||||
interactor = Gitea::RegisterInteractor.call({username: user.login, email: user.mail, password: password})
|
||||
if interactor.success?
|
||||
gitea_user = interactor.result
|
||||
result = Gitea::User::GenerateTokenService.call(user.login, password)
|
||||
user.gitea_token = result['sha1']
|
||||
user.gitea_uid = gitea_user[:body]['id']
|
||||
if user.save!
|
||||
UserExtension.create!(user_id: user.id)
|
||||
# 绑定授权账号
|
||||
if ["qq", "wechat", "gitee", "github", "educoder"].include?(params[:type].to_s) && session[:unionid].present?
|
||||
"OpenUsers::#{params[:type].to_s.capitalize}".constantize.create!(user: user, uid: session[:unionid])
|
||||
end
|
||||
successful_authentication(user)
|
||||
render_ok
|
||||
end
|
||||
else
|
||||
tip_exception(-1, interactor.error)
|
||||
end
|
||||
rescue Register::BaseForm::EmailError => e
|
||||
render_result(-2, e.message)
|
||||
rescue Register::BaseForm::LoginError => e
|
||||
render_result(-3, e.message)
|
||||
rescue Register::BaseForm::PhoneError => e
|
||||
render_result(-4, e.message)
|
||||
rescue Register::BaseForm::PasswordFormatError => e
|
||||
render_result(-5, e.message)
|
||||
rescue Register::BaseForm::PasswordConfirmationError => e
|
||||
render_result(-7, e.message)
|
||||
rescue Register::BaseForm::VerifiCodeError => e
|
||||
render_result(-6, e.message)
|
||||
rescue Exception => e
|
||||
Gitea::User::DeleteService.call(user.login) unless user.nil?
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(-1, e.message)
|
||||
end
|
||||
end
|
||||
|
||||
# 用户登录
|
||||
def login
|
||||
Users::LoginForm.new(login_params).validate!
|
||||
@user = User.try_to_login(params[:login], params[:password])
|
||||
|
||||
return normal_status(-2, "错误的账号或密码") if @user.blank?
|
||||
# user is already in local database
|
||||
return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked?
|
||||
|
||||
login_control = LimitForbidControl::UserLogin.new(@user)
|
||||
return normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码") if login_control.forbid?
|
||||
|
||||
password_ok = @user.check_password?(params[:password].to_s)
|
||||
unless password_ok
|
||||
if login_control.remain_times-1 == 0
|
||||
normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码")
|
||||
else
|
||||
normal_status(-2, "你已经输错密码#{login_control.error_times+1}次,还剩余#{login_control.remain_times-1}次机会")
|
||||
end
|
||||
login_control.increment!
|
||||
return
|
||||
end
|
||||
|
||||
successful_authentication(@user)
|
||||
sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步
|
||||
|
||||
# session[:user_id] = @user.id
|
||||
end
|
||||
|
||||
def change_password
|
||||
@user = User.find_by(login: params[:login])
|
||||
return render_error("未找到相关用户!") if @user.blank?
|
||||
return render_error("旧密码不正确") unless @user.check_password?(params[:old_password])
|
||||
|
||||
sync_params = {
|
||||
password: params[:password].to_s,
|
||||
email: @user.mail,
|
||||
login_name: @user.name,
|
||||
source_id: 0
|
||||
}
|
||||
|
||||
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
||||
if interactor.success?
|
||||
@user.update_attribute(:password, params[:password])
|
||||
render_ok
|
||||
else
|
||||
render_error(interactor.error)
|
||||
end
|
||||
end
|
||||
|
||||
# 忘记密码
|
||||
def reset_password
|
||||
begin
|
||||
Accounts::ResetPasswordForm.new(reset_password_params).validate!
|
||||
|
||||
user = find_user
|
||||
return render_error('未找到相关账号') if user.blank?
|
||||
|
||||
user = Accounts::ResetPasswordService.call(user, reset_password_params)
|
||||
LimitForbidControl::UserLogin.new(user).clear if user.save!
|
||||
|
||||
render_ok
|
||||
rescue Register::BaseForm::EmailError => e
|
||||
render_result(-2, e.message)
|
||||
rescue Register::BaseForm::PhoneError => e
|
||||
render_result(-4, e.message)
|
||||
rescue Register::BaseForm::PasswordFormatError => e
|
||||
render_result(-5, e.message)
|
||||
rescue Register::BaseForm::PasswordConfirmationError => e
|
||||
render_result(-7, e.message)
|
||||
rescue Register::BaseForm::VerifiCodeError => e
|
||||
render_result(-6, e.message)
|
||||
rescue ActiveRecord::Rollback => e
|
||||
render_result(-1, "服务器异常")
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
end
|
||||
|
||||
def successful_authentication(user)
|
||||
uid_logger("Successful authentication start: '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}")
|
||||
# Valid user
|
||||
self.logged_user = user
|
||||
# generate a key and set cookie if autologin
|
||||
|
||||
set_autologin_cookie(user)
|
||||
UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id), :ip => request.remote_ip)
|
||||
# user.daily_reward
|
||||
user.update_column(:last_login_on, Time.now)
|
||||
session[:"#{default_yun_session}"] = user.id
|
||||
Rails.logger.info("#########_____session_default_yun_session__________###############{default_yun_session}")
|
||||
# 注册完成后有一天的试用申请(先去掉)
|
||||
# UserDayCertification.create(user_id: user.id, status: 1)
|
||||
end
|
||||
|
||||
def set_autologin_cookie(user)
|
||||
token = Token.get_or_create_permanent_login_token(user, "autologin")
|
||||
# sync_user_token_to_trustie(user.login, token.value)
|
||||
|
||||
cookie_options = {
|
||||
:value => token.value,
|
||||
:expires => 1.month.from_now,
|
||||
:path => '/',
|
||||
:secure => false,
|
||||
:httponly => true
|
||||
}
|
||||
if edu_setting('cookie_domain').present?
|
||||
cookie_options = cookie_options.merge(domain: edu_setting('cookie_domain'))
|
||||
end
|
||||
cookies[autologin_cookie_name] = cookie_options
|
||||
cookies.signed[:user_id] ||= user.id
|
||||
|
||||
logger.info("cookies is #{cookies} ======> #{cookies.signed[:user_id]} =====> #{cookies[autologin_cookie_name]}")
|
||||
end
|
||||
|
||||
def logout
|
||||
Rails.logger.info("########___logout_current_user____________########{current_user.try(:id)}")
|
||||
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: "退出成功!"}
|
||||
end
|
||||
|
||||
# 检验邮箱是否已被注册及邮箱或者手机号是否合法
|
||||
# 参数type为事件类型 1:注册;2:忘记密码;3:绑定
|
||||
def valid_email_and_phone
|
||||
check_mail_and_phone_valid(params[:login], params[:type])
|
||||
end
|
||||
|
||||
# 发送验证码
|
||||
# params[:login] 手机号或者邮箱号
|
||||
# params[:type]为事件通知类型 1:用户注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验收手机号有效 # 如果有新的继续后面加
|
||||
# 发送验证码:send_type 1:注册手机验证码 2:找回密码手机验证码 3:找回密码邮箱验证码 4:绑定手机 5:绑定邮箱
|
||||
# 6:手机验证码登录 7:邮箱验证码登录 8:邮箱注册验证码 9: 验收手机号有效
|
||||
def get_verification_code
|
||||
code = %W(0 1 2 3 4 5 6 7 8 9)
|
||||
value = params[:login]
|
||||
type = params[:type].strip.to_i
|
||||
login_type = phone_mail_type(value)
|
||||
send_type = verify_type(login_type, type)
|
||||
verification_code = code.sample(6).join
|
||||
|
||||
sign = Digest::MD5.hexdigest("#{OPENKEY}#{value}")
|
||||
tip_exception(501, "请求不合理") if sign != params[:smscode]
|
||||
|
||||
logger.info "########### 验证码:#{verification_code}"
|
||||
logger.info("########get_verification_code: login_type: #{login_type}, send_type:#{send_type}, ")
|
||||
|
||||
# 记录验证码
|
||||
check_verification_code(verification_code, send_type, value)
|
||||
render_ok
|
||||
end
|
||||
|
||||
# check user's login or email or phone is used
|
||||
# params[:value] 手机号或者邮箱号或者登录名
|
||||
# params[:type] 为事件类型 1:登录名(login) 2:email(邮箱) 3:phone(手机号)
|
||||
def check
|
||||
Register::CheckColumnsForm.new(check_params).validate!
|
||||
render_ok
|
||||
end
|
||||
|
||||
def login_check
|
||||
Register::LoginCheckColumnsForm.new(check_params.merge(user: current_user)).validate!
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# type 事件类型 1:用户注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验证手机号是否有效 # 如果有新的继续后面加
|
||||
# login_type 1:手机类型 2:邮箱类型
|
||||
def verify_type login_type, type
|
||||
case type
|
||||
when 1
|
||||
login_type == 1 ? 1 : 8
|
||||
when 2
|
||||
login_type == 1 ? 2 : 3
|
||||
when 3
|
||||
login_type == 1 ? 4 : tip_exception('请填写正确的手机号')
|
||||
when 4
|
||||
login_type == 1 ? tip_exception('请填写正确的邮箱') : 5
|
||||
when 5
|
||||
login_type == 1 ? 9 : tip_exception('请填写正确的手机号')
|
||||
end
|
||||
end
|
||||
|
||||
def generate_login(login)
|
||||
type = phone_mail_type(login.strip)
|
||||
|
||||
if type == 1
|
||||
uid_logger("start register by phone: type is #{type}")
|
||||
pre = 'p'
|
||||
email = nil
|
||||
phone = login
|
||||
else
|
||||
uid_logger("start register by email: type is #{type}")
|
||||
pre = 'm'
|
||||
email = login
|
||||
phone = nil
|
||||
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, :type)
|
||||
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
|
||||
|
||||
def simple_update_params
|
||||
params.permit(:username, :email, :password, :platform)
|
||||
end
|
||||
end
|
||||
class AccountsController < ApplicationController
|
||||
|
||||
#skip_before_action :check_account, :only => [:logout]
|
||||
|
||||
def index
|
||||
render json: session
|
||||
end
|
||||
|
||||
# 其他平台同步注册的用户
|
||||
def remote_register
|
||||
username = params[:username]&.gsub(/\s+/, "")
|
||||
email = params[:email]&.gsub(/\s+/, "")
|
||||
password = params[:password]
|
||||
platform = (params[:platform] || 'forge')&.gsub(/\s+/, "")
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
result = autologin_register(username, email, password, platform)
|
||||
if result[:message].blank?
|
||||
render_ok({user: result[:user]})
|
||||
else
|
||||
render_error(result[:message])
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(-1, e.message)
|
||||
end
|
||||
|
||||
# 其他平台修改用户的信息,这边同步修改
|
||||
def remote_update
|
||||
ActiveRecord::Base.transaction do
|
||||
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)
|
||||
|
||||
if u.present?
|
||||
ue = u.user_extension
|
||||
u.login = user_params["login"] if user_params["login"]
|
||||
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.location = user_extension_params["location"]
|
||||
ue.location_city = user_extension_params["location_city"]
|
||||
ue.identity = user_extension_params["identity"]
|
||||
ue.technical_title = user_extension_params["technical_title"]
|
||||
ue.student_id = user_extension_params["student_id"]
|
||||
ue.description = user_extension_params["description"]
|
||||
ue.save!
|
||||
u.save!
|
||||
|
||||
sync_params = {}
|
||||
|
||||
if (user_params["mail"] && user_params["mail"] != user_mail)
|
||||
sync_params = sync_params.merge(email: user_params["mail"])
|
||||
end
|
||||
|
||||
if sync_params.present?
|
||||
interactor = Gitea::User::UpdateInteractor.call(u.login, sync_params)
|
||||
if interactor.success?
|
||||
render_ok
|
||||
else
|
||||
render_error(interactor.error)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(-1, e.message)
|
||||
end
|
||||
|
||||
# 其他平台同步登录
|
||||
def remote_login
|
||||
@user = User.try_to_login(params[:login], params[:password])
|
||||
if @user
|
||||
successful_authentication(@user)
|
||||
render_ok({user: {id: @user.id, token: @user.gitea_token}})
|
||||
else
|
||||
render_error("用户不存在")
|
||||
end
|
||||
end
|
||||
|
||||
#修改密码
|
||||
def remote_password
|
||||
@user = User.find_by(login: params[:login])
|
||||
return render_error("未找到相关用户!") if @user.blank?
|
||||
|
||||
sync_params = {
|
||||
password: params[:password].to_s,
|
||||
email: @user.mail
|
||||
}
|
||||
|
||||
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
||||
if interactor.success?
|
||||
@user.update_attribute(:password, params[:password])
|
||||
render_ok
|
||||
else
|
||||
render_error(interactor.error)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
# 用户注册
|
||||
# 注意:用户注册需要兼顾本地版,本地版是不需要验证码及激活码以及使用授权的,注册完成即可使用
|
||||
# params[:login] 邮箱或者手机号
|
||||
# params[:code] 验证码
|
||||
# code_type 1:注册手机验证码 8:邮箱注册验证码
|
||||
def register
|
||||
begin
|
||||
# 查询验证码是否正确;type只可能是1或者8
|
||||
type = phone_mail_type(params[:login].strip)
|
||||
code = params[:code].strip
|
||||
|
||||
if type == 1
|
||||
uid_logger("start register by phone: type is #{type}")
|
||||
pre = 'p'
|
||||
email = nil
|
||||
phone = params[:login]
|
||||
verifi_code = VerificationCode.where(phone: phone, code: code, code_type: 1).last
|
||||
else
|
||||
uid_logger("start register by email: type is #{type}")
|
||||
pre = 'm'
|
||||
email = params[:login]
|
||||
phone = nil
|
||||
verifi_code = VerificationCode.where(email: email, code: code, code_type: 8).last
|
||||
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}")
|
||||
# check_code = (verifi_code.try(:code) == code.strip && (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60)
|
||||
# todo 上线前请删除万能验证码"513231"
|
||||
unless code == "513231" && request.subdomain == "test-newweb"
|
||||
return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
|
||||
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
|
||||
end
|
||||
|
||||
return normal_status(-1, "8~16位密码,支持字母数字和符号") unless params[:password] =~ CustomRegexp::PASSWORD
|
||||
|
||||
code = generate_identifier User, 8, pre
|
||||
login = pre + code
|
||||
@user = User.new(admin: false, login: login, mail: email, phone: phone, type: "User")
|
||||
@user.password = params[:password]
|
||||
# 现在因为是验证码,所以在注册的时候就可以激活
|
||||
@user.activate
|
||||
# 必须要用save操作,密码的保存是在users中
|
||||
if @user.save!
|
||||
# todo user_extension
|
||||
UserExtension.create!(user_id: @user.id)
|
||||
# 注册完成,手机号或邮箱想可以奖励500金币
|
||||
# RewardGradeService.call(
|
||||
# @user,
|
||||
# container_id: @user.id,
|
||||
# container_type: pre == 'p' ? 'Phone' : 'Mail',
|
||||
# score: 500
|
||||
# )
|
||||
# 注册时,记录是否是引流用户
|
||||
ip = request.remote_ip
|
||||
ua = UserAgent.find_by_ip(ip)
|
||||
ua.update_column(:agent_type, UserAgent::USER_REGISTER) if ua
|
||||
successful_authentication(@user)
|
||||
# session[:user_id] = @user.id
|
||||
normal_status("注册成功")
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(-1, e.message)
|
||||
end
|
||||
end
|
||||
|
||||
# 用户登录
|
||||
def login
|
||||
@user = User.try_to_login(params[:login], params[:password])
|
||||
|
||||
return normal_status(-2, "错误的账号或密码") if @user.blank?
|
||||
# user is already in local database
|
||||
return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked?
|
||||
|
||||
login_control = LimitForbidControl::UserLogin.new(@user)
|
||||
return normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码") if login_control.forbid?
|
||||
|
||||
password_ok = @user.check_password?(params[:password].to_s)
|
||||
unless password_ok
|
||||
if login_control.remain_times-1 == 0
|
||||
normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码")
|
||||
else
|
||||
normal_status(-2, "你已经输错密码#{login_control.error_times+1}次,还剩余#{login_control.remain_times-1}次机会")
|
||||
end
|
||||
login_control.increment!
|
||||
return
|
||||
end
|
||||
|
||||
successful_authentication(@user)
|
||||
sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步
|
||||
|
||||
# session[:user_id] = @user.id
|
||||
end
|
||||
|
||||
# 忘记密码
|
||||
def reset_password
|
||||
begin
|
||||
code = params[:code]
|
||||
login_type = phone_mail_type(params[:login].strip)
|
||||
# 获取验证码
|
||||
if login_type == 1
|
||||
phone = params[:login]
|
||||
verifi_code = VerificationCode.where(phone: phone, code: code, code_type: 2).last
|
||||
user = User.find_by_phone(phone)
|
||||
else
|
||||
email = params[:login]
|
||||
verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last
|
||||
user = User.find_by_mail(email) #这里有问题,应该是为email,而不是mail 6.13-hs
|
||||
end
|
||||
return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
|
||||
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
|
||||
return normal_status(-1, "8~16位密码,支持字母数字和符号") unless params[:new_password] =~ CustomRegexp::PASSWORD
|
||||
|
||||
user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||||
ActiveRecord::Base.transaction do
|
||||
user.save!
|
||||
LimitForbidControl::UserLogin.new(user).clear
|
||||
end
|
||||
sucess_status
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
end
|
||||
|
||||
def successful_authentication(user)
|
||||
uid_logger("Successful authentication start: '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}")
|
||||
# Valid user
|
||||
self.logged_user = user
|
||||
# generate a key and set cookie if autologin
|
||||
|
||||
set_autologin_cookie(user)
|
||||
UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id), :ip => request.remote_ip)
|
||||
user.update_column(:last_login_on, Time.now)
|
||||
session[:"#{default_yun_session}"] = user.id
|
||||
Rails.logger.info("#########_____session_default_yun_session__________###############{default_yun_session}")
|
||||
# 注册完成后有一天的试用申请(先去掉)
|
||||
# UserDayCertification.create(user_id: user.id, status: 1)
|
||||
end
|
||||
|
||||
def set_autologin_cookie(user)
|
||||
token = Token.get_or_create_permanent_login_token(user, autologin_cookie_name)
|
||||
cookie_options = {
|
||||
:value => token.value,
|
||||
:expires => 1.month.from_now,
|
||||
:path => '/',
|
||||
:secure => false,
|
||||
:httponly => true
|
||||
}
|
||||
if edu_setting('cookie_domain').present?
|
||||
cookie_options = cookie_options.merge(domain: edu_setting('cookie_domain'))
|
||||
end
|
||||
cookies[autologin_cookie_name] = cookie_options
|
||||
cookies.signed[:user_id] ||= user.id
|
||||
|
||||
logger.info("cookies is #{cookies} ======> #{cookies.signed[:user_id]} =====> #{cookies[autologin_cookie_name]}")
|
||||
end
|
||||
|
||||
def logout
|
||||
Rails.logger.info("########___logout_current_user____________########{current_user.try(:id)}")
|
||||
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: "退出成功!"}
|
||||
end
|
||||
|
||||
# 检验邮箱是否已被注册及邮箱或者手机号是否合法
|
||||
# 参数type为事件类型 1:注册;2:忘记密码;3:绑定
|
||||
def valid_email_and_phone
|
||||
check_mail_and_phone_valid(params[:login], params[:type])
|
||||
end
|
||||
|
||||
# 发送验证码
|
||||
# params[:login] 手机号或者邮箱号
|
||||
# params[:type]为事件通知类型 1:用户注册注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验收手机号有效 # 如果有新的继续后面加
|
||||
# 发送验证码:send_type 1:注册手机验证码 2:找回密码手机验证码 3:找回密码邮箱验证码 4:绑定手机 5:绑定邮箱
|
||||
# 6:手机验证码登录 7:邮箱验证码登录 8:邮箱注册验证码 9: 验收手机号有效
|
||||
def get_verification_code
|
||||
code = %W(0 1 2 3 4 5 6 7 8 9)
|
||||
value = params[:login]
|
||||
type = params[:type].strip.to_i
|
||||
login_type = phone_mail_type(value)
|
||||
send_type = verify_type(login_type, type)
|
||||
verification_code = code.sample(6).join
|
||||
|
||||
sign = Digest::MD5.hexdigest("#{OPENKEY}#{value}")
|
||||
tip_exception(501, "请求不合理") if sign != params[:smscode]
|
||||
|
||||
logger.info("########get_verification_code: login_type: #{login_type}, send_type:#{send_type}, ")
|
||||
|
||||
# 记录验证码
|
||||
check_verification_code(verification_code, send_type, value)
|
||||
sucess_status
|
||||
end
|
||||
|
||||
# 1 手机类型;0 邮箱类型
|
||||
# 注意新版的login是自动名生成的
|
||||
def phone_mail_type value
|
||||
value =~ /^1\d{10}$/ ? 1 : 0
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# type 事件类型 1:用户注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验证手机号是否有效 # 如果有新的继续后面加
|
||||
# login_type 1:手机类型 2:邮箱类型
|
||||
def verify_type login_type, type
|
||||
case type
|
||||
when 1
|
||||
login_type == 1 ? 1 : 8
|
||||
when 2
|
||||
login_type == 1 ? 2 : 3
|
||||
when 3
|
||||
login_type == 1 ? 4 : tip_exception('请填写正确的手机号')
|
||||
when 4
|
||||
login_type == 1 ? tip_exception('请填写正确的邮箱') : 5
|
||||
when 5
|
||||
login_type == 1 ? 9 : tip_exception('请填写正确的手机号')
|
||||
end
|
||||
end
|
||||
|
||||
def generate_login(login)
|
||||
type = phone_mail_type(login.strip)
|
||||
|
||||
if type == 1
|
||||
uid_logger("start register by phone: type is #{type}")
|
||||
pre = 'p'
|
||||
email = nil
|
||||
phone = login
|
||||
else
|
||||
uid_logger("start register by email: type is #{type}")
|
||||
pre = 'm'
|
||||
email = login
|
||||
phone = nil
|
||||
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
|
||||
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ class Admins::AuthSchoolsController < Admins::BaseController
|
|||
def search_manager
|
||||
school = School.find_by(id: params[:school_id])
|
||||
user_ids = school&.ec_school_users&.pluck(:user_id)
|
||||
@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)
|
||||
@users = User.where.not(id: user_ids).where("concat(lastname, firstname) like ?", "%#{params[:name].strip.to_s}%").limit(10)
|
||||
end
|
||||
|
||||
# 添加认证学校管理员
|
||||
|
|
|
@ -1,33 +1,10 @@
|
|||
class Admins::DashboardsController < Admins::BaseController
|
||||
def index
|
||||
# 用户活跃数
|
||||
day_user_ids = CommitLog.where(created_at: today).pluck(:user_id).uniq
|
||||
weekly_user_ids = CommitLog.where(created_at: current_week).pluck(:user_id).uniq
|
||||
month_user_ids = CommitLog.where(created_at: current_month).pluck(:user_id).uniq
|
||||
@active_user_count = User.where(last_login_on: today).or(User.where(id: day_user_ids)).count
|
||||
@weekly_active_user_count = User.where(last_login_on: current_week).or(User.where(id: weekly_user_ids)).count
|
||||
@month_active_user_count = User.where(last_login_on: current_month).or(User.where(id: month_user_ids)).count
|
||||
user_ids = User.where(created_on: pre_week).pluck(:id).uniq
|
||||
weekly_keep_user_count = User.where(id: user_ids).where(last_login_on: current_week).count
|
||||
@weekly_keep_rate = format("%.2f", user_ids.size > 0 ? weekly_keep_user_count.to_f / user_ids.size : 0)
|
||||
@active_user_count = User.where(last_login_on: today).count
|
||||
@weekly_active_user_count = User.where(last_login_on: current_week).count
|
||||
@month_active_user_count = User.where(last_login_on: current_month).count
|
||||
|
||||
# 新用户注册数
|
||||
@day_new_user_count = User.where(created_on: today).count
|
||||
@weekly_new_user_count = User.where(created_on: current_week).count
|
||||
@month_new_user_count = User.where(created_on: current_month).count
|
||||
|
||||
# 活跃项目数
|
||||
day_project_ids = (CommitLog.where(created_at: today).pluck(:project_id).uniq + Issue.where(created_on: today).pluck(:project_id).uniq).uniq
|
||||
weekly_project_ids = (CommitLog.where(created_at: current_week).pluck(:project_id).uniq + Issue.where(created_on: current_week).pluck(:project_id).uniq).uniq
|
||||
month_project_ids = (CommitLog.where(created_at: current_month).pluck(:project_id).uniq + Issue.where(created_on: current_month).pluck(:project_id).uniq).uniq
|
||||
@day_active_project_count = Project.where(updated_on: today).or(Project.where(id: day_project_ids)).count
|
||||
@weekly_active_project_count = Project.where(updated_on: current_week).or(Project.where(id: weekly_project_ids)).count
|
||||
@month_active_project_count = Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count
|
||||
|
||||
# 新增项目数
|
||||
@day_new_project_count = Project.where(created_on: today).count
|
||||
@weekly_new_project_count = Project.where(created_on: current_week).count
|
||||
@month_new_project_count = Project.where(created_on: current_month).count
|
||||
@new_user_count = User.where(created_on: current_month).count
|
||||
end
|
||||
|
||||
def month_active_user
|
||||
|
@ -39,6 +16,7 @@ class Admins::DashboardsController < Admins::BaseController
|
|||
{ value: count['professional'].to_i, name: '专业人士' },
|
||||
{ value: count[nil].to_i, name: '未选职业' },
|
||||
]
|
||||
|
||||
render_ok(data: data)
|
||||
end
|
||||
|
||||
|
@ -64,14 +42,10 @@ class Admins::DashboardsController < Admins::BaseController
|
|||
end
|
||||
|
||||
def current_week
|
||||
7.days.ago.end_of_day..Time.now.end_of_day
|
||||
7.days.ago.beginning_of_day..Time.now.end_of_day
|
||||
end
|
||||
|
||||
def current_month
|
||||
30.days.ago.end_of_day..Time.now.end_of_day
|
||||
end
|
||||
|
||||
def pre_week
|
||||
14.days.ago.end_of_day..7.days.ago.end_of_day
|
||||
30.days.ago.beginning_of_day..Time.now.end_of_day
|
||||
end
|
||||
end
|
|
@ -1,55 +0,0 @@
|
|||
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
|
|
@ -1,58 +0,0 @@
|
|||
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
|
|
@ -1,49 +0,0 @@
|
|||
class Admins::FeedbacksController < Admins::BaseController
|
||||
before_action :get_feedback, only: [:new_history, :create_history, :destroy]
|
||||
|
||||
def index
|
||||
sort_by = Feedback.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||
feedbacks = Feedback.order("#{sort_by} #{sort_direction}")
|
||||
@feedbacks = paginate(feedbacks)
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @feedback.destroy
|
||||
redirect_to admins_feedbacks_path
|
||||
flash[:success] = "反馈意见删除成功"
|
||||
else
|
||||
redirect_to admins_feedbacks_path
|
||||
flash[:danger] = "反馈意见删除失败"
|
||||
end
|
||||
end
|
||||
|
||||
def new_history
|
||||
@feedback_message_history = FeedbackMessageHistory.new
|
||||
end
|
||||
|
||||
def create_history
|
||||
@feedback_message_history = @feedback.feedback_message_histories.new(feedback_message_history_params)
|
||||
@feedback_message_history.user = current_user
|
||||
if @feedback_message_history.save
|
||||
redirect_to admins_feedbacks_path
|
||||
flash[:success] = "发送通知成功"
|
||||
else
|
||||
redirect_to admins_feedbacks_path
|
||||
flash[:danger] = @feedback_message_history.errors.full_messages.join(", ")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def feedback_params
|
||||
params.require(:feedback).permit!
|
||||
end
|
||||
|
||||
def feedback_message_history_params
|
||||
params.require(:feedback_message_history).permit(:title, :content)
|
||||
end
|
||||
|
||||
def get_feedback
|
||||
@feedback = Feedback.find_by_id(params[:id])
|
||||
end
|
||||
end
|
|
@ -2,7 +2,7 @@ class Admins::ImportUsersController < Admins::BaseController
|
|||
def create
|
||||
return render_error('请上传正确的文件') if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile)
|
||||
|
||||
result = Admins::ImportUserFromExcelService.call(params[:file].to_io)
|
||||
result = Admins::ImportUserService.call(params[:file].to_io)
|
||||
render_ok(result)
|
||||
rescue Admins::ImportUserService::Error => ex
|
||||
render_error(ex)
|
||||
|
|
|
@ -6,12 +6,6 @@ class Admins::LaboratoriesController < Admins::BaseController
|
|||
@laboratories = paginate laboratories.preload(:laboratory_users)
|
||||
end
|
||||
|
||||
def new
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
Admins::CreateLaboratoryService.call(create_params)
|
||||
render_ok
|
||||
|
@ -33,7 +27,7 @@ class Admins::LaboratoriesController < Admins::BaseController
|
|||
keyword = params[:keyword].to_s.strip
|
||||
if keyword.present?
|
||||
like_sql = 'shixuns.name LIKE :keyword OR CONCAT(users.lastname, users.firstname) LIKE :keyword '\
|
||||
'users.nickname LIKE :keyword OR mirror_repositories.name LIKE :keyword'
|
||||
'OR mirror_repositories.name LIKE :keyword'
|
||||
shixuns = shixuns.joins(:user, :mirror_repositories).where(like_sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
|
@ -48,7 +42,7 @@ class Admins::LaboratoriesController < Admins::BaseController
|
|||
|
||||
keyword = params[:keyword].to_s.strip
|
||||
if keyword.present?
|
||||
like_sql = 'subjects.name LIKE :keyword OR CONCAT(users.lastname, users.firstname) LIKE :keyword OR users.nickname LIKE :keyword'
|
||||
like_sql = 'subjects.name LIKE :keyword OR CONCAT(users.lastname, users.firstname) LIKE :keyword'
|
||||
subjects = subjects.joins(:user).where(like_sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
|
|
|
@ -1,11 +1,4 @@
|
|||
class Admins::LaboratorySettingsController < Admins::BaseController
|
||||
|
||||
def new
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@laboratory = current_laboratory
|
||||
end
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
class Admins::MessageTemplatesController < Admins::BaseController
|
||||
before_action :get_template, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
message_templates = MessageTemplate.ransack(sys_notice_or_email_or_email_title_cont: params[:search]).result
|
||||
@message_templates = kaminari_paginate(message_templates)
|
||||
end
|
||||
|
||||
def new
|
||||
@message_template = MessageTemplate.new
|
||||
end
|
||||
|
||||
def create
|
||||
@message_template = MessageTemplate::CustomTip.new(message_template_params)
|
||||
@message_template.type = "MessageTemplate::CustomTip"
|
||||
if @message_template.save!
|
||||
redirect_to admins_message_templates_path
|
||||
flash[:success] = "创建消息模板成功"
|
||||
else
|
||||
render :new
|
||||
flash[:danger] = "创建消息模板失败"
|
||||
end
|
||||
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
|
||||
# type = @message_template.present? ? @message_template.type : "MessageTemplate::CustomTip"
|
||||
# params.require(type.split("::").join("_").underscore.to_sym).permit!
|
||||
params.require(:message_template).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
|
|
@ -1,26 +0,0 @@
|
|||
class Admins::NpsController < Admins::BaseController
|
||||
def index
|
||||
@on_off_switch = EduSetting.get("nps-on-off-switch").to_s == 'true'
|
||||
@user_nps = UserNp.joins(:user).order(created_at: :desc)
|
||||
keyword = params[:keyword].to_s.strip.presence
|
||||
if keyword
|
||||
sql = 'CONCAT(users.lastname, users.firstname) LIKE :keyword OR users.nickname LIKE :keyword OR users.login LIKE :keyword OR users.mail LIKE :keyword OR users.phone LIKE :keyword'
|
||||
@user_nps = @user_nps.where(sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
@user_nps = @user_nps.where("action_type != 'close'") if params[:done_score].present?
|
||||
@min_score = @user_nps.where("action_type != 'close'").minimum("score")
|
||||
@max_score = @user_nps.where("action_type != 'close'").maximum("score")
|
||||
@score_total_count = UserNp.where("action_type !='close'").count
|
||||
@user_nps = paginate @user_nps.includes(:user)
|
||||
end
|
||||
|
||||
def switch_change
|
||||
edu_setting = EduSetting.find_by(name: "nps-on-off-switch")
|
||||
if edu_setting.blank?
|
||||
edu_setting = EduSetting.new(name: "nps-on-off-switch")
|
||||
end
|
||||
edu_setting.value = params[:switch].to_s
|
||||
edu_setting.save
|
||||
render_ok
|
||||
end
|
||||
end
|
|
@ -3,8 +3,8 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
|||
before_action :validate_names, only: [:create, :update]
|
||||
|
||||
def index
|
||||
sort_by = ProjectCategory.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||
sort_by = params[:sort_by] ||= 'created_at'
|
||||
sort_direction = params[:sort_direction] ||= 'desc'
|
||||
q = ProjectCategory.ransack(name_cont: params[:name])
|
||||
project_categories = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||
@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 = max_position_items.present? ? max_position_items.max.to_i : 0
|
||||
|
||||
@project_category = ProjectCategory.new(name: @name,position: max_position, pinned_index: params[:project_category][:pinned_index].to_i)
|
||||
@project_category = ProjectCategory.new(name: @name,position: max_position)
|
||||
if @project_category.save
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = '创建成功'
|
||||
|
@ -33,18 +33,17 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
|||
end
|
||||
|
||||
def update
|
||||
if @project_category.update_attributes({name: @name, pinned_index: params[:project_category][:pinned_index].to_i})
|
||||
save_image_file(params[:logo], 'logo')
|
||||
if @project_category.update_attribute(:name, @name)
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = '更新成功'
|
||||
else
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:danger] = '更新失败'
|
||||
flash[:success] = '更新失败'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @project_category.destroy
|
||||
if @project_language.destroy
|
||||
redirect_to admins_project_categories_path
|
||||
flash[:success] = "删除成功"
|
||||
else
|
||||
|
@ -81,12 +80,4 @@ class Admins::ProjectCategoriesController < Admins::BaseController
|
|||
flash[:danger] = '分类已存在'
|
||||
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
|
|
@ -1,10 +1,10 @@
|
|||
class Admins::ProjectIgnoresController < Admins::BaseController
|
||||
before_action :set_ignore, only: [:edit,:update, :destroy,:show]
|
||||
# before_action :validate_params, only: [:create, :update]
|
||||
before_action :validate_params, only: [:create, :update]
|
||||
|
||||
def index
|
||||
sort_by = Ignore.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||
sort_by = params[:sort_by] ||= 'created_at'
|
||||
sort_direction = params[:sort_direction] ||= 'desc'
|
||||
q = Ignore.ransack(name_cont: params[:search])
|
||||
project_ignores = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||
@project_ignores = paginate(project_ignores)
|
||||
|
@ -31,12 +31,12 @@ class Admins::ProjectIgnoresController < Admins::BaseController
|
|||
# }
|
||||
@project_ignore = Ignore.new(ignore_params)
|
||||
|
||||
if @project_ignore.save
|
||||
if @project_ignore.save!
|
||||
redirect_to admins_project_ignores_path
|
||||
flash[:success] = "创建成功"
|
||||
else
|
||||
redirect_to admins_project_ignores_path
|
||||
flash[:danger] = @project_ignore.errors.full_messages.join(",")
|
||||
render :new
|
||||
flash[:danger] = "创建失败"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -58,8 +58,8 @@ class Admins::ProjectIgnoresController < Admins::BaseController
|
|||
redirect_to admins_project_ignores_path
|
||||
flash[:success] = "更新成功"
|
||||
else
|
||||
redirect_to admins_project_ignores_path
|
||||
flash[:danger] = @project_ignore.errors.full_messages.join(",")
|
||||
render :edit
|
||||
flash[:danger] = "更新失败"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,23 +98,23 @@ class Admins::ProjectIgnoresController < Admins::BaseController
|
|||
params.require(:ignore).permit(:name,:content)
|
||||
end
|
||||
|
||||
# def validate_params
|
||||
# name = params[:ignore][:name]
|
||||
# if name.blank?
|
||||
# flash[:danger] = "名称不允许为空"
|
||||
# redirect_to admins_project_ignores_path
|
||||
# elsif check_ignore_present?(name) && @project_ignore.blank?
|
||||
# flash[:danger] = "创建失败:名称已存在"
|
||||
# redirect_to admins_project_ignores_path
|
||||
# end
|
||||
# end
|
||||
def validate_params
|
||||
name = params[:ignore][:name]
|
||||
if name.blank?
|
||||
flash[:danger] = "名称不允许为空"
|
||||
redirect_to admins_project_ignores_path
|
||||
elsif check_ignore_present?(name) && @project_ignore.blank?
|
||||
flash[:danger] = "创建失败:名称已存在"
|
||||
redirect_to admins_project_ignores_path
|
||||
end
|
||||
end
|
||||
|
||||
# def check_ignore_present?(name)
|
||||
# return true if name.blank?
|
||||
# name_downcase = name.downcase
|
||||
# name_upcase = name.upcase
|
||||
# name_first_big = name.capitalize
|
||||
# Ignore.exists?(name: name_downcase) || Ignore.exists?(name: name_upcase) || Ignore.exists?(name: name_first_big)
|
||||
# end
|
||||
def check_ignore_present?(name)
|
||||
return true if name.blank?
|
||||
name_downcase = name.downcase
|
||||
name_upcase = name.upcase
|
||||
name_first_big = name.capitalize
|
||||
Ignore.exists?(name: name_downcase) || Ignore.exists?(name: name_upcase) || Ignore.exists?(name: name_first_big)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ class Admins::ProjectLanguagesController < Admins::BaseController
|
|||
before_action :validate_names, only: [:create, :update]
|
||||
|
||||
def index
|
||||
sort_by = ProjectLanguage.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||
sort_by = params[:sort_by] ||= 'created_at'
|
||||
sort_direction = params[:sort_direction] ||= 'desc'
|
||||
q = ProjectLanguage.ransack(name_cont: params[:search])
|
||||
project_languages = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||
@project_languages = paginate(project_languages)
|
||||
|
@ -27,18 +27,17 @@ class Admins::ProjectLanguagesController < Admins::BaseController
|
|||
flash[:success] = '创建成功'
|
||||
else
|
||||
redirect_to admins_project_languages_path
|
||||
flash[:danger] = @project_language.errors.full_messages.join(",")
|
||||
flash[:danger] = '创建失败'
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@project_language.attributes = {name: @name}
|
||||
if @project_language.save
|
||||
if @project_language.update_attribute(:name, @name)
|
||||
redirect_to admins_project_languages_path
|
||||
flash[:success] = '更新成功'
|
||||
else
|
||||
redirect_to admins_project_languages_path
|
||||
flash[:danger] = @project_language.errors.full_messages.join(",")
|
||||
flash[:success] = '更新失败'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
class Admins::ProjectLicensesController < Admins::BaseController
|
||||
before_action :set_license, only: [:edit,:update, :destroy,:show]
|
||||
# before_action :validate_params, only: [:create, :update]
|
||||
before_action :validate_params, only: [:create, :update]
|
||||
|
||||
def index
|
||||
sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
|
||||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||
sort_by = params[:sort_by] ||= 'created_at'
|
||||
sort_direction = params[:sort_direction] ||= 'desc'
|
||||
q = License.ransack(name_cont: params[:search])
|
||||
project_licenses = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
|
||||
@project_licenses = paginate(project_licenses)
|
||||
|
@ -30,12 +30,13 @@ class Admins::ProjectLicensesController < Admins::BaseController
|
|||
# position: max_position
|
||||
# }
|
||||
@project_license = License.new(license_params)
|
||||
if @project_license.save
|
||||
|
||||
if @project_license.save!
|
||||
redirect_to admins_project_licenses_path
|
||||
flash[:success] = "创建成功"
|
||||
else
|
||||
redirect_to admins_project_licenses_path
|
||||
flash[:danger] = @project_license.errors.full_messages.join(",")
|
||||
render :new
|
||||
flash[:danger] = "创建失败"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -53,13 +54,12 @@ class Admins::ProjectLicensesController < Admins::BaseController
|
|||
# permissions: permissions.to_s,
|
||||
# limitations: limitations.to_s
|
||||
# }
|
||||
@project_license.attributes = license_params
|
||||
if @project_license.save
|
||||
if @project_license.update_attributes(license_params)
|
||||
redirect_to admins_project_licenses_path
|
||||
flash[:success] = "更新成功"
|
||||
else
|
||||
render admins_project_licenses_path
|
||||
flash[:danger] = @project_license.errors.full_messages.join(",")
|
||||
render :edit
|
||||
flash[:danger] = "更新失败"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -98,23 +98,23 @@ class Admins::ProjectLicensesController < Admins::BaseController
|
|||
params.require(:license).permit(:name,:content)
|
||||
end
|
||||
|
||||
# def validate_params
|
||||
# name = params[:license][:name]
|
||||
# if name.blank?
|
||||
# flash[:danger] = "名称不允许为空"
|
||||
# redirect_to admins_project_licenses_path
|
||||
# elsif check_license_present?(name) && @project_license.blank?
|
||||
# flash[:danger] = "创建失败:名称已存在"
|
||||
# redirect_to admins_project_licenses_path
|
||||
# end
|
||||
# end
|
||||
def validate_params
|
||||
name = params[:license][:name]
|
||||
if name.blank?
|
||||
flash[:danger] = "名称不允许为空"
|
||||
redirect_to admins_project_licenses_path
|
||||
elsif check_license_present?(name) && @project_license.blank?
|
||||
flash[:danger] = "创建失败:名称已存在"
|
||||
redirect_to admins_project_licenses_path
|
||||
end
|
||||
end
|
||||
|
||||
# def check_license_present?(name)
|
||||
# return true if name.blank?
|
||||
# name_downcase = name.downcase
|
||||
# name_upcase = name.upcase
|
||||
# name_first_big = name.capitalize
|
||||
# License.exists?(name: name_downcase) || License.exists?(name: name_upcase) || License.exists?(name: name_first_big)
|
||||
# end
|
||||
def check_license_present?(name)
|
||||
return true if name.blank?
|
||||
name_downcase = name.downcase
|
||||
name_upcase = name.upcase
|
||||
name_first_big = name.capitalize
|
||||
License.exists?(name: name_downcase) || License.exists?(name: name_upcase) || License.exists?(name: name_first_big)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,34 +1,14 @@
|
|||
class Admins::ProjectsController < Admins::BaseController
|
||||
before_action :find_project, only: [:edit, :update]
|
||||
|
||||
def index
|
||||
sort_by = Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_on'
|
||||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||
sort_by = params[:sort_by] ||= 'created_on'
|
||||
sort_direction = params[:sort_direction] ||= 'desc'
|
||||
|
||||
search = params[:search].to_s.strip
|
||||
projects = Project.where("name like ?", "%#{search}%").order("#{sort_by} #{sort_direction}")
|
||||
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
|
||||
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
|
||||
project = Project.find_by!(id: params[:id])
|
||||
ActiveRecord::Base.transaction do
|
||||
|
@ -42,13 +22,4 @@ class Admins::ProjectsController < Admins::BaseController
|
|||
redirect_to admins_projects_path
|
||||
flash[:danger] = "删除失败"
|
||||
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
|
|
@ -1,84 +0,0 @@
|
|||
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
|
|
@ -1,56 +0,0 @@
|
|||
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
|
|
@ -1,75 +0,0 @@
|
|||
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
|
|
@ -1,57 +0,0 @@
|
|||
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
|
|
@ -1,58 +0,0 @@
|
|||
class Admins::Topic::BannersController < Admins::Topic::BaseController
|
||||
before_action :find_banner, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@banners = paginate(::Topic::Banner)
|
||||
@banners = paginate(::Topic::Banner.where("title like ?", "%#{params[:search]}%")) if params[:search].present?
|
||||
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, :url)
|
||||
end
|
||||
end
|
|
@ -1,11 +0,0 @@
|
|||
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
|
|
@ -1,57 +0,0 @@
|
|||
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
|
|
@ -1,57 +0,0 @@
|
|||
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
|
|
@ -1,57 +0,0 @@
|
|||
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
|
|
@ -1,57 +0,0 @@
|
|||
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
|
|
@ -1,57 +0,0 @@
|
|||
class Admins::Topic::GlccNewsController < Admins::Topic::BaseController
|
||||
before_action :find_glcc, only: [:edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
q = ::Topic::GlccNews.ransack(title_cont: params[:search])
|
||||
glcc_news = q.result(distinct: true)
|
||||
@glcc_news = paginate(glcc_news)
|
||||
end
|
||||
|
||||
def new
|
||||
@glcc = ::Topic::GlccNews.new
|
||||
end
|
||||
|
||||
def create
|
||||
@glcc = ::Topic::GlccNews.new(glcc_params)
|
||||
if @glcc.save
|
||||
redirect_to admins_topic_glcc_news_index_path
|
||||
flash[:success] = "新增新闻稿成功"
|
||||
else
|
||||
redirect_to admins_topic_glcc_news_index_path
|
||||
flash[:danger] = "新增新闻稿失败"
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@glcc.attributes = glcc_params
|
||||
if @glcc.save
|
||||
redirect_to admins_topic_glcc_news_index_path
|
||||
flash[:success] = "更新新闻稿成功"
|
||||
else
|
||||
redirect_to admins_topic_glcc_news_index_path
|
||||
flash[:danger] = "更新新闻稿失败"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @glcc.destroy
|
||||
redirect_to admins_topic_glcc_news_index_path
|
||||
flash[:success] = "删除新闻稿成功"
|
||||
else
|
||||
redirect_to admins_topic_glcc_news_index_path
|
||||
flash[:danger] = "删除新闻稿失败"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_glcc
|
||||
@glcc = ::Topic::GlccNews.find_by_id(params[:id])
|
||||
end
|
||||
|
||||
def glcc_params
|
||||
params.require(:topic_glcc_news).permit(:title, :uuid, :url, :order_index)
|
||||
end
|
||||
end
|
|
@ -1,57 +0,0 @@
|
|||
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,6 +1,4 @@
|
|||
class Admins::UsersController < Admins::BaseController
|
||||
before_action :finder_user, except: [:index]
|
||||
|
||||
def index
|
||||
params[:sort_by] = params[:sort_by].presence || 'created_on'
|
||||
params[:sort_direction] = params[:sort_direction].presence || 'desc'
|
||||
|
@ -10,9 +8,12 @@ class Admins::UsersController < Admins::BaseController
|
|||
end
|
||||
|
||||
def edit
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@user = User.find(params[:id])
|
||||
|
||||
Admins::UpdateUserService.call(@user, update_params)
|
||||
flash[:success] = '保存成功'
|
||||
redirect_to edit_admins_user_path(@user)
|
||||
|
@ -25,47 +26,43 @@ class Admins::UsersController < Admins::BaseController
|
|||
end
|
||||
|
||||
def destroy
|
||||
@user.destroy!
|
||||
Gitea::User::DeleteService.call(@user.login)
|
||||
User.find(params[:id]).destroy!
|
||||
|
||||
render_delete_success
|
||||
end
|
||||
|
||||
def lock
|
||||
@user.lock!
|
||||
User.find(params[:id]).lock!
|
||||
|
||||
render_ok
|
||||
end
|
||||
|
||||
def unlock
|
||||
@user.activate!
|
||||
User.find(params[:id]).activate!
|
||||
|
||||
render_ok
|
||||
end
|
||||
|
||||
def reward_grade
|
||||
user = User.find(params[:user_id])
|
||||
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
|
||||
|
||||
def reset_login_times
|
||||
@user.reset_login_times!
|
||||
User.find(params[:id]).reset_login_times!
|
||||
|
||||
render_ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def finder_user
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
def update_params
|
||||
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
|
||||
password professional_certification authentication login])
|
||||
password professional_certification authentication])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
class Api::V1::BaseController < ApplicationController
|
||||
|
||||
include Api::ProjectHelper
|
||||
include Api::UserHelper
|
||||
include Api::PullHelper
|
||||
|
||||
# before_action :doorkeeper_authorize!
|
||||
# skip_before_action :user_setup
|
||||
|
||||
protected
|
||||
# def current_user
|
||||
# #client方法对接,需要一直带着用户标识uid
|
||||
# Rails.logger.info doorkeeper_token
|
||||
# if doorkeeper_token && doorkeeper_token.resource_owner_id.blank?
|
||||
# # return User.anonymous if params[:uid].nil?
|
||||
# # tip_exception("2222")
|
||||
# # return render_error('缺少用户标识!') if params[:uid].nil?
|
||||
# User.current = User.find(params[:uid])
|
||||
# else
|
||||
# User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
|
||||
# end
|
||||
# end
|
||||
|
||||
def limit
|
||||
params.fetch(:limit, 15)
|
||||
end
|
||||
def page
|
||||
params.fetch(:page, 1)
|
||||
end
|
||||
|
||||
# 具有对仓库的管理权限
|
||||
def require_manager_above
|
||||
@project = load_project
|
||||
return render_forbidden if !current_user.admin? && !@project.manager?(current_user)
|
||||
end
|
||||
|
||||
# 具有对仓库的操作权限
|
||||
def require_operate_above
|
||||
@project = load_project
|
||||
return render_forbidden if !current_user.admin? && !@project.operator?(current_user)
|
||||
end
|
||||
|
||||
# 具有仓库的操作权限或者fork仓库的操作权限
|
||||
def require_operate_above_or_fork_project
|
||||
@project = load_project
|
||||
puts !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
|
||||
return render_forbidden if !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
|
||||
end
|
||||
|
||||
# 具有对仓库的访问权限
|
||||
def require_public_and_member_above
|
||||
@project = load_project
|
||||
return render_forbidden if !@project.is_public && !current_user.admin? && !@project.member?(current_user)
|
||||
end
|
||||
end
|
|
@ -1,18 +0,0 @@
|
|||
class Api::V1::Projects::BranchesController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:all]
|
||||
|
||||
def all
|
||||
@result_object = Api::V1::Projects::Branches::AllListService.call(@project, current_user&.gitea_token)
|
||||
end
|
||||
|
||||
before_action :require_operate_above, only: [:create]
|
||||
|
||||
def create
|
||||
@result_object = Api::V1::Projects::Branches::CreateService.call(@project, branch_params, current_user&.gitea_token)
|
||||
end
|
||||
|
||||
private
|
||||
def branch_params
|
||||
params.require(:branch).permit(:new_branch_name, :old_branch_name)
|
||||
end
|
||||
end
|
|
@ -1,8 +0,0 @@
|
|||
class Api::V1::Projects::CodeStatsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:index]
|
||||
|
||||
def index
|
||||
@result_object = Api::V1::Projects::CodeStats::ListService.call(@project, {ref: params[:ref]}, current_user&.gitea_token)
|
||||
puts @result_object
|
||||
end
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
class Api::V1::Projects::CommitsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:index, :diff]
|
||||
|
||||
def index
|
||||
@result_object = Api::V1::Projects::Commits::ListService.call(@project, {page: page, limit: limit, sha: params[:sha]}, current_user&.gitea_token)
|
||||
puts @result_object
|
||||
end
|
||||
|
||||
def diff
|
||||
@result_object = Api::V1::Projects::Commits::DiffService.call(@project, params[:sha], current_user&.gitea_token)
|
||||
end
|
||||
end
|
|
@ -1,17 +0,0 @@
|
|||
class Api::V1::Projects::ContentsController < Api::V1::BaseController
|
||||
before_action :require_operate_above_or_fork_project, only: [:batch]
|
||||
|
||||
def batch
|
||||
@batch_content_params = batch_content_params
|
||||
# 处理下author和committer信息,如果没传则默认为当前用户信息
|
||||
@batch_content_params.merge!(author_email: current_user.mail, author_name: current_user.login) if batch_content_params[:author_email].blank? && batch_content_params[:author_name].blank?
|
||||
@batch_content_params.merge!(committer_email: current_user.mail, committer_name: current_user.login) if batch_content_params[:committer_email].blank? && batch_content_params[:committer_name].blank?
|
||||
|
||||
@result_object = Api::V1::Projects::Contents::BatchCreateService.call(@project, @batch_content_params, @project.owner.gitea_token)
|
||||
end
|
||||
|
||||
private
|
||||
def batch_content_params
|
||||
params.require(:content).permit(:author_email, :author_name, :author_timeunix, :branch, :committer_email, :committer_name, :committer_timeunix, :message, :new_branch, files: [ :action_type, :content, :encoding, :file_path])
|
||||
end
|
||||
end
|
|
@ -1,12 +0,0 @@
|
|||
class Api::V1::Projects::GitController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:trees, :blobs]
|
||||
|
||||
def trees
|
||||
@result_object = Api::V1::Projects::Git::TreesService.call(@project, params[:sha], {recursive: params[:recursive], page: page, limit: limit}, current_user&.gitea_token)
|
||||
end
|
||||
|
||||
def blobs
|
||||
@result_object = Api::V1::Projects::Git::BlobsService.call(@project, params[:sha], current_user&.gitea_token)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,5 +0,0 @@
|
|||
class Api::V1::Projects::Pulls::BaseController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above
|
||||
before_action :load_pull_request
|
||||
|
||||
end
|
|
@ -1,40 +0,0 @@
|
|||
class Api::V1::Projects::Pulls::JournalsController < Api::V1::Projects::Pulls::BaseController
|
||||
|
||||
def index
|
||||
@journals = Api::V1::Projects::Pulls::Journals::ListService.call(@project, @pull_request, params, current_user)
|
||||
@journals = @journals.limit(200)
|
||||
end
|
||||
|
||||
def create
|
||||
@journal = Api::V1::Projects::Pulls::Journals::CreateService.call(@project, @pull_request, create_params, current_user)
|
||||
end
|
||||
|
||||
before_action :find_journal, only: [:update, :destroy]
|
||||
|
||||
def update
|
||||
@journal = Api::V1::Projects::Pulls::Journals::UpdateService.call(@project, @pull_request, @journal, update_params, current_user)
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @journal.destroy
|
||||
render_ok
|
||||
else
|
||||
render_error("删除评论失败!")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def create_params
|
||||
params.permit(:parent_id, :line_code, :note, :commit_id, :path, :type, :review_id, :diff => {})
|
||||
end
|
||||
|
||||
def update_params
|
||||
params.permit(:note, :commit_id, :state)
|
||||
end
|
||||
|
||||
def find_journal
|
||||
@journal = @pull_request.journals.find_by_id(params[:id])
|
||||
return render_not_found unless @journal.present?
|
||||
end
|
||||
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
class Api::V1::Projects::Pulls::PullsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above
|
||||
|
||||
def index
|
||||
@pulls = Api::V1::Projects::Pulls::ListService.call(@project, query_params)
|
||||
@pulls = kaminari_paginate(@pulls)
|
||||
end
|
||||
|
||||
before_action :load_pull_request, only: [:show]
|
||||
|
||||
def show
|
||||
@result_object = Api::V1::Projects::Pulls::GetService.call(@project, @pull_request, current_user&.gitea_token)
|
||||
@last_review = @pull_request.reviews.order(created_at: :desc).take
|
||||
end
|
||||
|
||||
private
|
||||
def query_params
|
||||
params.permit(:status, :keyword, :priority_id, :issue_tag_id, :version_id, :reviewer_id, :sort_by, :sort_direction)
|
||||
end
|
||||
end
|
|
@ -1,23 +0,0 @@
|
|||
class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::BaseController
|
||||
|
||||
def index
|
||||
@reviews = @pull_request.reviews
|
||||
@reviews = @reviews.where(status: params[:status]) if params[:status].present?
|
||||
# @reviews = kaminari_paginate(@reviews)
|
||||
end
|
||||
|
||||
before_action :require_reviewer, only: [:create]
|
||||
|
||||
def create
|
||||
@review = Api::V1::Projects::Pulls::Reviews::CreateService.call(@project, @pull_request, review_params, current_user)
|
||||
end
|
||||
|
||||
private
|
||||
def require_reviewer
|
||||
return render_forbidden('您没有审查权限,请联系项目管理员') if !current_user.admin? && !@pull_request.reviewers.exists?(current_user.id) && !@project.manager?(current_user)
|
||||
end
|
||||
|
||||
def review_params
|
||||
params.require(:review).permit(:content, :commit_id, :status)
|
||||
end
|
||||
end
|
|
@ -1,10 +0,0 @@
|
|||
class Api::V1::Projects::Pulls::VersionsController < Api::V1::Projects::Pulls::BaseController
|
||||
|
||||
def index
|
||||
@result_object = Api::V1::Projects::Pulls::Versions::ListService.call(@project, @pull_request, {page: page, limit: limit}, current_user&.gitea_token)
|
||||
end
|
||||
|
||||
def diff
|
||||
@result_object = Api::V1::Projects::Pulls::Versions::GetDiffService.call(@project, @pull_request, params[:id], {filepath: params[:filepath]}, current_user&.gitea_token)
|
||||
end
|
||||
end
|
|
@ -1,61 +0,0 @@
|
|||
class Api::V1::Projects::WebhooksController < Api::V1::BaseController
|
||||
before_action :require_manager_above
|
||||
before_action :find_webhook, only: [:show, :update, :destroy, :tests, :hooktasks]
|
||||
|
||||
def index
|
||||
# @result_object = Api::V1::Projects::Webhooks::ListService.call(@project, current_user&.gitea_token)
|
||||
@webhooks = @project.webhooks
|
||||
@webhooks = @webhooks.where(type: params[:type]) if params[:type].present?
|
||||
@webhooks = kaminari_paginate(@webhooks)
|
||||
end
|
||||
|
||||
def create
|
||||
return render_error("webhooks数量已到上限!请删除暂不使用的webhooks以进行添加操作") if @project.webhooks.size > 49
|
||||
@result_object = Api::V1::Projects::Webhooks::CreateService.call(@project, create_webhook_params, current_user&.gitea_token)
|
||||
end
|
||||
|
||||
def show
|
||||
@result_object = Api::V1::Projects::Webhooks::GetService.call(@project, params[:id], current_user&.gitea_token)
|
||||
end
|
||||
|
||||
def update
|
||||
@result_object = Api::V1::Projects::Webhooks::UpdateService.call(@project, params[:id], webhook_params, current_user&.gitea_token)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@result_object = Api::V1::Projects::Webhooks::DeleteService.call(@project, params[:id], current_user&.gitea_token)
|
||||
if @result_object
|
||||
return render_ok
|
||||
else
|
||||
return render_error('删除失败!')
|
||||
end
|
||||
end
|
||||
|
||||
def tests
|
||||
@result_object = Api::V1::Projects::Webhooks::TestsService.call(@project, params[:id], current_user&.gitea_token)
|
||||
if @result_object
|
||||
return render_ok
|
||||
else
|
||||
return render_error('推送失败!')
|
||||
end
|
||||
end
|
||||
|
||||
def hooktasks
|
||||
@hooktasks = @webhook.tasks.where(is_delivered: true).order("delivered desc")
|
||||
@hooktasks = kaminari_paginate(@hooktasks)
|
||||
end
|
||||
|
||||
private
|
||||
def create_webhook_params
|
||||
params.require(:webhook).permit(:active, :branch_filter, :http_method, :url, :content_type, :secret, :type, events: [])
|
||||
end
|
||||
|
||||
def webhook_params
|
||||
params.require(:webhook).permit(:active, :branch_filter, :http_method, :url, :content_type, :secret, events: [])
|
||||
end
|
||||
|
||||
def find_webhook
|
||||
@webhook = Gitea::Webhook.find_by_id(params[:id])
|
||||
return render_not_found unless @webhook.present?
|
||||
end
|
||||
end
|
|
@ -1,19 +0,0 @@
|
|||
class Api::V1::ProjectsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:show, :compare, :blame]
|
||||
|
||||
def index
|
||||
render_ok
|
||||
end
|
||||
|
||||
def show
|
||||
@result_object = Api::V1::Projects::GetService.call(@project, current_user.gitea_token)
|
||||
end
|
||||
|
||||
def compare
|
||||
@result_object = Api::V1::Projects::CompareService.call(@project, params[:from], params[:to], current_user&.gitea_token)
|
||||
end
|
||||
|
||||
def blame
|
||||
@result_object = Api::V1::Projects::BlameService.call(@project, params[:sha], params[:filepath], current_user&.gitea_token)
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
class Api::V1::Users::FeedbacksController < Api::V1::BaseController
|
||||
|
||||
before_action :load_observe_user
|
||||
before_action :check_auth_for_observe_user
|
||||
|
||||
def create
|
||||
@result = Api::V1::Users::Feedbacks::CreateService.call(@observe_user, feedback_params)
|
||||
return render_error("反馈意见创建失败.") if @result.nil?
|
||||
return render_ok
|
||||
end
|
||||
|
||||
private
|
||||
def feedback_params
|
||||
params.permit(:content)
|
||||
end
|
||||
end
|
|
@ -1,13 +0,0 @@
|
|||
class Api::V1::Users::ProjectsController < Api::V1::BaseController
|
||||
before_action :load_observe_user
|
||||
|
||||
def index
|
||||
@object_results = Api::V1::Users::Projects::ListService.call(@observe_user, query_params, current_user)
|
||||
@projects = kaminari_paginate(@object_results)
|
||||
end
|
||||
|
||||
private
|
||||
def query_params
|
||||
params.permit(:category, :is_public, :project_type, :sort_by, :sort_direction, :search)
|
||||
end
|
||||
end
|
|
@ -1,105 +0,0 @@
|
|||
class Api::V1::UsersController < Api::V1::BaseController
|
||||
|
||||
before_action :load_observe_user
|
||||
before_action :check_auth_for_observe_user
|
||||
|
||||
def send_email_vefify_code
|
||||
code = %W(0 1 2 3 4 5 6 7 8 9)
|
||||
verification_code = code.sample(6).join
|
||||
mail = params[:email]
|
||||
code_type = params[:code_type]
|
||||
|
||||
sign = Digest::MD5.hexdigest("#{OPENKEY}#{mail}")
|
||||
Rails.logger.info sign
|
||||
|
||||
tip_exception(501, "请求不合理") if sign != params[:smscode]
|
||||
|
||||
# 60s内不能重复发送
|
||||
send_email_limit_cache_key = "send_email_60_second_limit:#{mail}"
|
||||
tip_exception(-2, '请勿频繁操作') if Rails.cache.exist?(send_email_limit_cache_key)
|
||||
send_email_control = LimitForbidControl::SendEmailCode.new(mail)
|
||||
tip_exception(-2, '邮件发送太频繁,请稍后再试') if send_email_control.forbid?
|
||||
begin
|
||||
UserMailer.update_email(mail, verification_code).deliver_now
|
||||
|
||||
Rails.cache.write(send_email_limit_cache_key, 1, expires_in: 1.minute)
|
||||
send_email_control.increment!
|
||||
rescue Exception => e
|
||||
logger_error(e)
|
||||
tip_exception(-2,"邮件发送失败,请稍后重试")
|
||||
end
|
||||
ver_params = {code_type: code_type, code: verification_code, email: mail}
|
||||
last_code = VerificationCode.where(code_type: code_type, email: mail).last
|
||||
last_code.update_attributes!({created_at: Time.current - 10.minute}) if last_code.present?
|
||||
data = VerificationCode.new(ver_params)
|
||||
if data.save!
|
||||
render_ok
|
||||
else
|
||||
tip_exception(-1, "创建数据失败")
|
||||
end
|
||||
end
|
||||
|
||||
def check_password
|
||||
password = params[:password]
|
||||
return tip_exception(-5, "8~16位密码,支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD
|
||||
return tip_exception(-5, "密码错误") unless @observe_user.check_password?(password)
|
||||
render_ok
|
||||
end
|
||||
|
||||
def check_email
|
||||
mail = strip(params[:email])
|
||||
return tip_exception(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL
|
||||
|
||||
exist_owner = Owner.find_by(mail: mail)
|
||||
return tip_exception(-2, '邮箱已被使用') if exist_owner
|
||||
render_ok
|
||||
end
|
||||
|
||||
def check_email_verify_code
|
||||
code = strip(params[:code])
|
||||
mail = strip(params[:email])
|
||||
code_type = params[:code_type]
|
||||
|
||||
return tip_exception(-2, "邮件格式有误") unless mail =~ CustomRegexp::EMAIL
|
||||
|
||||
verifi_code = VerificationCode.where(email: mail, code: code, code_type: code_type).last
|
||||
return render_ok if code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试
|
||||
|
||||
return tip_exception(-6, "验证码不正确") if verifi_code&.code != code
|
||||
return tip_exception(-6, "验证码已失效") if !verifi_code&.effective?
|
||||
render_ok
|
||||
end
|
||||
|
||||
def check_phone_verify_code
|
||||
code = strip(params[:code])
|
||||
phone = strip(params[:phone])
|
||||
code_type = params[:code_type]
|
||||
|
||||
return tip_exception(-2, "手机号格式有误") unless phone =~ CustomRegexp::PHONE
|
||||
|
||||
verifi_code = VerificationCode.where(phone: phone, code: code, code_type: code_type).last
|
||||
return render_ok if code == "123123" && EduSetting.get("code_debug") # 万能验证码,用于测试 # TODO 万能验证码,用于测试
|
||||
|
||||
return tip_exception(-6, "验证码不正确") if verifi_code&.code != code
|
||||
return tip_exception(-6, "验证码已失效") if !verifi_code&.effective?
|
||||
render_ok
|
||||
end
|
||||
|
||||
def update_email
|
||||
@result_object = Api::V1::Users::UpdateEmailService.call(@observe_user, params, current_user.gitea_token)
|
||||
if @result_object
|
||||
return render_ok
|
||||
else
|
||||
return render_error('更改邮箱失败!')
|
||||
end
|
||||
end
|
||||
|
||||
def update_phone
|
||||
@result_object = Api::V1::Users::UpdatePhoneService.call(@observe_user, params)
|
||||
if @result_object
|
||||
return render_ok
|
||||
else
|
||||
return render_error('更改手机号失败!')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,30 +10,25 @@ class ApplicationController < ActionController::Base
|
|||
include LoggerHelper
|
||||
include LoginHelper
|
||||
include RegisterHelper
|
||||
include UpdateHelper
|
||||
|
||||
|
||||
protect_from_forgery prepend: true, unless: -> { request.format.json? }
|
||||
|
||||
before_action :check_sign
|
||||
before_action :user_setup
|
||||
#before_action :check_account
|
||||
after_action :user_trace_log
|
||||
|
||||
# TODO
|
||||
# check sql query time
|
||||
before_action do
|
||||
# if request.subdomain === 'testforgeplus' || request.subdomain === "profiler"
|
||||
# Rack::MiniProfiler.authorize_request
|
||||
# end
|
||||
if request.subdomain === 'testforgeplus' || request.subdomain === "profiler"
|
||||
Rack::MiniProfiler.authorize_request
|
||||
end
|
||||
end
|
||||
|
||||
before_action :update_last_login_on
|
||||
|
||||
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 = Rails.application.config_for(:configuration)['sign_key'] || "79e33abd4b6588941ab7622aed1e67e8"
|
||||
OPENKEY = "79e33abd4b6588941ab7622aed1e67e8"
|
||||
|
||||
|
||||
helper_method :current_user, :base_url
|
||||
helper_method :current_user
|
||||
|
||||
# 所有请求必须合法签名
|
||||
def check_sign
|
||||
|
@ -75,27 +70,66 @@ class ApplicationController < ActionController::Base
|
|||
(current_user.professional_certification && (ue.teacher? || ue.professional?))
|
||||
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?
|
||||
User.current.admin? || User.current.business?
|
||||
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:绑定
|
||||
def check_mail_and_phone_valid login, type
|
||||
unless login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ || login =~ /^1\d{10}$/
|
||||
unless login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ || login =~ /^1\d{10}$/ ||
|
||||
login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])$/
|
||||
tip_exception(-2, "请输入正确的手机号或邮箱")
|
||||
end
|
||||
|
||||
user_exist = Owner.exists?(phone: login) || Owner.exists?(mail: login)
|
||||
if user_exist && type.to_i == 1
|
||||
# 考虑到安全参数问题,多一次查询,去掉Union
|
||||
user = User.where(phone: login).first || User.where(mail: login).first
|
||||
if type.to_i == 1 && !user.nil?
|
||||
tip_exception(-2, "该手机号码或邮箱已被注册")
|
||||
elsif type.to_i == 2 && !user_exist
|
||||
elsif type.to_i == 2 && user.nil?
|
||||
tip_exception(-2, "该手机号码或邮箱未注册")
|
||||
elsif type.to_i == 3 && user_exist
|
||||
elsif type.to_i == 3 && user.present?
|
||||
tip_exception(-2, "该手机号码或邮箱已绑定")
|
||||
end
|
||||
render_ok
|
||||
sucess_status
|
||||
end
|
||||
|
||||
# 发送及记录激活码
|
||||
|
@ -106,10 +140,8 @@ class ApplicationController < ActionController::Base
|
|||
when 1, 2, 4, 9
|
||||
# 手机类型的发送
|
||||
sigle_para = {phone: value}
|
||||
# status = Gitlink::Sms.send(mobile: value, code: code)
|
||||
# tip_exception(-2, code_msg(status)) if status != 0
|
||||
status = Sms::UcloudService.call(value, code, send_type)
|
||||
tip_exception(-2, ucloud_code_msg(status)) if status != 0
|
||||
status = Educoder::Sms.send(mobile: value, code: code)
|
||||
tip_exception(-2, code_msg(status)) if status != 0
|
||||
when 8, 3, 5
|
||||
# 邮箱类型的发送
|
||||
sigle_para = {email: value}
|
||||
|
@ -121,13 +153,8 @@ class ApplicationController < ActionController::Base
|
|||
send_email_control = LimitForbidControl::SendEmailCode.new(value)
|
||||
tip_exception(-1, '邮件发送太频繁,请稍后再试') if send_email_control.forbid?
|
||||
begin
|
||||
if send_type == 3
|
||||
UserMailer.find_password(value, code).deliver_now
|
||||
elsif send_type == 5
|
||||
UserMailer.bind_email(value, code).deliver_now
|
||||
else
|
||||
UserMailer.register_email(value, code).deliver_now
|
||||
end
|
||||
UserMailer.register_email(value, code).deliver_now
|
||||
|
||||
Rails.cache.write(send_email_limit_cache_key, 1, expires_in: 1.minute)
|
||||
send_email_control.increment!
|
||||
# Mailer.run.email_register(code, value)
|
||||
|
@ -159,25 +186,24 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def ucloud_code_msg status
|
||||
case status
|
||||
when 0
|
||||
"验证码已经发送到您的手机,请注意查收"
|
||||
when 171
|
||||
"API签名错误"
|
||||
when 18014
|
||||
"无效手机号码"
|
||||
when 18017
|
||||
"无效模板"
|
||||
when 18018
|
||||
"短信模板参数与短信模板不匹配"
|
||||
when 18023
|
||||
"短信内容中含有运营商拦截的关键词"
|
||||
when 18033
|
||||
"变量内容不符合规范"
|
||||
else
|
||||
"错误码#{status}"
|
||||
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)
|
||||
|
@ -189,6 +215,21 @@ class ApplicationController < ActionController::Base
|
|||
@page_size = params[:page_size] || 15
|
||||
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
|
||||
normal_status(403, "") unless User.current.admin?
|
||||
end
|
||||
|
@ -201,39 +242,13 @@ class ApplicationController < ActionController::Base
|
|||
# 未授权的捕捉407,弹试用申请弹框
|
||||
def require_login
|
||||
#6.13 -hs
|
||||
|
||||
tip_exception(401, "请登录后再操作") unless User.current.logged?
|
||||
end
|
||||
|
||||
def require_login_or_token
|
||||
if params[:token].present?
|
||||
user = User.try_to_autologin(params[:token])
|
||||
User.current = user
|
||||
end
|
||||
tip_exception(401, "请登录后再操作") unless User.current.logged?
|
||||
end
|
||||
|
||||
def require_login_cloud_ide_saas
|
||||
if params[:sign].present? && params[:email].present?
|
||||
sign = Digest::MD5.hexdigest("#{OPENKEY}#{params[:email]}")
|
||||
if params[:sign].to_s == sign
|
||||
user = User.find_by(mail: params[:email])
|
||||
User.current = user
|
||||
end
|
||||
end
|
||||
tip_exception(401, "请登录后再操作") unless User.current.logged?
|
||||
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)
|
||||
raise Gitlink::TipException.new(status, message)
|
||||
raise Educoder::TipException.new(status, message)
|
||||
end
|
||||
|
||||
def missing_template
|
||||
|
@ -242,7 +257,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
# 弹框提醒
|
||||
def tip_show_exception(status = -2, message)
|
||||
raise Gitlink::TipException.new(status, message)
|
||||
raise Educoder::TipException.new(status, message)
|
||||
end
|
||||
|
||||
def normal_status(status = 0, message)
|
||||
|
@ -257,7 +272,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
# 资料是否完善
|
||||
def check_account
|
||||
if !current_user. profile_is_completed?
|
||||
if !current_user.profile_completed?
|
||||
#info_url = '/account/profile'
|
||||
tip_exception(402, nil)
|
||||
end
|
||||
|
@ -298,55 +313,39 @@ class ApplicationController < ActionController::Base
|
|||
#return if params[:controller] == "main"
|
||||
# Find the current user
|
||||
#Rails.logger.info("current_laboratory is #{current_laboratory} domain is #{request.subdomain}")
|
||||
if request.headers["Authorization"].present? && request.headers["Authorization"].start_with?('Bearer')
|
||||
tip_exception(401, "请登录后再操作!") unless valid_doorkeeper_token?
|
||||
if @doorkeeper_token.present?
|
||||
# client方法对接,需要一直带着用户标识uid
|
||||
if @doorkeeper_token.resource_owner_id.blank?
|
||||
tip_exception(-1, "缺少用户标识!") if params[:uid].nil?
|
||||
User.current = User.find(params[:uid])
|
||||
else
|
||||
User.current = User.find_by(id: @doorkeeper_token.resource_owner_id)
|
||||
User.current = find_current_user
|
||||
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous"))
|
||||
|
||||
# 开放课程通过链接访问的用户
|
||||
if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank?
|
||||
content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}"
|
||||
|
||||
if Digest::MD5.hexdigest(content) == params[:chinaoocKey]
|
||||
user = open_class_user
|
||||
if user
|
||||
start_user_session(user)
|
||||
set_autologin_cookie(user)
|
||||
end
|
||||
User.current = user
|
||||
end
|
||||
else
|
||||
User.current = find_current_user
|
||||
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous"))
|
||||
end
|
||||
|
||||
# 开放课程通过链接访问的用户
|
||||
if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank?
|
||||
content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}"
|
||||
# if !User.current.logged? && Rails.env.development?
|
||||
# User.current = User.find 1
|
||||
# end
|
||||
|
||||
if Digest::MD5.hexdigest(content) == params[:chinaoocKey]
|
||||
user = open_class_user
|
||||
if user
|
||||
start_user_session(user)
|
||||
set_autologin_cookie(user)
|
||||
end
|
||||
User.current = user
|
||||
end
|
||||
end
|
||||
|
||||
if !User.current.logged? && Rails.env.development?
|
||||
# 测试版前端需求
|
||||
logger.info("subdomain:#{request.subdomain}")
|
||||
if request.subdomain != "www"
|
||||
if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除
|
||||
User.current = User.find 81403
|
||||
elsif params[:debug] == 'student'
|
||||
User.current = User.find 8686
|
||||
elsif params[:debug] == 'admin'
|
||||
user = User.find 1
|
||||
User.current = user
|
||||
start_user_session(user)
|
||||
end
|
||||
|
||||
|
||||
# 测试版前端需求
|
||||
logger.info("subdomain:#{request.subdomain}")
|
||||
if request.subdomain != "www"
|
||||
if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除
|
||||
User.current = User.find 81403
|
||||
elsif params[:debug] == 'student'
|
||||
User.current = User.find 8686
|
||||
elsif params[:debug] == 'admin'
|
||||
logger.info "@@@@@@@@@@@@@@@@@@@@@@ debug mode....."
|
||||
user = User.find 36480
|
||||
User.current = user
|
||||
cookies.signed[:user_id] = user.id
|
||||
end
|
||||
cookies.signed[:user_id] = user.id
|
||||
end
|
||||
end
|
||||
# User.current = User.find 81403
|
||||
|
@ -367,27 +366,14 @@ class ApplicationController < ActionController::Base
|
|||
# RSS key authentication does not start a session
|
||||
User.find_by_rss_key(params[:key])
|
||||
end
|
||||
# User.current = User.find(2) # need to remove this statement before running in production
|
||||
end
|
||||
|
||||
def user_trace_log
|
||||
user = current_user
|
||||
# print("*********************url:", request.url, "****routes", request.request_method)
|
||||
Rails.logger.user_trace.info("{id: #{user.id}, login: #{user.login}, url: #{request.url}, method: #{request.method}, params: #{params}, response_code: #{response.code}, time: #{Time.now}}")
|
||||
end
|
||||
|
||||
def user_trace_update_log(old_value_hash)
|
||||
user = current_user
|
||||
str = "{id: #{user.id}, login: #{user.login}, url: #{request.url}, method: #{request.method}, params: #{params.merge(old_value: old_value_hash)}, response_code: #{response.code}, time: #{Time.now}}"
|
||||
Rails.logger.user_trace.info(str)
|
||||
end
|
||||
end
|
||||
|
||||
def try_to_autologin
|
||||
if cookies[autologin_cookie_name]
|
||||
# auto-login feature starts a new session
|
||||
user = nil
|
||||
Rails.logger.info("111111111111111111#{default_yun_session}, session is #{session[:"#{default_yun_session}"]} ")
|
||||
user = User.try_to_autologin(cookies[autologin_cookie_name])
|
||||
user = User.try_to_autologin(cookies[autologin_cookie_name], autologin_cookie_name)
|
||||
# start_user_session(user) if user # TODO 解决sso退出不同步的问题
|
||||
user
|
||||
end
|
||||
|
@ -398,7 +384,11 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def current_user
|
||||
User.current
|
||||
if Rails.env.development?
|
||||
User.current = User.find 1
|
||||
else
|
||||
User.current
|
||||
end
|
||||
end
|
||||
|
||||
## 默认输出json
|
||||
|
@ -406,13 +396,13 @@ class ApplicationController < ActionController::Base
|
|||
respond_to do |format|
|
||||
format.json
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
## 输出错误信息
|
||||
def error_status(message = nil)
|
||||
@status = -1
|
||||
@message = message
|
||||
end
|
||||
## 输出错误信息
|
||||
def error_status(message = nil)
|
||||
@status = -1
|
||||
@message = message
|
||||
end
|
||||
|
||||
# 实训等对应的仓库地址
|
||||
def repo_ip_url(repo_path)
|
||||
|
@ -451,7 +441,7 @@ class ApplicationController < ActionController::Base
|
|||
JSON.parse(res)
|
||||
rescue Exception => e
|
||||
uid_logger_error("--uri_exec: exception #{e.message}")
|
||||
raise Gitlink::TipException.new("实训平台繁忙(繁忙等级:84)")
|
||||
raise Educoder::TipException.new("实训平台繁忙(繁忙等级:84)")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -470,7 +460,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
rescue Exception => e
|
||||
uid_logger("--uri_exec: exception #{e.message}")
|
||||
raise Gitlink::TipException.new(message)
|
||||
raise Educoder::TipException.new(message)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -494,7 +484,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
rescue Exception => e
|
||||
uid_logger("--uri_exec: exception #{e.message}")
|
||||
raise Gitlink::TipException.new("服务器繁忙")
|
||||
raise Educoder::TipException.new("服务器繁忙")
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -628,8 +618,8 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
# 排序
|
||||
rorder = UserExtension.column_names.include?(option[:order]) ? option[:order] : "updated_at"
|
||||
b_order = %w(desc asc).include?(option[:b_order]) ? option[:b_order] : "desc"
|
||||
rorder = option[:order] || "updated_at"
|
||||
b_order = option[:b_order] || "desc"
|
||||
if rorder == "created_at" || rorder == "work_score"
|
||||
work_list = work_list.order("graduation_works.#{rorder} #{b_order}")
|
||||
elsif rorder == "student_id"
|
||||
|
@ -655,23 +645,6 @@ class ApplicationController < ActionController::Base
|
|||
ss
|
||||
end
|
||||
|
||||
def strip_html(text, len=0, endss="...")
|
||||
ss = ""
|
||||
if !text.nil? && text.length>0
|
||||
ss=text.gsub(/<\/?.*?>/, '').strip
|
||||
ss = ss.gsub(/ */, '')
|
||||
ss = ss.gsub(/\r\n/,'') #新增
|
||||
ss = ss.gsub(/\n/,'') #新增
|
||||
if len > 0 && ss.length > len
|
||||
ss = ss[0, len] + endss
|
||||
elsif len > 0 && ss.length <= len
|
||||
ss = ss
|
||||
#ss = truncate(ss, :length => len)
|
||||
end
|
||||
end
|
||||
ss
|
||||
end
|
||||
|
||||
# Returns a string that can be used as filename value in Content-Disposition header
|
||||
def filename_for_content_disposition(name)
|
||||
request.env['HTTP_USER_AGENT'] =~ %r{MSIE|Trident|Edge} ? ERB::Util.url_encode(name) : name
|
||||
|
@ -710,14 +683,6 @@ class ApplicationController < ActionController::Base
|
|||
relation.page(page).per(limit)
|
||||
end
|
||||
|
||||
def kaminari_array_paginate(relation)
|
||||
limit = params[:limit] || params[:per_page]
|
||||
limit = (limit.to_i.zero? || limit.to_i > 20) ? 20 : limit.to_i
|
||||
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
|
||||
|
||||
Kaminari.paginate_array(relation).page(page).per(limit)
|
||||
end
|
||||
|
||||
def strf_time(time)
|
||||
time.blank? ? '' : time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
end
|
||||
|
@ -779,77 +744,34 @@ class ApplicationController < ActionController::Base
|
|||
namespace = params[:owner]
|
||||
id = params[:repo] || params[:id]
|
||||
|
||||
@project, @owner = Project.find_with_namespace(namespace, id)
|
||||
@project = Project.find_with_namespace(namespace, id)
|
||||
|
||||
if @project and (current_user.can_read_project?(@project) || controller_path == "projects/project_invite_links")
|
||||
if @project and current_user.can_read_project?(@project)
|
||||
logger.info "###########: has project and can read project"
|
||||
@project
|
||||
# elsif @project && current_user.is_a?(AnonymousUser)
|
||||
# logger.info "###########:This is AnonymousUser"
|
||||
# @project = nil if !@project.is_public?
|
||||
# render_forbidden and return
|
||||
elsif current_user.is_a?(AnonymousUser)
|
||||
logger.info "###########:This is AnonymousUser"
|
||||
@project = nil if !@project.is_public?
|
||||
render_forbidden and return
|
||||
else
|
||||
if @project.present?
|
||||
logger.info "###########: has project and but can't read project"
|
||||
@project = nil
|
||||
render_forbidden and return
|
||||
else
|
||||
logger.info "###########:project not found"
|
||||
@project = nil
|
||||
render_not_found and return
|
||||
end
|
||||
logger.info "###########:project not found"
|
||||
@project = nil
|
||||
render_not_found and return
|
||||
end
|
||||
@project
|
||||
end
|
||||
|
||||
def load_repository
|
||||
@repository ||= load_project&.repository
|
||||
@repository ||= load_project.repository
|
||||
end
|
||||
|
||||
def 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
|
||||
|
||||
def avatar_path(object)
|
||||
ApplicationController.helpers.disk_filename(object.class, object.id)
|
||||
end
|
||||
|
||||
private
|
||||
def update_last_login_on
|
||||
if current_user.logged?
|
||||
current_user.update_column(:last_login_on, Time.now)
|
||||
end
|
||||
def object_not_found
|
||||
uid_logger("Missing template or cant't find record, responding with 404")
|
||||
render json: {message: "您访问的页面不存在或已被删除", status: 404}
|
||||
false
|
||||
end
|
||||
|
||||
def object_not_found
|
||||
uid_logger("Missing template or cant't find record, responding with 404")
|
||||
render json: {message: "您访问的页面不存在或已被删除", status: 404}
|
||||
false
|
||||
end
|
||||
|
||||
def tip_show(exception)
|
||||
uid_logger("Tip show status is #{exception.status}, message is #{exception.message}")
|
||||
render json: exception.tip_json
|
||||
|
@ -895,327 +817,4 @@ class ApplicationController < ActionController::Base
|
|||
HotSearchKeyword.add(keyword)
|
||||
end
|
||||
|
||||
# author: zxh
|
||||
# blockchain相关项目活动调用函数
|
||||
# return true: 表示上链操作成功; return false: 表示上链操作失败
|
||||
def push_activity_2_blockchain(activity_type, model)
|
||||
if activity_type == "issue_create"
|
||||
|
||||
project_id = model['project_id']
|
||||
project = Project.find(project_id)
|
||||
if project['use_blockchain'] == 0 || project['use_blockchain'] == false
|
||||
# 无需执行上链操作
|
||||
return true
|
||||
end
|
||||
|
||||
id = model['id']
|
||||
|
||||
owner_id = project['user_id']
|
||||
owner = User.find(owner_id)
|
||||
ownername = owner['login']
|
||||
identifier = project['identifier']
|
||||
|
||||
author_id = project['user_id']
|
||||
author = User.find(author_id)
|
||||
username = author['login']
|
||||
|
||||
action = 'opened'
|
||||
|
||||
title = model['subject']
|
||||
content = model['description']
|
||||
created_at = model['created_on']
|
||||
updated_at = model['updated_on']
|
||||
|
||||
# 调用区块链接口
|
||||
params = {
|
||||
"request-type": "upload issue info",
|
||||
"issue_id": "gitlink-" + id.to_s,
|
||||
"repo_id": "gitlink-" + project_id.to_s,
|
||||
"issue_number": 0, # 暂时不需要改字段
|
||||
"reponame": identifier,
|
||||
"ownername": ownername,
|
||||
"username": username,
|
||||
"action": action,
|
||||
"title": title,
|
||||
"content": content,
|
||||
"created_at": created_at,
|
||||
"updated_at": updated_at
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] == 10
|
||||
raise Error, resp_body['message']
|
||||
elsif resp_body['status'] != 0
|
||||
raise Error, "区块链接口请求失败."
|
||||
end
|
||||
|
||||
elsif activity_type == "issue_comment_create"
|
||||
issue_comment_id = model['id']
|
||||
issue_id = model['journalized_id']
|
||||
parent_id = model['parent_id'].nil? ? "" : model['parent_id']
|
||||
|
||||
issue = Issue.find(issue_id)
|
||||
issue_classify = issue['issue_classify'] # issue或pull_request
|
||||
project_id = issue['project_id']
|
||||
project = Project.find(project_id)
|
||||
|
||||
if project['use_blockchain'] == 0 || project['use_blockchain'] == false
|
||||
# 无需执行上链操作
|
||||
return
|
||||
end
|
||||
|
||||
identifier = project['identifier']
|
||||
owner_id = project['user_id']
|
||||
owner = User.find(owner_id)
|
||||
ownername = owner['login']
|
||||
|
||||
author_id = model['user_id']
|
||||
author = User.find(author_id)
|
||||
username = author['login']
|
||||
|
||||
action = 'created'
|
||||
|
||||
content = model['notes']
|
||||
created_at = model['created_on']
|
||||
|
||||
if issue_classify == "issue"
|
||||
params = {
|
||||
"request-type": "upload issue comment info",
|
||||
"issue_comment_id": "gitlink-" + issue_comment_id.to_s,
|
||||
"issue_comment_number": 0, # 暂时不需要
|
||||
"issue_number": 0, # 暂时不需要
|
||||
"issue_id": "gitlink-" + issue_id.to_s,
|
||||
"repo_id": "gitlink-" + project.id.to_s,
|
||||
"parent_id": parent_id.to_s,
|
||||
"reponame": identifier,
|
||||
"ownername": ownername,
|
||||
"username": username,
|
||||
"action": action,
|
||||
"content": content,
|
||||
"created_at": created_at,
|
||||
}.to_json
|
||||
elsif issue_classify == "pull_request"
|
||||
params = {
|
||||
"request-type": "upload pull request comment info",
|
||||
"pull_request_comment_id": "gitlink-" + issue_comment_id.to_s,
|
||||
"pull_request_comment_number": 0, # 不考虑该字段
|
||||
"pull_request_number": 0, # 不考虑该字段
|
||||
"pull_request_id": "gitlink-" + issue_id.to_s,
|
||||
"parent_id": parent_id.to_s,
|
||||
"repo_id": "gitlink-" + project.id.to_s,
|
||||
"reponame": identifier,
|
||||
"ownername": ownername,
|
||||
"username": username,
|
||||
"action": action,
|
||||
"content": content,
|
||||
"created_at": created_at,
|
||||
}.to_json
|
||||
end
|
||||
|
||||
# 调用区块链接口
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] == 10
|
||||
raise Error, resp_body['message']
|
||||
elsif resp_body['status'] != 0
|
||||
raise Error, "区块链接口请求失败."
|
||||
end
|
||||
elsif activity_type == "pull_request_create"
|
||||
# 调用区块链接口
|
||||
project_id = model['project_id']
|
||||
project = Project.find(project_id)
|
||||
if project['use_blockchain'] == 0 || project['use_blockchain'] == false
|
||||
# 无需执行上链操作
|
||||
return
|
||||
end
|
||||
|
||||
pull_request_id = model['id']
|
||||
identifier = project['identifier']
|
||||
owner_id = project['user_id']
|
||||
owner = User.find(owner_id)
|
||||
ownername = owner['login']
|
||||
|
||||
action = 'opened'
|
||||
|
||||
title = model['title']
|
||||
content = model['body']
|
||||
|
||||
source_branch = model['head']
|
||||
source_repo_id = model['fork_project_id'].nil? ? project_id : model['fork_project_id']
|
||||
|
||||
target_branch = model['base']
|
||||
target_repo_id = project_id
|
||||
|
||||
author_id = model['user_id']
|
||||
author = User.find(author_id)
|
||||
username = author['login']
|
||||
|
||||
created_at = model['created_at']
|
||||
updated_at = model['updated_at']
|
||||
|
||||
# 查询pull request对应的commit信息
|
||||
commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number'])
|
||||
if commits.nil?
|
||||
raise Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败
|
||||
end
|
||||
commit_shas = []
|
||||
commits.each do |c|
|
||||
commit_shas << c["Sha"]
|
||||
end
|
||||
params = {
|
||||
"request-type": "upload pull request info",
|
||||
"pull_request_id": "gitlink-" + pull_request_id.to_s,
|
||||
"pull_request_number": 0, # trustie没有该字段
|
||||
"repo_id": "gitlink-" + project_id.to_s,
|
||||
"ownername": ownername,
|
||||
"reponame": identifier,
|
||||
"username": username,
|
||||
"action": action,
|
||||
"title": title,
|
||||
"content": content,
|
||||
"source_branch": source_branch,
|
||||
"target_branch": target_branch,
|
||||
"reviewers": [], # trustie没有该字段
|
||||
"commit_shas": commit_shas,
|
||||
"merge_user": "", # trustie没有该字段
|
||||
"created_at": created_at,
|
||||
"updated_at": updated_at
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] == 9
|
||||
raise Error, resp_body['message']
|
||||
elsif resp_body['status'] != 0
|
||||
raise Error, "区块链接口请求失败."
|
||||
end
|
||||
elsif activity_type == "pull_request_merge"
|
||||
# 调用区块链接口
|
||||
project_id = model['project_id']
|
||||
project = Project.find(project_id)
|
||||
if project['use_blockchain'] == 0 || project['use_blockchain'] == false
|
||||
# 无需执行上链操作
|
||||
return
|
||||
end
|
||||
|
||||
pull_request_id = model['id']
|
||||
identifier = project['identifier']
|
||||
owner_id = project['user_id']
|
||||
owner = User.find(owner_id)
|
||||
ownername = owner['login']
|
||||
|
||||
action = 'merged'
|
||||
|
||||
created_at = model['created_at']
|
||||
updated_at = model['updated_at']
|
||||
|
||||
# 查询pull request对应的commit信息
|
||||
commits = Gitea::PullRequest::CommitsService.call(ownername, identifier, model['gitea_number'])
|
||||
if commits.nil?
|
||||
raise Error, "区块链接口请求失败" # 获取pr中变更的commit信息失败
|
||||
end
|
||||
commit_shas = []
|
||||
commits.each do |c|
|
||||
commit_shas << c["Sha"]
|
||||
end
|
||||
|
||||
# 将pull request相关信息写入链上
|
||||
params = {
|
||||
"request-type": "upload pull request info",
|
||||
"pull_request_id": "gitlink-" + pull_request_id.to_s,
|
||||
"pull_request_number": 0, # trustie没有该字段
|
||||
"repo_id": "gitlink-" + project_id.to_s,
|
||||
"ownername": ownername,
|
||||
"reponame": identifier,
|
||||
"username": username,
|
||||
"action": action,
|
||||
"title": title,
|
||||
"content": content,
|
||||
"source_branch": source_branch,
|
||||
"target_branch": target_branch,
|
||||
"reviewers": [], # trustie没有该字段
|
||||
"commit_shas": commit_shas,
|
||||
"merge_user": "", # trustie没有该字段
|
||||
"created_at": created_at,
|
||||
"updated_at": updated_at
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] == 9
|
||||
raise Error, resp_body['message']
|
||||
elsif resp_body['status'] != 0
|
||||
raise Error, "区块链接口请求失败."
|
||||
end
|
||||
|
||||
|
||||
# 将commit相关信息写入链上
|
||||
commit_shas.each do |commit_sha|
|
||||
commit_diff = Gitea::Commit::DiffService.call(ownername, identifier, commit_sha, owner['gitea_token'])
|
||||
commit = Gitea::Commit::InfoService.call(ownername, identifier, commit_sha, owner['gitea_token'])
|
||||
params = {
|
||||
"request-type": "upload commit info",
|
||||
"commit_hash": commit_sha,
|
||||
"repo_id": "gitlink-" + project_id.to_s,
|
||||
"author": commit['commit']['author']['name'],
|
||||
"author_email": commit['commit']['author']['email'],
|
||||
"committer": commit['commit']['committer']['name'],
|
||||
"committer_email": commit['commit']['committer']['email'],
|
||||
"author_time": commit['commit']['author']['date'],
|
||||
"committer_time": commit['commit']['committer']['date'],
|
||||
"content": commit['commit']['message'],
|
||||
"commit_diff": commit_diff['Files'].to_s
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] == 7
|
||||
raise Error, resp_body['message']
|
||||
elsif resp_body['status'] != 0
|
||||
raise Error, "区块链接口请求失败."
|
||||
end
|
||||
end
|
||||
|
||||
elsif activity_type == "pull_request_refuse"
|
||||
|
||||
# 调用区块链接口
|
||||
project_id = model['project_id']
|
||||
project = Project.find(project_id)
|
||||
if project['use_blockchain'] == 0 || project['use_blockchain'] == false
|
||||
# 无需执行上链操作
|
||||
return true
|
||||
end
|
||||
|
||||
pull_request_id = model['id']
|
||||
identifier = project['identifier']
|
||||
owner_id = project['user_id']
|
||||
owner = User.find(owner_id)
|
||||
ownername = owner['login']
|
||||
|
||||
action = 'refused'
|
||||
|
||||
# 将pull request相关信息写入链上
|
||||
params = {
|
||||
"request-type": "upload pull request info",
|
||||
"pull_request_id": "gitlink-" + pull_request_id.to_s,
|
||||
"pull_request_number": 0, # trustie没有该字段
|
||||
"repo_id": "gitlink-" + project_id.to_s,
|
||||
"ownername": ownername,
|
||||
"reponame": identifier,
|
||||
"username": username,
|
||||
"action": action,
|
||||
"title": title,
|
||||
"content": content,
|
||||
"source_branch": source_branch,
|
||||
"target_branch": target_branch,
|
||||
"reviewers": [], # trustie没有该字段
|
||||
"commit_shas": commit_shas,
|
||||
"merge_user": "", # trustie没有该字段
|
||||
"created_at": created_at,
|
||||
"updated_at": updated_at
|
||||
}.to_json
|
||||
resp_body = Blockchain::InvokeBlockchainApi.call(params)
|
||||
if resp_body['status'] == 9
|
||||
raise Error, resp_body['message']
|
||||
elsif resp_body['status'] != 0
|
||||
raise Error, "区块链接口请求失败."
|
||||
end
|
||||
end
|
||||
end
|
||||
def find_atme_receivers
|
||||
@atme_receivers = User.where(login: params[:receivers_login])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
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
|
|
@ -0,0 +1,16 @@
|
|||
class ApplySignaturesController < ApplicationController
|
||||
def create
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
@signature = current_user.apply_signatures.create!(project_id: params[:project_id])
|
||||
@attachment = Attachment.find_by_id(params[:attachment_id])
|
||||
@attachment.container = @signature
|
||||
@attachment.save!
|
||||
rescue Exception => e
|
||||
tip_exception("#{e}")
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
render_json
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,258 +1,232 @@
|
|||
#coding=utf-8
|
||||
#
|
||||
# 文件上传
|
||||
class AttachmentsController < ApplicationController
|
||||
before_action :require_login, :check_auth, except: [:show, :preview_attachment, :get_file]
|
||||
before_action :find_file, only: %i[show destroy]
|
||||
before_action :attachment_candown, only: [:show]
|
||||
skip_before_action :check_sign, only: [:show, :create]
|
||||
|
||||
include ApplicationHelper
|
||||
|
||||
def show
|
||||
# 1. 优先跳到cdn
|
||||
# 2. 如果没有cdn,send_file
|
||||
if @file.cloud_url.present?
|
||||
update_downloads(@file)
|
||||
redirect_to @file.cloud_url and return
|
||||
end
|
||||
|
||||
type_attachment = params[:disposition] || "attachment"
|
||||
if type_attachment == "inline"
|
||||
send_file absolute_path(local_path(@file)),filename: @file.title, disposition: 'inline',type: 'application/pdf'
|
||||
elsif type_attachment == "MP4"
|
||||
send_file_with_range absolute_path(local_path(@file)), disposition: 'inline', type: "video/mp4", range: true
|
||||
else
|
||||
send_file(absolute_path(local_path(@file)), filename: @file.title,stream:false, type: @file.content_type.presence || 'application/octet-stream')
|
||||
end
|
||||
update_downloads(@file)
|
||||
end
|
||||
|
||||
|
||||
def get_file
|
||||
normal_status(-1, "参数缺失") if params[:download_url].blank?
|
||||
url = base_url.starts_with?("https:") ? URI.encode(params[:download_url].to_s.gsub("http:", "https:")) : URI.encode(params[:download_url].to_s)
|
||||
if url.starts_with?(base_url) && !url.starts_with?("#{base_url}/repo")
|
||||
domain = GiteaService.gitea_config[:domain]
|
||||
api_url = GiteaService.gitea_config[:base_url]
|
||||
url = ("/repos"+url.split(base_url + "/api")[1]).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')
|
||||
end
|
||||
|
||||
def create
|
||||
# 1. 本地存储
|
||||
# 2. 上传到云
|
||||
begin
|
||||
upload_file = params["file"] || params["#{params[:file_param_name]}"]# 这里的file_param_name是为了方便其他插件名称
|
||||
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
|
||||
raise "未上传文件" unless upload_file
|
||||
|
||||
folder = file_storage_directory
|
||||
raise "存储目录未定义" unless folder.present?
|
||||
|
||||
month_folder = current_month_folder
|
||||
save_path = File.join(folder, month_folder)
|
||||
|
||||
ext = file_ext(upload_file.original_filename)
|
||||
|
||||
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
|
||||
|
||||
content_type = upload_file.content_type.presence || 'application/octet-stream'
|
||||
|
||||
# remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type)
|
||||
remote_path = nil # TODO 暂时本地上传,待域名配置后方可上传至云端
|
||||
|
||||
logger.info "local_path: #{local_path}"
|
||||
logger.info "remote_path: #{remote_path}"
|
||||
|
||||
|
||||
disk_filename = local_path[save_path.size + 1, local_path.size]
|
||||
#存数据库
|
||||
#
|
||||
@attachment = Attachment.where(disk_filename: disk_filename,
|
||||
author_id: current_user.id,
|
||||
cloud_url: remote_path).first
|
||||
if @attachment.blank?
|
||||
@attachment = Attachment.new
|
||||
@attachment.filename = upload_file.original_filename
|
||||
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
|
||||
@attachment.filesize = upload_file.tempfile.size
|
||||
@attachment.content_type = content_type
|
||||
@attachment.digest = digest
|
||||
@attachment.author_id = current_user.id
|
||||
@attachment.disk_directory = month_folder
|
||||
@attachment.cloud_url = remote_path
|
||||
@attachment.save!
|
||||
else
|
||||
logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
|
||||
end
|
||||
|
||||
render_json
|
||||
rescue => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
begin
|
||||
@file_path = absolute_path(local_path(@file))
|
||||
#return normal_status(403, "") unless @file.author == current_user
|
||||
@file.destroy!
|
||||
|
||||
delete_file(@file_path)
|
||||
normal_status("删除成功")
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
||||
# 附件为视频时,点击播放
|
||||
def preview_attachment
|
||||
attachment = Attachment.find_by(id: params[:id])
|
||||
dir_path = "#{Rails.root}/public/preview"
|
||||
Dir.mkdir(dir_path) unless Dir.exist?(dir_path)
|
||||
if params[:status] == "preview"
|
||||
if system("cp -r #{absolute_path(local_path(attachment))} #{dir_path}/")
|
||||
render json: {status: 1, url: "/preview/#{attachment.disk_filename}"}
|
||||
else
|
||||
normal_status(-1, "出现错误,请稍后重试")
|
||||
end
|
||||
else
|
||||
if system("rm -rf #{dir_path}/#{attachment.disk_filename}")
|
||||
normal_status(1, "操作成功")
|
||||
else
|
||||
normal_status(-1, "出现错误,请稍后重试")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_file
|
||||
@file =
|
||||
if params[:type] == 'history'
|
||||
AttachmentHistory.find params[:id]
|
||||
else
|
||||
Attachment.find params[:id]
|
||||
end
|
||||
end
|
||||
|
||||
def delete_file(file_path)
|
||||
File.delete(file_path) if File.exist?(file_path)
|
||||
end
|
||||
|
||||
def current_month_folder
|
||||
date = Time.now
|
||||
"#{date.year}/#{date.month.to_s.rjust(2, '0')}"
|
||||
end
|
||||
|
||||
def file_ext(file_name)
|
||||
ext = ''
|
||||
exts = file_name.split(".")
|
||||
if exts.size > 1
|
||||
ext = ".#{exts.last}"
|
||||
end
|
||||
ext
|
||||
end
|
||||
|
||||
def file_save_to_local(save_path, temp_file, ext)
|
||||
unless Dir.exists?(save_path)
|
||||
FileUtils.mkdir_p(save_path) ##不成功这里会抛异常
|
||||
end
|
||||
|
||||
digest = md5_file(temp_file)
|
||||
digest = "#{digest}_#{(Time.now.to_f * 1000).to_i}"
|
||||
local_file_path = File.join(save_path, digest) + ext
|
||||
save_temp_file(temp_file, local_file_path)
|
||||
|
||||
[local_file_path, digest]
|
||||
end
|
||||
|
||||
def save_temp_file(temp_file, save_file_path)
|
||||
File.open(save_file_path, 'wb') do |f|
|
||||
temp_file.rewind
|
||||
while (buffer = temp_file.read(8192))
|
||||
f.write(buffer)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def md5_file(temp_file)
|
||||
md5 = Digest::MD5.new
|
||||
temp_file.rewind
|
||||
while (buffer = temp_file.read(8192))
|
||||
md5.update(buffer)
|
||||
end
|
||||
md5.hexdigest
|
||||
end
|
||||
|
||||
def file_save_to_ucloud(path, file, content_type)
|
||||
ufile = Gitlink::Ufile.new(
|
||||
ucloud_public_key: edu_setting('public_key'),
|
||||
ucloud_private_key: edu_setting('private_key'),
|
||||
ucloud_public_read: true,
|
||||
ucloud_public_bucket: edu_setting('public_bucket'),
|
||||
ucloud_public_bucket_host: edu_setting('public_bucket_host'),
|
||||
ucloud_public_cdn_host: edu_setting('public_cdn_host'),
|
||||
)
|
||||
File.open(file) do |f|
|
||||
ufile.put(path, f, 'Content-Type' => content_type)
|
||||
end
|
||||
edu_setting('public_cdn_host') + "/" + path
|
||||
end
|
||||
|
||||
def attachment_candown
|
||||
unless current_user.admin? || current_user.business?
|
||||
candown = true
|
||||
if @file.container
|
||||
if @file.container.is_a?(Issue)
|
||||
project = @file.container.project
|
||||
candown = project.is_public || (current_user.logged? && project.member?(current_user))
|
||||
elsif @file.container.is_a?(Journal)
|
||||
project = @file.container.issue.project
|
||||
candown = project.is_public || (current_user.logged? && project.member?(current_user))
|
||||
else
|
||||
project = nil
|
||||
end
|
||||
tip_exception(403, "您没有权限进入") if project.present? && !candown
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def send_file_with_range(path, options = {})
|
||||
logger.info("########request.headers: #{request.headers}")
|
||||
logger.info("########request.headers: #{File.exist?(path)}")
|
||||
|
||||
if File.exist?(path)
|
||||
size = File.size(path)
|
||||
logger.info("########request.headers: #{request.headers}")
|
||||
if !request.headers["Range"]
|
||||
status_code = 200 # 200 OK
|
||||
offset = 0
|
||||
length = File.size(path)
|
||||
else
|
||||
status_code = 206 # 206 Partial Content
|
||||
bytes = Rack::Utils.byte_ranges(request.headers, size)[0]
|
||||
offset = bytes.begin
|
||||
length = bytes.end - bytes.begin
|
||||
end
|
||||
response.header["Accept-Ranges"] = "bytes"
|
||||
response.header["Content-Range"] = "bytes #{bytes.begin}-#{bytes.end}/#{size}" if bytes
|
||||
response.header["status"] = status_code
|
||||
|
||||
send_data IO.binread(path, length, offset), options
|
||||
else
|
||||
raise ActionController::MissingFile, "Cannot read file #{path}."
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
#coding=utf-8
|
||||
#
|
||||
# 文件上传
|
||||
class AttachmentsController < ApplicationController
|
||||
before_action :require_login, :check_auth, except: [:show]
|
||||
before_action :find_file, only: %i[show destroy]
|
||||
before_action :attachment_candown, only: [:show]
|
||||
skip_before_action :check_sign, only: [:show, :create]
|
||||
|
||||
include ApplicationHelper
|
||||
|
||||
def show
|
||||
# 1. 优先跳到cdn
|
||||
# 2. 如果没有cdn,send_file
|
||||
if @file.cloud_url.present?
|
||||
update_downloads(@file)
|
||||
redirect_to @file.cloud_url and return
|
||||
end
|
||||
|
||||
type_attachment = params[:disposition] || "attachment"
|
||||
if type_attachment == "inline"
|
||||
send_file absolute_path(local_path(@file)),filename: @file.title, disposition: 'inline',type: 'application/pdf'
|
||||
elsif type_attachment == "MP4"
|
||||
send_file_with_range absolute_path(local_path(@file)), disposition: 'inline', type: "video/mp4", range: true
|
||||
else
|
||||
send_file(absolute_path(local_path(@file)), filename: @file.title,stream:false, type: @file.content_type.presence || 'application/octet-stream')
|
||||
end
|
||||
update_downloads(@file)
|
||||
end
|
||||
|
||||
def create
|
||||
# 1. 本地存储
|
||||
# 2. 上传到云
|
||||
begin
|
||||
upload_file = params["file"] || params["#{params[:file_param_name]}"]# 这里的file_param_name是为了方便其他插件名称
|
||||
dun_check_file = upload_file.dup
|
||||
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
|
||||
raise "未上传文件" unless upload_file
|
||||
|
||||
folder = edu_setting('attachment_folder')
|
||||
raise "存储目录未定义" unless folder.present?
|
||||
|
||||
month_folder = current_month_folder
|
||||
save_path = File.join(folder, month_folder)
|
||||
|
||||
ext = file_ext(upload_file.original_filename)
|
||||
|
||||
local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext)
|
||||
|
||||
content_type = upload_file.content_type.presence || 'application/octet-stream'
|
||||
|
||||
# remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type)
|
||||
remote_path = nil # TODO 暂时本地上传,待域名配置后方可上传至云端
|
||||
|
||||
logger.info "local_path: #{local_path}"
|
||||
logger.info "remote_path: #{remote_path}"
|
||||
|
||||
|
||||
disk_filename = local_path[save_path.size + 1, local_path.size]
|
||||
#存数据库
|
||||
#
|
||||
@attachment = Attachment.where(disk_filename: disk_filename,
|
||||
author_id: current_user.id,
|
||||
cloud_url: remote_path).first
|
||||
if @attachment.blank?
|
||||
@attachment = Attachment.new
|
||||
@attachment.filename = upload_file.original_filename
|
||||
@attachment.disk_filename = local_path[save_path.size + 1, local_path.size]
|
||||
@attachment.filesize = upload_file.tempfile.size
|
||||
@attachment.content_type = content_type
|
||||
@attachment.digest = digest
|
||||
@attachment.author_id = current_user.id
|
||||
@attachment.disk_directory = month_folder
|
||||
# @attachment.cloud_url = remote_path
|
||||
# @attachment.save!
|
||||
if @attachment.save!
|
||||
check_result = Attachment.check_image_able(dun_check_file)
|
||||
if check_result[:status].to_i == -1
|
||||
@attachment.destroy
|
||||
raise "上传失败,#{check_result[:message]}"
|
||||
# return render json: {status: -1, message: "上传失败,#{check_result[:message]}" }
|
||||
end
|
||||
end
|
||||
else
|
||||
logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
|
||||
end
|
||||
|
||||
render_json
|
||||
rescue => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
begin
|
||||
@file_path = absolute_path(local_path(@file))
|
||||
#return normal_status(403, "") unless @file.author == current_user
|
||||
@file.destroy!
|
||||
|
||||
delete_file(@file_path)
|
||||
normal_status("删除成功")
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def find_file
|
||||
@file =
|
||||
if params[:type] == 'history'
|
||||
AttachmentHistory.find params[:id]
|
||||
else
|
||||
Attachment.find params[:id]
|
||||
end
|
||||
end
|
||||
|
||||
def delete_file(file_path)
|
||||
File.delete(file_path) if File.exist?(file_path)
|
||||
end
|
||||
|
||||
def current_month_folder
|
||||
date = Time.now
|
||||
"#{date.year}/#{date.month.to_s.rjust(2, '0')}"
|
||||
end
|
||||
|
||||
def file_ext(file_name)
|
||||
ext = ''
|
||||
exts = file_name.split(".")
|
||||
if exts.size > 1
|
||||
ext = ".#{exts.last}"
|
||||
end
|
||||
ext
|
||||
end
|
||||
|
||||
def file_save_to_local(save_path, temp_file, ext)
|
||||
unless Dir.exists?(save_path)
|
||||
FileUtils.mkdir_p(save_path) ##不成功这里会抛异常
|
||||
end
|
||||
|
||||
digest = md5_file(temp_file)
|
||||
digest = "#{digest}_#{(Time.now.to_f * 1000).to_i}"
|
||||
local_file_path = File.join(save_path, digest) + ext
|
||||
save_temp_file(temp_file, local_file_path)
|
||||
|
||||
[local_file_path, digest]
|
||||
end
|
||||
|
||||
def save_temp_file(temp_file, save_file_path)
|
||||
File.open(save_file_path, 'wb') do |f|
|
||||
temp_file.rewind
|
||||
while (buffer = temp_file.read(8192))
|
||||
f.write(buffer)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def md5_file(temp_file)
|
||||
md5 = Digest::MD5.new
|
||||
temp_file.rewind
|
||||
while (buffer = temp_file.read(8192))
|
||||
md5.update(buffer)
|
||||
end
|
||||
md5.hexdigest
|
||||
end
|
||||
|
||||
def file_save_to_ucloud(path, file, content_type)
|
||||
ufile = Educoder::Ufile.new(
|
||||
ucloud_public_key: edu_setting('public_key'),
|
||||
ucloud_private_key: edu_setting('private_key'),
|
||||
ucloud_public_read: true,
|
||||
ucloud_public_bucket: edu_setting('public_bucket'),
|
||||
ucloud_public_bucket_host: edu_setting('public_bucket_host'),
|
||||
ucloud_public_cdn_host: edu_setting('public_cdn_host'),
|
||||
)
|
||||
File.open(file) do |f|
|
||||
ufile.put(path, f, 'Content-Type' => content_type)
|
||||
end
|
||||
edu_setting('public_cdn_host') + "/" + path
|
||||
end
|
||||
|
||||
def attachment_candown
|
||||
unless current_user.admin? || current_user.business?
|
||||
candown = true
|
||||
unless params[:type] == 'history'
|
||||
if @file.container && current_user.logged?
|
||||
if @file.container.is_a?(Issue)
|
||||
course = @file.container.project
|
||||
candown = course.member?(current_user)
|
||||
elsif @file.container.is_a?(Journal)
|
||||
course = @file.container.issue.project
|
||||
candown = course.member?(current_user)
|
||||
else
|
||||
course = nil
|
||||
end
|
||||
tip_exception(403, "您没有权限进入") if course.present? && !candown
|
||||
tip_exception(403, "您没有权限进入") if @file.container.is_a?(ApplyUserAuthentication)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def send_file_with_range(path, options = {})
|
||||
logger.info("########request.headers: #{request.headers}")
|
||||
logger.info("########request.headers: #{File.exist?(path)}")
|
||||
|
||||
if File.exist?(path)
|
||||
size = File.size(path)
|
||||
logger.info("########request.headers: #{request.headers}")
|
||||
if !request.headers["Range"]
|
||||
status_code = 200 # 200 OK
|
||||
offset = 0
|
||||
length = File.size(path)
|
||||
else
|
||||
status_code = 206 # 206 Partial Content
|
||||
bytes = Rack::Utils.byte_ranges(request.headers, size)[0]
|
||||
offset = bytes.begin
|
||||
length = bytes.end - bytes.begin
|
||||
end
|
||||
response.header["Accept-Ranges"] = "bytes"
|
||||
response.header["Content-Range"] = "bytes #{bytes.begin}-#{bytes.end}/#{size}" if bytes
|
||||
response.header["status"] = status_code
|
||||
|
||||
send_data IO.binread(path, length, offset), options
|
||||
else
|
||||
raise ActionController::MissingFile, "Cannot read file #{path}."
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,19 +1,35 @@
|
|||
class BindUsersController < ApplicationController
|
||||
# before_action :require_login
|
||||
|
||||
def create
|
||||
Rails.logger.debug "--------------开始绑定用户------------"
|
||||
Rails.logger.debug "--------------params: #{params.to_unsafe_h}"
|
||||
tip_exception '系统错误' if session[:unionid].blank?
|
||||
# user = CreateBindUserService.call(create_params)
|
||||
#
|
||||
if params[:type] == "qq"
|
||||
begin
|
||||
user = CreateBindUserService.call(current_user, create_params)
|
||||
successful_authentication(user) if user.id != current_user.id
|
||||
|
||||
bind_user = User.try_to_login(params[:username], params[:password])
|
||||
tip_exception '用户名或者密码错误' if bind_user.blank?
|
||||
tip_exception '用户名或者密码错误' unless bind_user.check_password?(params[:password].to_s)
|
||||
tip_exception '参数错误' unless ["qq", "wechat", "gitee", "github", "educoder"].include?(params[:type].to_s)
|
||||
tip_exception '该账号已被绑定,请更换其他账号进行绑定' if bind_user.bind_open_user?(params[:type].to_s)
|
||||
render_ok
|
||||
rescue ApplicationService::Error => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
else
|
||||
begin
|
||||
tip_exception '系统错误' if session[:unionid].blank?
|
||||
|
||||
"OpenUsers::#{params[:type].to_s.capitalize}".constantize.create!(user: bind_user, uid: session[:unionid])
|
||||
successful_authentication(bind_user)
|
||||
@user = bind_user
|
||||
bind_user = User.try_to_login(params[:username], params[:password])
|
||||
tip_exception '用户名或者密码错误' if bind_user.blank?
|
||||
tip_exception '用户名或者密码错误' unless bind_user.check_password?(params[:password].to_s)
|
||||
tip_exception '该账号已被绑定,请更换其他账号进行绑定' if bind_user.bind_open_user?(params[:type].to_s)
|
||||
|
||||
OpenUsers::Wechat.create!(user: bind_user, uid: session[:unionid])
|
||||
successful_authentication(bind_user)
|
||||
|
||||
render_ok
|
||||
rescue Exception => e
|
||||
render_error(e.message)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def new_user
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
class Blockchain::BaseController < ApplicationController
|
||||
|
||||
before_action :require_login
|
||||
before_action :connect_to_ci_database, if: -> { current_user && !current_user.is_a?(AnonymousUser) && !current_user.devops_uninit? }
|
||||
before_action :connect_to_ci_database, only: :load_repo
|
||||
|
||||
|
||||
def load_repo
|
||||
namespace = params[:owner]
|
||||
id = params[:repo] || params[:id]
|
||||
|
||||
@ci_user, @repo = Ci::Repo.find_with_namespace(namespace, id)
|
||||
end
|
||||
|
||||
private
|
||||
def authorize_access_project!
|
||||
unless @project.manager?(current_user)
|
||||
return render_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
def authenticate_manager!
|
||||
unless @project.manager?(current_user)
|
||||
return render_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
def authenticate_admin!
|
||||
return render_forbidden unless current_user.admin?
|
||||
end
|
||||
|
||||
def authorize_owner!
|
||||
unless @project.owner?(current_user)
|
||||
return render_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
def find_cloud_account
|
||||
@cloud_account ||= current_user.ci_cloud_account
|
||||
@cloud_account.blank? ? nil : @cloud_account
|
||||
end
|
||||
|
||||
def load_ci_user
|
||||
@ci_user ||= Ci::User.find_by(user_login: params[:owner])
|
||||
@ci_user.blank? ? raise("未找到相关的记录") : @ci_user
|
||||
end
|
||||
|
||||
end
|
|
@ -1,7 +0,0 @@
|
|||
class BlockchainController < ApplicationController
|
||||
|
||||
def get_issue_token_num
|
||||
puts "pause"
|
||||
end
|
||||
|
||||
end
|
|
@ -1,76 +0,0 @@
|
|||
class Ci::BaseController < ApplicationController
|
||||
include Ci::DbConnectable
|
||||
|
||||
before_action :require_login
|
||||
before_action :connect_to_ci_db
|
||||
|
||||
def load_repo
|
||||
namespace = params[:owner]
|
||||
id = params[:repo] || params[:id]
|
||||
|
||||
@ci_user, @repo = Ci::Repo.find_with_namespace(namespace, id, current_user.login)
|
||||
end
|
||||
|
||||
def load_all_repo
|
||||
namespace = current_user.login
|
||||
@repos = Ci::Repo.find_all_with_namespace(namespace)
|
||||
end
|
||||
|
||||
def load_repo_by_repo_slug(slug)
|
||||
@repo_slug = Ci::Repo.load_repo_by_repo_slug(slug)
|
||||
end
|
||||
|
||||
private
|
||||
def authorize_access_project!
|
||||
unless @project.manager?(current_user)
|
||||
return render_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
def authenticate_manager!
|
||||
unless @project.manager?(current_user)
|
||||
return render_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
def authenticate_admin!
|
||||
return render_forbidden unless current_user.admin?
|
||||
end
|
||||
|
||||
def authorize_owner!
|
||||
unless @project.owner?(current_user)
|
||||
return render_forbidden
|
||||
end
|
||||
end
|
||||
|
||||
def find_cloud_account
|
||||
@cloud_account ||= current_user.ci_cloud_account
|
||||
@cloud_account.blank? ? nil : @cloud_account
|
||||
end
|
||||
|
||||
def load_ci_user
|
||||
@ci_user ||= Ci::User.find_by(user_login: params[:owner])
|
||||
@ci_user.blank? ? raise("未找到相关的记录") : @ci_user
|
||||
end
|
||||
|
||||
def connect_to_ci_db(options={})
|
||||
current = current_user
|
||||
owner = params[:owner]
|
||||
if owner
|
||||
current = User.find_by(login: owner)
|
||||
end
|
||||
|
||||
if !(current && !current.is_a?(AnonymousUser) && !current.devops_uninit?)
|
||||
return
|
||||
end
|
||||
|
||||
if current.ci_cloud_account.server_type == Ci::CloudAccount::SERVER_TYPE_TRUSTIE
|
||||
connect_to_trustie_ci_database(options)
|
||||
else
|
||||
options = options.merge(db_name: current.login)
|
||||
connect_to_ci_database(options)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
|
@ -1,53 +0,0 @@
|
|||
class Ci::BuildsController < Ci::BaseController
|
||||
include RepositoriesHelper
|
||||
|
||||
before_action :load_project
|
||||
before_action :authorize_owner!, only: [:restart, :stop]
|
||||
before_action :load_repo
|
||||
before_action :find_cloud_account, except: [:index, :show]
|
||||
|
||||
def index
|
||||
@user = current_user
|
||||
|
||||
scope = Ci::Builds::ListQuery.call(@repo, params)
|
||||
|
||||
@total_count = scope.map(&:build_id).size
|
||||
@builds = paginate scope
|
||||
end
|
||||
|
||||
def show
|
||||
@build = @repo.builds.includes(stages: [:steps]).find_by(build_number: params[:build])
|
||||
end
|
||||
|
||||
def restart
|
||||
result = Ci::Drone::API.new(@ci_user.user_hash, @cloud_account.drone_url, @repo.repo_namespace, @repo.repo_name, number: params[:build]).restart
|
||||
|
||||
render json: result
|
||||
end
|
||||
|
||||
def stop
|
||||
result = Ci::Drone::API.new(@ci_user.user_hash, @cloud_account.drone_url, @repo.repo_namespace, @repo.repo_name, number: params[:build]).stop
|
||||
render json: result
|
||||
end
|
||||
|
||||
def logs
|
||||
# TODO **待优化**
|
||||
# 因直接操作ci库,如下查询待优化,可直接根据log id查询即可
|
||||
build = @repo.builds.find_by(build_number: params[:build])
|
||||
return render_not_found("Couldn't found build with 'number'= #{params[:build]}") if build.blank?
|
||||
|
||||
stage = build.stages.includes(steps: [:log]).find_by(stage_number: params[:stage])
|
||||
return render_not_found("Couldn't found build with 'number'= #{params[:stage]}") if stage.blank?
|
||||
|
||||
step = stage.steps.find_by(step_number: params[:step])
|
||||
return render_not_found("Couldn't found build with 'number'= #{params[:step]}") if step.blank?
|
||||
|
||||
log = step.log
|
||||
|
||||
result = log.blank? ? nil : (log.log_data[0..5].include?('null') ? nil : JSON.parse(log.log_data))
|
||||
|
||||
# result = Ci::Drone::API.new(@user.user_hash, @cloud_account.drone_url, @repo.repo_namespace, @repo.repo_name, build: params[:build], stage: params[:stage], step: params[:step]).logs
|
||||
|
||||
render json: result
|
||||
end
|
||||
end
|
|
@ -1,129 +0,0 @@
|
|||
class Ci::CloudAccountsController < Ci::BaseController
|
||||
include Ci::CloudAccountManageable
|
||||
|
||||
skip_before_action :connect_to_ci_db, only: %i[create bind trustie_bind]
|
||||
before_action :load_project, only: %i[create activate]
|
||||
before_action :authorize_owner!, only: %i[create activate]
|
||||
before_action :load_repo, only: %i[activate]
|
||||
before_action :load_all_repo, only: %i[unbind]
|
||||
before_action :find_cloud_account, only: %i[show oauth_grant]
|
||||
before_action :validate_params!, only: %i[create bind]
|
||||
before_action only: %i[create bind] do
|
||||
connect_to_ci_database(master_db: true)
|
||||
end
|
||||
|
||||
def create
|
||||
flag, msg = check_bind_cloud_account!
|
||||
return tip_exception(msg) if flag === true
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
@cloud_account = bind_account!
|
||||
if @cloud_account.blank?
|
||||
tip_exception('激活失败, 请检查你的云服务器信息是否正确.')
|
||||
raise ActiveRecord::Rollback
|
||||
else
|
||||
current_user.set_drone_step!(User::DEVOPS_UNVERIFIED)
|
||||
render_ok(redirect_url: @cloud_account.authenticate_url)
|
||||
end
|
||||
end
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
def activate
|
||||
return tip_exception('请先认证') unless current_user.ci_certification?
|
||||
|
||||
begin
|
||||
@cloud_account = Ci::CloudAccount.find params[:id]
|
||||
ActiveRecord::Base.transaction do
|
||||
if @repo
|
||||
return tip_exception('该项目已经激活') if @repo.repo_active?
|
||||
@repo.activate!(@project)
|
||||
else
|
||||
@repo = Ci::Repo.auto_create!(@ci_user, @project)
|
||||
@user.update_column(:user_syncing, false)
|
||||
end
|
||||
|
||||
result = bind_hook!(current_user, @cloud_account, @repo)
|
||||
@project.update_columns(open_devops: true, gitea_webhook_id: result['id'])
|
||||
@cloud_account.update_column(:ci_user_id, @ci_user.user_id)
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def bind
|
||||
flag, msg = check_bind_cloud_account!
|
||||
return tip_exception(msg) if flag === true
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
@cloud_account = bind_account!
|
||||
if @cloud_account.blank?
|
||||
tip_exception('激活失败, 请检查你的云服务器信息是否正确.')
|
||||
raise ActiveRecord::Rollback
|
||||
else
|
||||
current_user.set_drone_step!(User::DEVOPS_UNVERIFIED)
|
||||
end
|
||||
end
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
def trustie_bind
|
||||
account = params[:account].to_s
|
||||
return tip_exception("account不能为空.") if account.blank?
|
||||
|
||||
flag, msg = check_trustie_bind_cloud_account!
|
||||
return tip_exception(msg) if flag === true
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
@cloud_account = trustie_bind_account!
|
||||
if @cloud_account.blank?
|
||||
tip_exception('激活失败, 请检查你的云服务器信息是否正确.')
|
||||
raise ActiveRecord::Rollback
|
||||
else
|
||||
current_user.set_drone_step!(User::DEVOPS_UNVERIFIED)
|
||||
end
|
||||
end
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
def unbind
|
||||
ActiveRecord::Base.transaction do
|
||||
if current_user.ci_cloud_account.server_type == Ci::CloudAccount::SERVER_TYPE_TRUSTIE
|
||||
if @repos
|
||||
@repos.each do |repo|
|
||||
repo.deactivate!
|
||||
end
|
||||
end
|
||||
end
|
||||
unbind_account!
|
||||
render_ok
|
||||
end
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
def oauth_grant
|
||||
password = params[:password].to_s
|
||||
return tip_exception('你输入的密码不正确.') unless current_user.check_password?(password)
|
||||
|
||||
oauth = current_user.oauths.last
|
||||
return tip_exception("服务器出小差了.") if oauth.blank?
|
||||
|
||||
result = gitea_oauth_grant!(password, oauth)
|
||||
return tip_exception('授权失败.') unless result === true
|
||||
current_user.set_drone_step!(User::DEVOPS_CERTIFICATION)
|
||||
end
|
||||
|
||||
private
|
||||
def validate_params!
|
||||
Ci::CreateCloudAccountForm.new(devops_params).validate!
|
||||
end
|
||||
end
|
|
@ -1,20 +0,0 @@
|
|||
class Ci::LanguagesController < Ci::BaseController
|
||||
# TODO 需要开启权限认证,只有该项目devops初始化成功后才能获取语言列表
|
||||
before_action :find_langugae, only: :show
|
||||
|
||||
def index
|
||||
@languages = Ci::Language.by_usage_amount_desc
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def common
|
||||
@languages = Ci::Language.six_common
|
||||
end
|
||||
|
||||
private
|
||||
def find_langugae
|
||||
@language = Ci::Language.find params[:id]
|
||||
end
|
||||
end
|
|
@ -1,295 +0,0 @@
|
|||
class Ci::PipelinesController < Ci::BaseController
|
||||
|
||||
before_action :require_login, only: %i[list create content]
|
||||
skip_before_action :connect_to_ci_db, except: %i[list create destroy content]
|
||||
before_action :load_project, only: %i[create content]
|
||||
before_action :load_repo, only: %i[create content]
|
||||
|
||||
# ======流水线相关接口========== #
|
||||
def list
|
||||
@result = Array.new
|
||||
list = Ci::Pipeline.where('identifier=? and owner=?', params[:identifier], params[:owner])
|
||||
# 查询build状态
|
||||
list.collect do |pipeline|
|
||||
pipeline.last_build_time = nil
|
||||
repo = load_repo_by_repo_slug("#{pipeline.owner}/#{pipeline.identifier}")
|
||||
if repo
|
||||
build = repo.builds.order("build_created desc").find_by(build_target: pipeline.branch)
|
||||
if build
|
||||
pipeline.pipeline_status = build.build_status
|
||||
pipeline.last_build_time = Time.at(build.build_created)
|
||||
end
|
||||
end
|
||||
@result.push(pipeline)
|
||||
end
|
||||
@total_count = @result.size
|
||||
@pipelines = paginate @result
|
||||
end
|
||||
|
||||
def create
|
||||
ActiveRecord::Base.transaction do
|
||||
size = Ci::Pipeline.where('branch=? and identifier=? and owner=?', params[:branch], params[:repo], params[:owner]).size
|
||||
if size > 0
|
||||
tip_exception("#{params[:branch]}分支已经存在流水线!")
|
||||
return
|
||||
end
|
||||
pipeline = Ci::Pipeline.new(pipeline_name: params[:pipeline_name], file_name: params[:file_name],owner: params[:owner],
|
||||
login: current_user.login, identifier: params[:repo], branch: params[:branch], event: params[:event])
|
||||
pipeline.save!
|
||||
|
||||
# 默认创建四个初始阶段
|
||||
init_stages = Ci::PipelineStage::INIT_STAGES
|
||||
index = 1
|
||||
init_stages.each do |type, name|
|
||||
pipeline.pipeline_stages.build(
|
||||
stage_name: name,
|
||||
stage_type: type,
|
||||
show_index: index
|
||||
).save!
|
||||
index += 1
|
||||
end
|
||||
create_pipeline_file(pipeline)
|
||||
create_ci_repo(pipeline)
|
||||
render_ok({id: pipeline.id})
|
||||
end
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
# 在代码库创建文件
|
||||
def create_pipeline_file(pipeline)
|
||||
sha = get_pipeline_file_sha(pipeline.file_name, pipeline.branch)
|
||||
if sha
|
||||
logger.info "#{pipeline.file_name}已存在"
|
||||
else
|
||||
interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params)
|
||||
if interactor.success?
|
||||
logger.info "#{pipeline.file_name}创建成功"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 在drone数据库repo表新增一条repo记录
|
||||
def create_ci_repo(pipeline)
|
||||
if pipeline.branch != 'master'
|
||||
create_params = {
|
||||
repo_user_id: @ci_user.user_id,
|
||||
repo_namespace: @project.owner.login,
|
||||
repo_name: @project.identifier,
|
||||
repo_slug: "#{@project.owner.login}/#{@project.identifier}-" + pipeline.id.to_s,
|
||||
repo_clone_url: @project.repository.url,
|
||||
repo_branch: pipeline.branch,
|
||||
repo_config: pipeline.file_name
|
||||
}
|
||||
Rails.logger.info("########create_params===#{create_params.to_json}")
|
||||
repo = Ci::Repo.create_repo(create_params)
|
||||
repo
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def get_pipeline_file_sha(file_name, branch)
|
||||
file_path_uri = URI.parse(file_name)
|
||||
interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: branch || 'master')
|
||||
if interactor.success?
|
||||
file = interactor.result
|
||||
file['sha']
|
||||
end
|
||||
end
|
||||
|
||||
def content_params
|
||||
{
|
||||
filepath: params[:file_name],
|
||||
branch: params[:branch],
|
||||
new_branch: params[:new_branch],
|
||||
content: "#pipeline \n",
|
||||
message: 'create pipeline',
|
||||
committer: {
|
||||
email: current_user.mail,
|
||||
name: current_user.login
|
||||
},
|
||||
identifier: params[:repo]
|
||||
}
|
||||
end
|
||||
|
||||
def update
|
||||
pipeline = Ci::Pipeline.find(params[:id])
|
||||
if pipeline
|
||||
pipeline.update!(pipeline_name: params[:pipeline_name],branch: params[:branch], event: params[:event])
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
def destroy
|
||||
pipeline = Ci::Pipeline.find(params[:id])
|
||||
if pipeline
|
||||
repo = load_repo_by_repo_slug("#{pipeline.login}/#{pipeline.identifier}-" + pipeline.id.to_s)
|
||||
if repo
|
||||
repo.destroy!
|
||||
end
|
||||
pipeline.destroy!
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
def content
|
||||
@yaml = "\n"
|
||||
pipeline = Ci::Pipeline.find(params[:id])
|
||||
stages = pipeline.pipeline_stages
|
||||
if stages && !stages.empty?
|
||||
init_step = stages.first.pipeline_stage_steps.first
|
||||
@yaml += init_step.content + "\n" + "steps:\n"
|
||||
stages = stages.slice(1, stages.size - 1)
|
||||
unless stages.empty?
|
||||
stages.each do |stage|
|
||||
steps = stage.pipeline_stage_steps
|
||||
next unless steps && !steps.empty?
|
||||
steps.each do |step|
|
||||
@yaml += step.content + "\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@sha = get_pipeline_file_sha(pipeline.file_name, pipeline.branch)
|
||||
trigger = ''
|
||||
trigger += " branch:\r\n - #{pipeline.branch}\r\n" unless pipeline.branch.blank?
|
||||
unless pipeline.event.blank?
|
||||
trigger += " event:\r\n"
|
||||
pipeline.event.split(',').each { |event| trigger += " - #{event}\r\n"}
|
||||
end
|
||||
@yaml += "trigger:\r\n" + trigger unless trigger.blank?
|
||||
@branch = pipeline.branch
|
||||
end
|
||||
|
||||
# =========阶段相关接口========= #
|
||||
def stages
|
||||
pipeline_id = params[:id]
|
||||
@pipeline_name = Ci::Pipeline.find(pipeline_id).pipeline_name
|
||||
@pipeline_stages = Ci::PipelineStage.where('pipeline_id=?', pipeline_id).order('show_index asc')
|
||||
end
|
||||
|
||||
def create_stage
|
||||
ActiveRecord::Base.transaction do
|
||||
# 修改stage排序
|
||||
update_stage_index(params[:id], params[:show_index], 1)
|
||||
pipeline_stage = Ci::PipelineStage.new(stage_name: params[:stage_name],
|
||||
stage_type: params[:stage_type].blank? ? 'customize' : params[:stage_type],
|
||||
pipeline_id: params[:id], show_index: params[:show_index])
|
||||
pipeline_stage.save!
|
||||
render_ok
|
||||
end
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
def update_stage
|
||||
pipeline_stage = Ci::PipelineStage.find(params[:stage_id])
|
||||
if pipeline_stage
|
||||
pipeline_stage.update!(stage_name: params[:stage_name])
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
def delete_stage
|
||||
ActiveRecord::Base.transaction do
|
||||
update_stage_index(params[:id], params[:show_index].to_i, -1)
|
||||
pipeline_stage = Ci::PipelineStage.find(params[:stage_id])
|
||||
if pipeline_stage
|
||||
pipeline_stage.destroy!
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
def update_stage_index(pipeline_id, show_index, diff)
|
||||
stages = Ci::Pipeline.find(pipeline_id).pipeline_stages
|
||||
stages.each do |stage|
|
||||
if stage.show_index >= show_index
|
||||
stage.update!(show_index: stage.show_index + diff)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# ========步骤相关接口========= #
|
||||
def steps
|
||||
@stage_type = Ci::PipelineStage.find(params[:stage_id]).stage_type
|
||||
@pipeline_stage_steps = Ci::PipelineStageStep.where('stage_id=?', params[:stage_id]).order('show_index asc')
|
||||
end
|
||||
|
||||
def stage_step
|
||||
ActiveRecord::Base.transaction do
|
||||
steps = params[:steps]
|
||||
unless steps.empty?
|
||||
steps.each do |step|
|
||||
unless step[:template_id]
|
||||
tip_exception('请选择模板!')
|
||||
return
|
||||
end
|
||||
if !step[:id]
|
||||
step = Ci::PipelineStageStep.new(step_name: step[:step_name], stage_id: params[:stage_id],
|
||||
template_id: step[:template_id], content: step[:content], show_index: step[:show_index])
|
||||
step.save!
|
||||
else
|
||||
pipeline_stage_step = Ci::PipelineStageStep.find(step[:id])
|
||||
pipeline_stage_step.update(step_name: step[:step_name], content: step[:content],
|
||||
show_index: step[:show_index], template_id: step[:template_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
def create_stage_step
|
||||
ActiveRecord::Base.transaction do
|
||||
steps = params[:steps]
|
||||
unless steps.empty?
|
||||
steps.each do |step|
|
||||
step = Ci::PipelineStageStep.new(step_name: step[:step_name], stage_id: params[:stage_id],
|
||||
template_id: step[:template_id], content: step[:content], show_index: step[:show_index])
|
||||
step.save!
|
||||
end
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
def update_stage_step
|
||||
ActiveRecord::Base.transaction do
|
||||
steps = params[:steps]
|
||||
unless steps.empty?
|
||||
steps.each do |step|
|
||||
pipeline_stage_step = Ci::PipelineStageStep.find(step[:id])
|
||||
if pipeline_stage_step
|
||||
pipeline_stage_step.update(step_name: step[:step_name], content: step[:content], template_id: step[:template_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
|
||||
def delete_stage_step
|
||||
pipeline_stage_step = Ci::PipelineStageStep.find(params[:step_id])
|
||||
if pipeline_stage_step
|
||||
pipeline_stage_step.destroy!
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
end
|
|
@ -1,70 +0,0 @@
|
|||
class Ci::ProjectsController < Ci::BaseController
|
||||
include RepositoriesHelper
|
||||
include Ci::CloudAccountManageable
|
||||
|
||||
before_action :load_project
|
||||
before_action :load_repo, only: [:update_trustie_pipeline, :activate, :deactivate]
|
||||
before_action :authorize_owner!, only: [:authorize]
|
||||
before_action :find_cloud_account, only: [:authorize, :activate, :deactivate]
|
||||
|
||||
def authorize
|
||||
@user = current_user
|
||||
end
|
||||
|
||||
# get .trustie-pipeline.yml file
|
||||
def get_trustie_pipeline
|
||||
file_path_uri = URI.parse('.trustie-pipeline.yml')
|
||||
interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: params[:ref] || "master")
|
||||
if interactor.success?
|
||||
file = interactor.result
|
||||
return render json: {} if file[:status]
|
||||
|
||||
json = {name: file['name'], path: file['path'], sha: file['sha'], content: render_decode64_content(file['content'])}
|
||||
render json: json
|
||||
end
|
||||
end
|
||||
|
||||
def update_trustie_pipeline
|
||||
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, params[:owner], params.merge(identifier: @project.identifier))
|
||||
if interactor.success?
|
||||
@file = interactor.result
|
||||
render_result(1, "更新成功")
|
||||
else
|
||||
tip_exception(interactor.error)
|
||||
end
|
||||
end
|
||||
|
||||
def activate
|
||||
return tip_exception('你还未认证') unless current_user.ci_certification?
|
||||
|
||||
begin
|
||||
ActiveRecord::Base.transaction do
|
||||
if @repo
|
||||
@repo.destroy! if @repo&.repo_user_id == 0
|
||||
return tip_exception('该项目已经激活') if @repo.repo_active?
|
||||
@repo.activate!(@project)
|
||||
else
|
||||
@repo = Ci::Repo.auto_create!(@ci_user, @project)
|
||||
@ci_user.update_column(:user_syncing, false)
|
||||
end
|
||||
|
||||
result = bind_hook!(current_user, @cloud_account, @repo)
|
||||
@project.update_columns(open_devops: true, gitea_webhook_id: result['id'])
|
||||
@project.increment!(:open_devops_count)
|
||||
@cloud_account.update_column(:ci_user_id, @ci_user.user_id)
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => ex
|
||||
tip_exception(ex.message)
|
||||
end
|
||||
end
|
||||
|
||||
def deactivate
|
||||
return tip_exception('该项目已经取消激活') if !@repo.repo_active?
|
||||
|
||||
@project.update_column(:open_devops, false)
|
||||
@repo.deactivate_repos!
|
||||
render_ok
|
||||
end
|
||||
|
||||
end
|
|
@ -1,53 +0,0 @@
|
|||
class Ci::SecretsController < Ci::BaseController
|
||||
|
||||
before_action :load_repo
|
||||
|
||||
# 参数列表
|
||||
def index
|
||||
result = Ci::Drone::API.new(@ci_user.user_hash, ci_drone_url, params[:owner], params[:repo], nil).secrets
|
||||
@secrets = result
|
||||
end
|
||||
|
||||
#新增、更新参数
|
||||
def create
|
||||
options = {
|
||||
name: params[:name],
|
||||
data: params[:data]
|
||||
}
|
||||
id = params[:id]
|
||||
if id
|
||||
result = Ci::Drone::API.new(@ci_user.user_hash, ci_drone_url, params[:owner], params[:repo], options).update_secret
|
||||
if result["id"]
|
||||
render_ok
|
||||
else
|
||||
tip_exception(result["message"])
|
||||
end
|
||||
else
|
||||
result = Ci::Drone::API.new(@ci_user.user_hash, ci_drone_url, params[:owner], params[:repo], options).create_secret
|
||||
if result["id"]
|
||||
render_ok
|
||||
else
|
||||
tip_exception(result["message"])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#删除参数
|
||||
def destroy
|
||||
name = params[:name]
|
||||
if !name.blank?
|
||||
Ci::Drone::API.new(@ci_user.user_hash, ci_drone_url, params[:owner], params[:repo], {name: name}).delete_secret
|
||||
render_ok
|
||||
else
|
||||
tip_exception("参数名不能为空")
|
||||
end
|
||||
rescue Exception => ex
|
||||
render_ok
|
||||
end
|
||||
|
||||
def ci_drone_url
|
||||
user = User.find_by(login: params[:owner]) || User.find_by(login: current_user.login)
|
||||
user&.ci_cloud_account.drone_url
|
||||
end
|
||||
|
||||
end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue