Fakultas Ilmu Komputer UI

Commit 87843815 authored by M. Reza Qorib's avatar M. Reza Qorib
Browse files

Merge branch 'UserStory2' of https://gitlab.com/PPL2017csui/PPLA1 into UserStory2

# Conflicts:
#	assets/js/components/Lowongan.jsx
parents c1800905 440a3b36
......@@ -100,22 +100,32 @@ font-size: 30px;
}
.coverLetter{
margin-top:15px;
margin-top:30px;
}
.linkCV{
float: right;
margin-top: 10px;
margin-top: 30px;
margin-bottom: 10px;
}
.registerForm{
width: 800px;
margin: 0 auto;
padding:50px;
background-color: #3B8686;
}
item{
color:black;
}
textarea{
width: 800px !important;
height: 160px !important;
}
.register{
background-color:#3B8686;
......@@ -142,4 +152,8 @@ input.active:invalid {
card .formRegis{
margin-top: 100px;
}
itemLowongan{
color: black;
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ export default class Dashboard extends React.Component {
render = () => (
<div>
<TopMenu color="blue" />
<TopMenu />
{this.props.children}
</div>
)
......
......@@ -7,7 +7,6 @@ import Login from './Login';
import VacancyPage from './VacancyPage';
import CompanyRegister from './CompanyRegister';
import Server from './lib/Server';
// import Register from './CompanyRegister'
export const Profile = () => (
<Segment>
......@@ -22,12 +21,17 @@ export default class App extends React.Component {
super(props);
/* istanbul ignore next */
this.handleAuth = this.handleAuth.bind(this);
this.handleHome = this.handleHome.bind(this);
}
handleAuth = (nextState, replace) => (
Server.isLoggedIn() || replace({ pathname: '/login' })
);
handleHome= (nextState, replace) => (
Server.isLoggedIn() ? replace({ pathname: '/lowongan' }) : replace({ pathname: '/login' })
);
render = () => (
<Router history={browserHistory}>
......@@ -35,11 +39,12 @@ export default class App extends React.Component {
<Route path="/register" component={CompanyRegister} />
<Route component={Dashboard} onEnter={this.handleAuth}>
<Route path="/" component={Profile} />
<Route path="profile" component={Profile} />
<Route path="lowongan" component={VacancyPage} />
<Route path="users" component={Profile} />
<Route path="/profile" component={Profile} />
<Route path="/lowongan" component={VacancyPage} />
<Route path="/users" component={Profile} />
</Route>
<Redirect from="*" to="/login" />
<Route path="/home" onEnter={this.handleHome} />
<Redirect from="*" to="/home" />
</Router>
);
}
......
......@@ -2,6 +2,7 @@ import React from 'react';
import { Form, Input, Button, Message, Image } from 'semantic-ui-react';
import { browserHistory } from 'react-router';
import Server from '../lib/Server';
import Storage from '../lib/Storage';
export default class LoginForm extends React.Component {
......@@ -21,7 +22,7 @@ export default class LoginForm extends React.Component {
constructor(props) {
super(props);
/* istanbul ignore next */
this.state = { email: '', password: '', errorFlag: false };
this.state = { username: '', password: '', errorFlag: false };
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
......@@ -33,11 +34,13 @@ export default class LoginForm extends React.Component {
handleSubmit(event) {
event.preventDefault();
const data = {
type: this.props.type,
email: this.state.email,
'login-type': this.props.type,
username: this.state.username,
password: this.state.password,
};
Server.post('api/login/', data).then(() => {
Server.post('/login/', data).then((response) => {
Storage.set('user-data', response);
browserHistory.push('/home');
}, () => {
this.setState({ errorFlag: true });
......@@ -52,8 +55,8 @@ export default class LoginForm extends React.Component {
</div>
<Form.Group widths="equal">
<Form.Field required>
<label htmlFor="id"> Email </label>
<Input type="text" id="email" icon="user" iconPosition="left" placeholder="email" onChange={e => this.handleChange(e, 'email')} required />
<label htmlFor="id"> Username </label>
<Input type="text" id="username" icon="user" iconPosition="left" placeholder="username" onChange={e => this.handleChange(e, 'username')} required />
</Form.Field>
</Form.Group>
......@@ -67,7 +70,7 @@ export default class LoginForm extends React.Component {
<Button type="submit" fluid color="blue">Login</Button>
<Message
error
content="Login gagal: email atau password salah."
content="Login gagal: username atau password salah."
/>
</Form>
......
import React from 'react';
import { Button, Image as ImageComponent, Item, Rating } from 'semantic-ui-react'
import ModalPendaftaran from './ModalPendaftaran';
const paragraph = <ImageComponent src="http://semantic-ui.com/images/wireframe/short-paragraph.png" />;
const image = <Item.Image size="small" src="http://semantic-ui.com/images/wireframe/image.png" />;
export default class Lowongan extends React.Component {
static propTypes = {
data: React.PropTypes.object.isRequired,
};
render() {
return (
<Item >
{image}
<Item.Content verticalAlign="middle">
<Item.Header>
{this.props.header}
</Item.Header>
<Item.Description>{this.props.content}</Item.Description>
<Item.Content>
<h3>{ this.props.data.data1 }</h3>
<h4>PT. Koding Kuat </h4>
<h5> JL.Kali deres utara no.1 Jakarta Barat, DKI Jakarta</h5>
<ModalPendaftaran id={1} data={ { header: 'Deskripsi Lowongan', description: 'Lorem ipsum dolor sit amet'} } buttonTitle="Daftar" />
</Item.Content>
</Item.Content>
</Item>
);
}
}
\ No newline at end of file
......@@ -46,26 +46,28 @@ export default class ModalPendaftaran extends React.Component {
>
<Modal.Header>{this.props.data.header}</Modal.Header>
<Modal.Content image>
<div className="image">
<Icon name="right arrow" />
</div>
<Modal.Content>
<Modal.Description>
<Modal.Header> <h3> Deskripsi Lowongan </h3></Modal.Header>
{this.props.data.description}
<div className="linkCV">
</Modal.Description>
<div className="coverLetter">
<div className="linkCV">
<a> your latest CV </a>
</div>
<div className="coverLetter">
<h5> Write your Cover Letter </h5>
<Form>
<TextArea placeholder="Tell us more" onChange={this.handleChange} />
<Form >
<TextArea placeholder="Tell us more" size='big' />
</Form>
</div>
</Modal.Description>
</Modal.Content>
<Modal.Actions>
<ModalAlert
......
import React from 'react';
import { Menu, Image } from 'semantic-ui-react';
import { Link } from 'react-router';
import { Link, browserHistory } from 'react-router';
import Server from '../lib/Server';
import Storage from '../lib/Storage';
export default class TopMenu extends React.Component {
state = { activeItem: 'home' };
constructor(props) {
super(props);
/* istanbul ignore next */
this.logout = this.logout.bind(this);
}
handleItemClick = (e, { name2 }) => this.setState({ activeItem: name })
logout = () => {
Server.get('/api-auth/logout/?next=/', true).then(() => {
Storage.clear();
browserHistory.push('/login');
});
};
render() {
const { activeItem } = this.state
return (
<Menu pointing secondary>
<Menu color="blue" pointing secondary>
<Image as="a" size="small" src="/assets/img/logo.png" href="/" />
<Menu.Menu position="right">
<Menu.Item as={Link} to="/lowongan" name="home" />
<Menu.Item as={Link} to="/profile" name="profil" />
{Server.isLoggedIn() ?
<Menu.Item as={Link} href="/api/api-auth/logout/?next=/" name="logout" /> :
<Menu.Item as={Link} to="/login" name="login" />
}
<Menu.Item as={Link} to="/lowongan" name="home" onClick={this.handleItemClick} />
<Menu.Item as={Link} to="/profile" name="profil" onClick={this.handleItemClick} />
<Menu.Item as={Link} onClick={this.logout} name="logout" />
</Menu.Menu>
</Menu>
);
......
......@@ -26,6 +26,7 @@ export default class VacancyList extends React.Component {
);
}
render = () => {
return (
<Item.Group relaxed>
......
......@@ -44,7 +44,7 @@ export default class Server {
if (response.status === 204) {
return response;
}
return response.json();
return response.hasOwnProperty(response) ? response.json() : response;
});
/* istanbul ignore next */
......
# __init__.py
from core.tests.test_login import LoginTests
from core.tests.test_accounts import LoginTests
from core.tests.test_vacancies import ApplicationTests, BookmarkApplicationTests
import requests_mock
from rest_framework import status
from rest_framework.test import APITestCase
from django.contrib.auth.models import User
from core.models.accounts import Company
class LoginTests(APITestCase):
@requests_mock.Mocker()
def test_login(self, m):
def test_succesful_student_login_relogin(self, m):
"""
Ensure we can login
"""
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', [{'json': {
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
"username": "dummy.mahasiswa",
"nama": "Dummy Mahasiswa",
"state": 1,
"kode_org": "01.00.12.01:mahasiswa",
"kodeidentitas": "1234567890",
"nama_role": "mahasiswa"
}, 'status_code': 200}, {'json': {
"username": "dummy.mahasiswa",
"nama": "Dummy Mahasiswa",
"state": 1,
"kode_org": "01.00.12.01:mahasiswa",
"kodeidentitas": "1234567890",
"nama_role": "mahasiswa"
}, 'status_code': 200}, {'json': {
"username": "dummy.dosen",
"nama": "Dummy Dosen",
"state": 1,
"kode_org": "01.00.12.01:dosen",
"kodeidentitas": "1234567820",
"nama_role": "dosen"
}, 'status_code': 200}, {'json': {
"state": 0
}, 'status_code': 200}])
}, status_code=200)
url = '/api/login/'
response = self.client.post(url, { 'username' : 'dummy.mahasiswa', 'password' : 'lalala', 'login-type' : 'sso-ui'}, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
format='json')
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
@requests_mock.Mocker()
def test_successful_supervisor_login_relogin(self, m):
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
"username": "dummy.dosen",
"nama": "Dummy Dosen",
"state": 1,
"kode_org": "01.00.12.01:dosen",
"kodeidentitas": "1234567891",
"nama_role": "dosen"
}, status_code=200)
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.dosen', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
response = self.client.post(url, {'username': 'dummy.dosen', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
@requests_mock.Mocker()
def test_failed_sso_login(self, m):
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
"state": 0
}, status_code=200)
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.salah', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
response = self.client.post(url, {'username': 'dummy.perusahaan.salah', 'password': 'lalala', 'login-type': 'perusahaan'}, format='json')
def test_failed_company_login(self):
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.company.failed', 'password': 'lalala', 'login-type': 'company'}, format='json')
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
def test_success_company_login(self):
new_user = User.objects.create_user('dummy.login.company', 'dummy.login.company@company.com', 'lalala123')
new_company = Company.objects.create(user=new_user, description="lalalala", verified=True, logo=None, alamat=None)
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.login.company', 'password': 'lalala123', 'login-type': 'company'}, format='json')
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
def test_bad_request(self):
url = '/api/login/'
response = self.client.post(url, {'uesrname': 'lalala'}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
\ No newline at end of file
from datetime import datetime
import requests_mock
from rest_framework import status
from rest_framework.test import APITestCase
from django.contrib.auth.models import User
from core.models.accounts import Company
from core.models.vacancies import Vacancy
class ApplicationTests(APITestCase):
@requests_mock.Mocker()
def test_application_list(self, m):
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
"username": "dummy.mahasiswa",
"nama": "Dummy Mahasiswa",
"state": 1,
"kode_org": "01.00.12.01:mahasiswa",
"kodeidentitas": "1234567890",
"nama_role": "mahasiswa"
}, status_code=200)
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
student_id = response.data.get('student').get('id')
url = '/api/students/' + str(student_id) + '/applications/'
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
@requests_mock.Mocker()
def test_application_create_and_delete(self, m):
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
"username": "dummy.mahasiswa",
"nama": "Dummy Mahasiswa",
"state": 1,
"kode_org": "01.00.12.01:mahasiswa",
"kodeidentitas": "1234567890",
"nama_role": "mahasiswa"
}, status_code=200)
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
format='json')
student_id = response.data.get('student').get('id')
new_user = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123')
new_company = Company.objects.create(user=new_user, description="lalala",verified=True,logo=None,alamat=None)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0), description="lalala", close_time=datetime.today())
url = '/api/students/' + str(student_id) + '/applications/'
response = self.client.post(url, {'vacancy_id' : new_vacancy.pk}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
url = '/api/students/' + str(student_id) + '/applications/' + str(new_vacancy.pk) + '/'
response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
class BookmarkApplicationTests(APITestCase):
@requests_mock.Mocker()
def test_application_list(self, m):
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
"username": "dummy.mahasiswa",
"nama": "Dummy Mahasiswa",
"state": 1,
"kode_org": "01.00.12.01:mahasiswa",
"kodeidentitas": "1234567890",
"nama_role": "mahasiswa"
}, status_code=200)
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'}, format='json')
student_id = response.data.get('student').get('id')
url = '/api/students/' + str(student_id) + '/bookmarked-vacancies/'
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
@requests_mock.Mocker()
def test_application_create_and_delete(self, m):
m.post('https://api.cs.ui.ac.id/authentication/ldap/v2/', json={
"username": "dummy.mahasiswa",
"nama": "Dummy Mahasiswa",
"state": 1,
"kode_org": "01.00.12.01:mahasiswa",
"kodeidentitas": "1234567890",
"nama_role": "mahasiswa"
}, status_code=200)
url = '/api/login/'
response = self.client.post(url, {'username': 'dummy.mahasiswa', 'password': 'lalala', 'login-type': 'sso-ui'},
format='json')
student_id = response.data.get('student').get('id')
new_user = User.objects.create_user('dummy.company', 'dummy.company@company.com', 'lalala123')
new_company = Company.objects.create(user=new_user, description="lalala",verified=True,logo=None,alamat=None)
new_vacancy = Vacancy.objects.create(company=new_company, verified=True, open_time=datetime.fromtimestamp(0), description="lalala", close_time=datetime.today())
url = '/api/students/' + str(student_id) + '/bookmarked-vacancies/'
response = self.client.post(url, {'vacancy_id' : new_vacancy.pk}, format='json')
self.assertEqual(response.status_code, status.HTTP_200_OK)
url = '/api/students/' + str(student_id) + '/bookmarked-vacancies/' + str(new_vacancy.pk) + '/'
response = self.client.delete(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
......@@ -31,6 +31,7 @@ class UserViewSet(viewsets.ModelViewSet):
return [AllowAny()]
return super(UserViewSet, self).get_permissions()
class StudentViewSet(viewsets.ModelViewSet):
queryset = Student.objects.all()
serializer_class = StudentSerializer
......
from rest_framework import viewsets
from rest_framework.generics import get_object_or_404
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from core.lib.permissions import IsAdminOrStudent, IsAdminOrCompany
......@@ -13,6 +14,11 @@ class VacancyViewSet(viewsets.ModelViewSet):
serializer_class = VacancySerializer
permission_classes = [IsAdminOrCompany]
def get_permissions(self):
if self.action in ["get", "list"]:
return [IsAuthenticated()]
return super(VacancyViewSet, self).get_permissions()
class ApplicationViewSet(viewsets.GenericViewSet):
serializer_class = VacancySerializer
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment