mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Merge branch 'develop' into fixes/advanced_search_serial_v2
This commit is contained in:
commit
371a39a118
|
@ -2362,6 +2362,15 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"login": "Delta5",
|
||||||
|
"name": "Evan Taylor",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/1975640?v=4",
|
||||||
|
"profile": "https://github.com/Delta5",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
"login": "PetriAsi",
|
"login": "PetriAsi",
|
||||||
"name": "Petri Asikainen",
|
"name": "Petri Asikainen",
|
||||||
"avatar_url": "https://avatars.githubusercontent.com/u/8735148?v=4",
|
"avatar_url": "https://avatars.githubusercontent.com/u/8735148?v=4",
|
||||||
|
@ -2378,6 +2387,96 @@
|
||||||
"contributions": [
|
"contributions": [
|
||||||
"code"
|
"code"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "vapier",
|
||||||
|
"name": "Mike Frysinger",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/176950?v=4",
|
||||||
|
"profile": "https://wh0rd.org/",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "AL4AL",
|
||||||
|
"name": "ALPHA",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/22044358?v=4",
|
||||||
|
"profile": "https://github.com/AL4AL",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "FliegenKLATSCH",
|
||||||
|
"name": "FliegenKLATSCH",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/1042587?v=4",
|
||||||
|
"profile": "https://www.ifern.de",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "jerm",
|
||||||
|
"name": "Jeremy Price",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/442138?v=4",
|
||||||
|
"profile": "https://github.com/jerm",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "Toreg87",
|
||||||
|
"name": "Toreg87",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/84392209?v=4",
|
||||||
|
"profile": "https://github.com/Toreg87",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "Computroniks",
|
||||||
|
"name": "Matthew Nickson",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/67638596?v=4",
|
||||||
|
"profile": "https://github.com/Computroniks",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "jethron",
|
||||||
|
"name": "Jethro Nederhof",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/1646397?v=4",
|
||||||
|
"profile": "https://jethron.id.au",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "01ste02",
|
||||||
|
"name": "Oskar Stenberg",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/23289826?v=4",
|
||||||
|
"profile": "https://github.com/01ste02",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "Robert-Azelis",
|
||||||
|
"name": "Robert-Azelis",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/82208283?v=4",
|
||||||
|
"profile": "https://github.com/Robert-Azelis",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "alwism",
|
||||||
|
"name": "Alexander William Smith",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/60648387?v=4",
|
||||||
|
"profile": "https://github.com/alwism",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
62
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
62
.github/ISSUE_TEMPLATE/Bug_report.md
vendored
|
@ -1,62 +0,0 @@
|
||||||
---
|
|
||||||
name: Bug report
|
|
||||||
about: Create a report to help us improve
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
#### Please confirm you have done the following before posting your bug report:
|
|
||||||
|
|
||||||
- [ ] I have enabled debug mode
|
|
||||||
- [ ] I have read [checked the Common Issues page](https://snipe-it.readme.io/docs/common-issues)
|
|
||||||
|
|
||||||
**Describe the bug**
|
|
||||||
A clear and concise description of what the bug is.
|
|
||||||
|
|
||||||
**To Reproduce**
|
|
||||||
Steps to reproduce the behavior:
|
|
||||||
1. Go to '...'
|
|
||||||
2. Click on '....'
|
|
||||||
3. Scroll down to '....'
|
|
||||||
4. See error
|
|
||||||
|
|
||||||
**Expected behavior**
|
|
||||||
A clear and concise description of what you expected to happen.
|
|
||||||
|
|
||||||
**Screenshots**
|
|
||||||
If applicable, add screenshots to help explain your problem.
|
|
||||||
|
|
||||||
**Server (please complete the following information):**
|
|
||||||
- Snipe-IT Version
|
|
||||||
- OS: [e.g. Ubuntu, CentOS]
|
|
||||||
- Web Server: [e.g. Apache, IIS]
|
|
||||||
- PHP Version
|
|
||||||
|
|
||||||
**Desktop (please complete the following information):**
|
|
||||||
- OS: [e.g. iOS]
|
|
||||||
- Browser [e.g. chrome, safari]
|
|
||||||
- Version [e.g. 22]
|
|
||||||
|
|
||||||
**Smartphone (please complete the following information):**
|
|
||||||
- Device: [e.g. iPhone6]
|
|
||||||
- OS: [e.g. iOS8.1]
|
|
||||||
- Browser [e.g. stock browser, safari]
|
|
||||||
- Version [e.g. 22]
|
|
||||||
|
|
||||||
**Error Messages**
|
|
||||||
- WITH DEBUG TURNED ON, if you're getting an error in your browser, include that error
|
|
||||||
- If a stacktrace is provided in the error, include that too.
|
|
||||||
- Any errors that appear in your browser's error console.
|
|
||||||
- Confirm whether the error is reproducible on the demo: https://snipeitapp.com/demo.
|
|
||||||
- Include any additional information you can find in `storage/logs` and your webserver's logs.
|
|
||||||
- Include the output from `php -m` (this should display what modules you have enabled.)
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
- Is this a fresh install or an upgrade?
|
|
||||||
- What OS and web server you're running Snipe-IT on
|
|
||||||
- What method you used to install Snipe-IT (install.sh, manual installation, docker, etc)
|
|
||||||
- Include what you've done so far in the installation, and if you got any error messages along the way.
|
|
||||||
- Indicate whether or not you've manually edited any data directly in the database
|
|
||||||
|
|
||||||
Add any other context about the problem here.
|
|
||||||
|
|
||||||
Please do not post an issue without answering the related questions above. If you have opened a different issue and already answered these questions, answer them again, once for every ticket. It will be next to impossible for us to help you.
|
|
23
.github/ISSUE_TEMPLATE/Feature_request.md
vendored
23
.github/ISSUE_TEMPLATE/Feature_request.md
vendored
|
@ -1,23 +0,0 @@
|
||||||
---
|
|
||||||
name: Feature request
|
|
||||||
about: Suggest an idea for this project
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**Server (please complete the following information):**
|
|
||||||
- Snipe-IT Version
|
|
||||||
- OS: [e.g. Ubuntu, CentOS]
|
|
||||||
- Web Server: [e.g. Apache, IIS]
|
|
||||||
- PHP Version
|
|
||||||
|
|
||||||
**Is your feature request related to a problem? Please describe.**
|
|
||||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
|
||||||
|
|
||||||
**Describe the solution you'd like**
|
|
||||||
A clear and concise description of what you want to happen.
|
|
||||||
|
|
||||||
**Describe alternatives you've considered**
|
|
||||||
A clear and concise description of any alternative solutions or features you've considered.
|
|
||||||
|
|
||||||
**Additional context**
|
|
||||||
Add any other context or screenshots about the feature request here.
|
|
129
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
129
.github/ISSUE_TEMPLATE/bug_report.yml
vendored
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
name: Bug Report
|
||||||
|
description: Create a report to help us improve
|
||||||
|
body:
|
||||||
|
- type: checkboxes
|
||||||
|
attributes:
|
||||||
|
label: Debug mode
|
||||||
|
description: Please confirm you have done the following before posting your bug report
|
||||||
|
options:
|
||||||
|
- label: I have enabled debug mode
|
||||||
|
required: true
|
||||||
|
- label: I have read [checked the Common Issues page](https://snipe-it.readme.io/docs/common-issues)
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Describe the bug
|
||||||
|
description: A clear and concise description of what the bug is.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Reproduction steps
|
||||||
|
description: Steps to reproduce the behavior.
|
||||||
|
value: |
|
||||||
|
1.
|
||||||
|
2.
|
||||||
|
3.
|
||||||
|
...
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Expected behavior
|
||||||
|
description: A clear and concise description of what you expected to happen.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Screenshots
|
||||||
|
description: 'If applicable, add screenshots to help explain your problem.'
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: "### Server"
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: Snipe-IT Version
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: server_operatingSystem
|
||||||
|
attributes:
|
||||||
|
label: Operating System
|
||||||
|
description: 'e.g. Ubuntu, Windows'
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: Web Server
|
||||||
|
description: 'e.g. Apache, IIS'
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: PHP Version
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: "### Desktop"
|
||||||
|
- type: input
|
||||||
|
id: desktop_operatingSystem
|
||||||
|
attributes:
|
||||||
|
label: Operating System
|
||||||
|
description: 'e.g. Ubuntu, Windows'
|
||||||
|
- type: input
|
||||||
|
id: desktop_browser
|
||||||
|
attributes:
|
||||||
|
label: Browser
|
||||||
|
description: 'e.g. Google Chrome, Safari'
|
||||||
|
- type: input
|
||||||
|
id: desktop_version
|
||||||
|
attributes:
|
||||||
|
label: Version
|
||||||
|
description: 'e.g. 93'
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: "### Mobile"
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: Device
|
||||||
|
description: 'e.g. iPhone 6, Pixel 4a'
|
||||||
|
- type: input
|
||||||
|
id: mobile_operatingSystem
|
||||||
|
attributes:
|
||||||
|
label: Operating System
|
||||||
|
description: 'e.g. iOS 8.1, Android 9'
|
||||||
|
- type: input
|
||||||
|
id: mobile_browser
|
||||||
|
attributes:
|
||||||
|
label: Browser
|
||||||
|
description: 'e.g. Google Chrome, Safari'
|
||||||
|
- type: input
|
||||||
|
id: mobile_version
|
||||||
|
attributes:
|
||||||
|
label: Version
|
||||||
|
description: 'e.g. 93'
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Error messages
|
||||||
|
description: |
|
||||||
|
WITH DEBUG TURNED ON, if you're getting an error in your browser, include that error
|
||||||
|
If a stacktrace is provided in the error, include that too.
|
||||||
|
Any errors that appear in your browser's error console.
|
||||||
|
Confirm whether the error is reproducible on the demo: https://snipeitapp.com/demo.
|
||||||
|
Include any additional information you can find in `storage/logs` and your webserver's logs.
|
||||||
|
Include the output from `php -m` (this should display what modules you have enabled.)
|
||||||
|
render: shell
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Additional context
|
||||||
|
description: |
|
||||||
|
Is this a fresh install or an upgrade?
|
||||||
|
What OS and web server you're running Snipe-IT on
|
||||||
|
What method you used to install Snipe-IT (install.sh, manual installation, docker, etc)
|
||||||
|
Include what you've done so far in the installation, and if you got any error messages along the way.
|
||||||
|
Indicate whether or not you've manually edited any data directly in the database
|
||||||
|
Add any other context about the problem here.
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: Please do not post an issue without answering the related questions above. If you have opened a different issue and already answered these questions, answer them again, once for every ticket. It will be next to impossible for us to help you.
|
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
blank_issues_enabled: false
|
42
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
42
.github/ISSUE_TEMPLATE/feature_request.yml
vendored
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
name: Feature Request
|
||||||
|
description: Suggest an idea for this project
|
||||||
|
body:
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: Snipe-IT Version
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: server_operatingSystem
|
||||||
|
attributes:
|
||||||
|
label: Operating System
|
||||||
|
description: 'e.g. Ubuntu, Windows'
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: Web Server
|
||||||
|
description: 'e.g. Apache, IIS'
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
attributes:
|
||||||
|
label: PHP Version
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Describe the solution you'd like A clear and concise description of what you want to happen.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
- type: textarea
|
||||||
|
attributes:
|
||||||
|
label: Additional context Add any other context or screenshots about the feature request here.
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -63,3 +63,5 @@ _ide_helper.php
|
||||||
.phpstorm.meta.php
|
.phpstorm.meta.php
|
||||||
_ide_helper_models.php
|
_ide_helper_models.php
|
||||||
/.phplint-cache
|
/.phplint-cache
|
||||||
|
storage/ldap_client_tls.cert
|
||||||
|
storage/ldap_client_tls.key
|
||||||
|
|
34
Dockerfile
34
Dockerfile
|
@ -1,5 +1,5 @@
|
||||||
FROM ubuntu:bionic
|
FROM ubuntu:20.04
|
||||||
LABEL maintainer Brady Wetherington <uberbrady@gmail.com>
|
LABEL maintainer="Brady Wetherington <bwetherington@grokability.com>"
|
||||||
|
|
||||||
# No need to add `apt-get clean` here, reference:
|
# No need to add `apt-get clean` here, reference:
|
||||||
# - https://github.com/snipe/snipe-it/pull/9201
|
# - https://github.com/snipe/snipe-it/pull/9201
|
||||||
|
@ -14,15 +14,15 @@ RUN export DEBIAN_FRONTEND=noninteractive; \
|
||||||
apt-utils \
|
apt-utils \
|
||||||
apache2 \
|
apache2 \
|
||||||
apache2-bin \
|
apache2-bin \
|
||||||
libapache2-mod-php7.2 \
|
libapache2-mod-php7.4 \
|
||||||
php7.2-curl \
|
php7.4-curl \
|
||||||
php7.2-ldap \
|
php7.4-ldap \
|
||||||
php7.2-mysql \
|
php7.4-mysql \
|
||||||
php7.2-gd \
|
php7.4-gd \
|
||||||
php7.2-xml \
|
php7.4-xml \
|
||||||
php7.2-mbstring \
|
php7.4-mbstring \
|
||||||
php7.2-zip \
|
php7.4-zip \
|
||||||
php7.2-bcmath \
|
php7.4-bcmath \
|
||||||
patch \
|
patch \
|
||||||
curl \
|
curl \
|
||||||
wget \
|
wget \
|
||||||
|
@ -38,7 +38,7 @@ autoconf \
|
||||||
libc-dev \
|
libc-dev \
|
||||||
pkg-config \
|
pkg-config \
|
||||||
libmcrypt-dev \
|
libmcrypt-dev \
|
||||||
php7.2-dev \
|
php7.4-dev \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
unzip \
|
unzip \
|
||||||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||||
|
@ -47,16 +47,16 @@ unzip \
|
||||||
RUN curl -L -O https://github.com/pear/pearweb_phars/raw/master/go-pear.phar
|
RUN curl -L -O https://github.com/pear/pearweb_phars/raw/master/go-pear.phar
|
||||||
RUN php go-pear.phar
|
RUN php go-pear.phar
|
||||||
|
|
||||||
RUN pecl install mcrypt-1.0.2
|
RUN pecl install mcrypt-1.0.3
|
||||||
|
|
||||||
RUN bash -c "echo extension=/usr/lib/php/20170718/mcrypt.so > /etc/php/7.2/mods-available/mcrypt.ini"
|
RUN bash -c "echo extension=/usr/lib/php/20190902/mcrypt.so > /etc/php/7.4/mods-available/mcrypt.ini"
|
||||||
|
|
||||||
RUN phpenmod mcrypt
|
RUN phpenmod mcrypt
|
||||||
RUN phpenmod gd
|
RUN phpenmod gd
|
||||||
RUN phpenmod bcmath
|
RUN phpenmod bcmath
|
||||||
|
|
||||||
RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php/7.2/apache2/php.ini
|
RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php/7.4/apache2/php.ini
|
||||||
RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php/7.2/cli/php.ini
|
RUN sed -i 's/variables_order = .*/variables_order = "EGPCS"/' /etc/php/7.4/cli/php.ini
|
||||||
|
|
||||||
RUN useradd -m --uid 1000 --gid 50 docker
|
RUN useradd -m --uid 1000 --gid 50 docker
|
||||||
|
|
||||||
|
@ -133,4 +133,4 @@ RUN chmod +x /startup.sh /usr/bin/supervisor-exit-event-listener
|
||||||
CMD ["/startup.sh"]
|
CMD ["/startup.sh"]
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
EXPOSE 443
|
EXPOSE 443
|
|
@ -1,4 +1,4 @@
|
||||||
FROM alpine:3.13
|
FROM alpine:3.14.2
|
||||||
# Apache + PHP
|
# Apache + PHP
|
||||||
RUN apk add --no-cache \
|
RUN apk add --no-cache \
|
||||||
apache2 \
|
apache2 \
|
||||||
|
@ -25,6 +25,8 @@ RUN apk add --no-cache \
|
||||||
php7-session \
|
php7-session \
|
||||||
php7-dom \
|
php7-dom \
|
||||||
php7-xmlwriter \
|
php7-xmlwriter \
|
||||||
|
php7-xmlreader \
|
||||||
|
php7-sodium \
|
||||||
curl \
|
curl \
|
||||||
wget \
|
wget \
|
||||||
vim \
|
vim \
|
||||||
|
@ -80,4 +82,4 @@ ENTRYPOINT ["/sbin/tini", "--"]
|
||||||
|
|
||||||
CMD ["/entrypoint.sh"]
|
CMD ["/entrypoint.sh"]
|
||||||
|
|
||||||
EXPOSE 80
|
EXPOSE 80
|
1
Procfile
Normal file
1
Procfile
Normal file
|
@ -0,0 +1 @@
|
||||||
|
web: php heroku/startup.php && heroku-php-apache2 public/
|
13
README.md
13
README.md
|
@ -1,5 +1,5 @@
|
||||||
 [](https://crowdin.com/project/snipe-it) [](https://gitter.im/snipe/snipe-it?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [](https://hub.docker.com/r/snipe/snipe-it/) [](https://twitter.com/snipeitapp) [](https://www.codacy.com/app/snipe/snipe-it?utm_source=github.com&utm_medium=referral&utm_content=snipe/snipe-it&utm_campaign=Badge_Grade)
|
 [](https://crowdin.com/project/snipe-it) [](https://hub.docker.com/r/snipe/snipe-it/) [](https://twitter.com/snipeitapp) [](https://www.codacy.com/app/snipe/snipe-it?utm_source=github.com&utm_medium=referral&utm_content=snipe/snipe-it&utm_campaign=Badge_Grade)
|
||||||
[](#contributors)
|
[](#contributors) [](https://discord.gg/yZFtShAcKk) [](https://huntr.dev)
|
||||||
|
|
||||||
## Snipe-IT - Open Source Asset Management System
|
## Snipe-IT - Open Source Asset Management System
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@ For instructions on installing and configuring Snipe-IT on your server, check ou
|
||||||
|
|
||||||
If you're having trouble with the installation, please check the [Common Issues](https://snipe-it.readme.io/docs/common-issues) and [Getting Help](https://snipe-it.readme.io/docs/getting-help) documentation, and search this repository's open *and* closed issues for help.
|
If you're having trouble with the installation, please check the [Common Issues](https://snipe-it.readme.io/docs/common-issues) and [Getting Help](https://snipe-it.readme.io/docs/getting-help) documentation, and search this repository's open *and* closed issues for help.
|
||||||
|
|
||||||
|
[](https://heroku.com/deploy)
|
||||||
|
|
||||||
-----
|
-----
|
||||||
### User's Manual
|
### User's Manual
|
||||||
For help using Snipe-IT, check out the [user's manual](https://snipe-it.readme.io/docs/overview).
|
For help using Snipe-IT, check out the [user's manual](https://snipe-it.readme.io/docs/overview).
|
||||||
|
@ -55,11 +57,11 @@ Since the release of the JSON REST API, several third-party developers have been
|
||||||
|
|
||||||
- [Python Module](https://github.com/jbloomer/SnipeIT-PythonAPI) by [@jbloomer](https://github.com/jbloomer)
|
- [Python Module](https://github.com/jbloomer/SnipeIT-PythonAPI) by [@jbloomer](https://github.com/jbloomer)
|
||||||
- [SnipeSharp - .NET module in C#](https://github.com/barrycarey/SnipeSharp) by [@barrycarey](https://github.com/barrycarey)
|
- [SnipeSharp - .NET module in C#](https://github.com/barrycarey/SnipeSharp) by [@barrycarey](https://github.com/barrycarey)
|
||||||
- [InQRy](https://github.com/Microsoft/InQRy) by [@Microsoft](https://github.com/Microsoft)
|
- [InQRy -unmaintained-](https://github.com/Microsoft/InQRy) by [@Microsoft](https://github.com/Microsoft)
|
||||||
- [SnipeitPS](https://github.com/snazy2000/SnipeitPS) by [@snazy2000](https://github.com/snazy2000) - Powershell API Wrapper for Snipe-it
|
- [SnipeitPS](https://github.com/snazy2000/SnipeitPS) by [@snazy2000](https://github.com/snazy2000) - Powershell API Wrapper for Snipe-it
|
||||||
- [jamf2snipe](https://github.com/ParadoxGuitarist/jamf2snipe) by [@ParadoxGuitarist](https://github.com/ParadoxGuitarist) - Python script to sync assets between a JAMFPro instance and a Snipe-IT instance
|
- [jamf2snipe](https://github.com/ParadoxGuitarist/jamf2snipe) by [@ParadoxGuitarist](https://github.com/ParadoxGuitarist) - Python script to sync assets between a JAMFPro instance and a Snipe-IT instance
|
||||||
- [Marksman](https://github.com/Scope-IT/marksman) - A Windows agent for Snipe-IT
|
- [Marksman](https://github.com/Scope-IT/marksman) - A Windows agent for Snipe-IT
|
||||||
- [Snipe-IT plugin for Jira Service Desk (beta)](https://marketplace.atlassian.com/apps/1220379/snipe-it-for-jira-service-desk-beta?hosting=cloud&tab=overview) - for the upcoming Snipe-IT v5 only
|
- [Snipe-IT plugin for Jira Service Desk](https://marketplace.atlassian.com/apps/1220964/snipe-it-for-jira)
|
||||||
- [Python 3 CSV importer](https://github.com/gastamper/snipeit-csvimporter) - allows importing assets into Snipe-IT based on Item Name rather than Asset Tag.
|
- [Python 3 CSV importer](https://github.com/gastamper/snipeit-csvimporter) - allows importing assets into Snipe-IT based on Item Name rather than Asset Tag.
|
||||||
- [Snipe-IT Kubernetes Helm Chart](https://github.com/t3n/helm-charts/tree/master/snipeit) - For more information, [click here](https://hub.helm.sh/charts/t3n/snipeit).
|
- [Snipe-IT Kubernetes Helm Chart](https://github.com/t3n/helm-charts/tree/master/snipeit) - For more information, [click here](https://hub.helm.sh/charts/t3n/snipeit).
|
||||||
- [Snipe-IT Bulk Edit](https://github.com/bricelabelle/snipe-it-bulkedit) - Google Script files to use Google Sheets as a bulk checkout/checkin/edit tool for Snipe-it.
|
- [Snipe-IT Bulk Edit](https://github.com/bricelabelle/snipe-it-bulkedit) - Google Script files to use Google Sheets as a bulk checkout/checkin/edit tool for Snipe-it.
|
||||||
|
@ -126,7 +128,8 @@ Thanks goes to all of these wonderful people ([emoji key](https://github.com/ken
|
||||||
| [<img src="https://avatars.githubusercontent.com/u/9255772?v=4" width="110px;"/><br /><sub>Mark Stenglein</sub>](https://markstenglein.com)<br />[💻](https://github.com/snipe/snipe-it/commits?author=ocelotsloth "Code") | [<img src="https://avatars.githubusercontent.com/u/35658596?v=4" width="110px;"/><br /><sub>ajsy</sub>](https://github.com/ajsy)<br />[💻](https://github.com/snipe/snipe-it/commits?author=ajsy "Code") | [<img src="https://avatars.githubusercontent.com/u/3628035?v=4" width="110px;"/><br /><sub>Jan Kiesewetter</sub>](https://github.com/t3easy)<br />[💻](https://github.com/snipe/snipe-it/commits?author=t3easy "Code") | [<img src="https://avatars.githubusercontent.com/u/79449630?v=4" width="110px;"/><br /><sub>Tetrachloromethane250</sub>](https://github.com/Tetrachloromethane250)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Tetrachloromethane250 "Code") | [<img src="https://avatars.githubusercontent.com/u/22004482?v=4" width="110px;"/><br /><sub>Lars Kajes</sub>](https://www.kajes.se/)<br />[💻](https://github.com/snipe/snipe-it/commits?author=kajes "Code") | [<img src="https://avatars.githubusercontent.com/u/13993216?v=4" width="110px;"/><br /><sub>Joly0</sub>](https://github.com/Joly0)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Joly0 "Code") | [<img src="https://avatars.githubusercontent.com/u/1501022?v=4" width="110px;"/><br /><sub>theburger</sub>](https://github.com/limeless)<br />[💻](https://github.com/snipe/snipe-it/commits?author=limeless "Code") |
|
| [<img src="https://avatars.githubusercontent.com/u/9255772?v=4" width="110px;"/><br /><sub>Mark Stenglein</sub>](https://markstenglein.com)<br />[💻](https://github.com/snipe/snipe-it/commits?author=ocelotsloth "Code") | [<img src="https://avatars.githubusercontent.com/u/35658596?v=4" width="110px;"/><br /><sub>ajsy</sub>](https://github.com/ajsy)<br />[💻](https://github.com/snipe/snipe-it/commits?author=ajsy "Code") | [<img src="https://avatars.githubusercontent.com/u/3628035?v=4" width="110px;"/><br /><sub>Jan Kiesewetter</sub>](https://github.com/t3easy)<br />[💻](https://github.com/snipe/snipe-it/commits?author=t3easy "Code") | [<img src="https://avatars.githubusercontent.com/u/79449630?v=4" width="110px;"/><br /><sub>Tetrachloromethane250</sub>](https://github.com/Tetrachloromethane250)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Tetrachloromethane250 "Code") | [<img src="https://avatars.githubusercontent.com/u/22004482?v=4" width="110px;"/><br /><sub>Lars Kajes</sub>](https://www.kajes.se/)<br />[💻](https://github.com/snipe/snipe-it/commits?author=kajes "Code") | [<img src="https://avatars.githubusercontent.com/u/13993216?v=4" width="110px;"/><br /><sub>Joly0</sub>](https://github.com/Joly0)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Joly0 "Code") | [<img src="https://avatars.githubusercontent.com/u/1501022?v=4" width="110px;"/><br /><sub>theburger</sub>](https://github.com/limeless)<br />[💻](https://github.com/snipe/snipe-it/commits?author=limeless "Code") |
|
||||||
| [<img src="https://avatars.githubusercontent.com/u/36065681?v=4" width="110px;"/><br /><sub>David Valin Alonso</sub>](https://github.com/deivishome)<br />[💻](https://github.com/snipe/snipe-it/commits?author=deivishome "Code") | [<img src="https://avatars.githubusercontent.com/u/8290389?v=4" width="110px;"/><br /><sub>andreaci</sub>](https://github.com/andreaci)<br />[💻](https://github.com/snipe/snipe-it/commits?author=andreaci "Code") | [<img src="https://avatars.githubusercontent.com/u/1828542?v=4" width="110px;"/><br /><sub>Jelle Sebreghts</sub>](http://www.jellesebreghts.be)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Jelle-S "Code") | [<img src="https://avatars.githubusercontent.com/u/11180862?v=4" width="110px;"/><br /><sub>Michael Pietsch</sub>](https://github.com/Skywalker-11)<br /> | [<img src="https://avatars.githubusercontent.com/u/22068886?v=4" width="110px;"/><br /><sub>Masudul Haque Shihab</sub>](https://github.com/sh1hab)<br />[💻](https://github.com/snipe/snipe-it/commits?author=sh1hab "Code") | [<img src="https://avatars.githubusercontent.com/u/16099942?v=4" width="110px;"/><br /><sub>Supapong Areeprasertkul</sub>](http://www.freedomdive.com/)<br />[💻](https://github.com/snipe/snipe-it/commits?author=zybersup "Code") | [<img src="https://avatars.githubusercontent.com/u/207358?v=4" width="110px;"/><br /><sub>Peter Sarossy</sub>](https://github.com/psarossy)<br />[💻](https://github.com/snipe/snipe-it/commits?author=psarossy "Code") |
|
| [<img src="https://avatars.githubusercontent.com/u/36065681?v=4" width="110px;"/><br /><sub>David Valin Alonso</sub>](https://github.com/deivishome)<br />[💻](https://github.com/snipe/snipe-it/commits?author=deivishome "Code") | [<img src="https://avatars.githubusercontent.com/u/8290389?v=4" width="110px;"/><br /><sub>andreaci</sub>](https://github.com/andreaci)<br />[💻](https://github.com/snipe/snipe-it/commits?author=andreaci "Code") | [<img src="https://avatars.githubusercontent.com/u/1828542?v=4" width="110px;"/><br /><sub>Jelle Sebreghts</sub>](http://www.jellesebreghts.be)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Jelle-S "Code") | [<img src="https://avatars.githubusercontent.com/u/11180862?v=4" width="110px;"/><br /><sub>Michael Pietsch</sub>](https://github.com/Skywalker-11)<br /> | [<img src="https://avatars.githubusercontent.com/u/22068886?v=4" width="110px;"/><br /><sub>Masudul Haque Shihab</sub>](https://github.com/sh1hab)<br />[💻](https://github.com/snipe/snipe-it/commits?author=sh1hab "Code") | [<img src="https://avatars.githubusercontent.com/u/16099942?v=4" width="110px;"/><br /><sub>Supapong Areeprasertkul</sub>](http://www.freedomdive.com/)<br />[💻](https://github.com/snipe/snipe-it/commits?author=zybersup "Code") | [<img src="https://avatars.githubusercontent.com/u/207358?v=4" width="110px;"/><br /><sub>Peter Sarossy</sub>](https://github.com/psarossy)<br />[💻](https://github.com/snipe/snipe-it/commits?author=psarossy "Code") |
|
||||||
| [<img src="https://avatars.githubusercontent.com/u/11823649?v=4" width="110px;"/><br /><sub>Renee Margaret McConahy</sub>](https://github.com/nepella)<br />[💻](https://github.com/snipe/snipe-it/commits?author=nepella "Code") | [<img src="https://avatars.githubusercontent.com/u/5553884?v=4" width="110px;"/><br /><sub>JohnnyPicnic</sub>](https://github.com/JohnnyPicnic)<br />[💻](https://github.com/snipe/snipe-it/commits?author=JohnnyPicnic "Code") | [<img src="https://avatars.githubusercontent.com/u/8799594?v=4" width="110px;"/><br /><sub>markbrule</sub>](https://github.com/markbrule)<br />[💻](https://github.com/snipe/snipe-it/commits?author=markbrule "Code") | [<img src="https://avatars.githubusercontent.com/u/1962801?v=4" width="110px;"/><br /><sub>Mike Campbell</sub>](https://github.com/mikecmpbll)<br />[💻](https://github.com/snipe/snipe-it/commits?author=mikecmpbll "Code") | [<img src="https://avatars.githubusercontent.com/u/11973217?v=4" width="110px;"/><br /><sub>tbrconnect</sub>](https://github.com/tbrconnect)<br />[💻](https://github.com/snipe/snipe-it/commits?author=tbrconnect "Code") | [<img src="https://avatars.githubusercontent.com/u/12447225?v=4" width="110px;"/><br /><sub>kcoyo</sub>](https://github.com/kcoyo)<br />[💻](https://github.com/snipe/snipe-it/commits?author=kcoyo "Code") | [<img src="https://avatars.githubusercontent.com/u/494017?v=4" width="110px;"/><br /><sub>Travis Miller</sub>](https://travismiller.com/)<br />[💻](https://github.com/snipe/snipe-it/commits?author=travismiller "Code") |
|
| [<img src="https://avatars.githubusercontent.com/u/11823649?v=4" width="110px;"/><br /><sub>Renee Margaret McConahy</sub>](https://github.com/nepella)<br />[💻](https://github.com/snipe/snipe-it/commits?author=nepella "Code") | [<img src="https://avatars.githubusercontent.com/u/5553884?v=4" width="110px;"/><br /><sub>JohnnyPicnic</sub>](https://github.com/JohnnyPicnic)<br />[💻](https://github.com/snipe/snipe-it/commits?author=JohnnyPicnic "Code") | [<img src="https://avatars.githubusercontent.com/u/8799594?v=4" width="110px;"/><br /><sub>markbrule</sub>](https://github.com/markbrule)<br />[💻](https://github.com/snipe/snipe-it/commits?author=markbrule "Code") | [<img src="https://avatars.githubusercontent.com/u/1962801?v=4" width="110px;"/><br /><sub>Mike Campbell</sub>](https://github.com/mikecmpbll)<br />[💻](https://github.com/snipe/snipe-it/commits?author=mikecmpbll "Code") | [<img src="https://avatars.githubusercontent.com/u/11973217?v=4" width="110px;"/><br /><sub>tbrconnect</sub>](https://github.com/tbrconnect)<br />[💻](https://github.com/snipe/snipe-it/commits?author=tbrconnect "Code") | [<img src="https://avatars.githubusercontent.com/u/12447225?v=4" width="110px;"/><br /><sub>kcoyo</sub>](https://github.com/kcoyo)<br />[💻](https://github.com/snipe/snipe-it/commits?author=kcoyo "Code") | [<img src="https://avatars.githubusercontent.com/u/494017?v=4" width="110px;"/><br /><sub>Travis Miller</sub>](https://travismiller.com/)<br />[💻](https://github.com/snipe/snipe-it/commits?author=travismiller "Code") |
|
||||||
| [<img src="https://avatars.githubusercontent.com/u/8735148?v=4" width="110px;"/><br /><sub>Petri Asikainen</sub>](https://github.com/PetriAsi)<br />[💻](https://github.com/snipe/snipe-it/commits?author=PetriAsi "Code") | [<img src="https://avatars.githubusercontent.com/u/11424540?v=4" width="110px;"/><br /><sub>derdeagle</sub>](https://github.com/derdeagle)<br />[💻](https://github.com/snipe/snipe-it/commits?author=derdeagle "Code") |
|
| [<img src="https://avatars.githubusercontent.com/u/8735148?v=4" width="110px;"/><br /><sub>Petri Asikainen</sub>](https://github.com/PetriAsi)<br />[💻](https://github.com/snipe/snipe-it/commits?author=PetriAsi "Code") | [<img src="https://avatars.githubusercontent.com/u/11424540?v=4" width="110px;"/><br /><sub>derdeagle</sub>](https://github.com/derdeagle)<br />[💻](https://github.com/snipe/snipe-it/commits?author=derdeagle "Code") | [<img src="https://avatars.githubusercontent.com/u/176950?v=4" width="110px;"/><br /><sub>Mike Frysinger</sub>](https://wh0rd.org/)<br />[💻](https://github.com/snipe/snipe-it/commits?author=vapier "Code") | [<img src="https://avatars.githubusercontent.com/u/22044358?v=4" width="110px;"/><br /><sub>ALPHA</sub>](https://github.com/AL4AL)<br />[💻](https://github.com/snipe/snipe-it/commits?author=AL4AL "Code") | [<img src="https://avatars.githubusercontent.com/u/1042587?v=4" width="110px;"/><br /><sub>FliegenKLATSCH</sub>](https://www.ifern.de)<br />[💻](https://github.com/snipe/snipe-it/commits?author=FliegenKLATSCH "Code") | [<img src="https://avatars.githubusercontent.com/u/442138?v=4" width="110px;"/><br /><sub>Jeremy Price</sub>](https://github.com/jerm)<br />[💻](https://github.com/snipe/snipe-it/commits?author=jerm "Code") | [<img src="https://avatars.githubusercontent.com/u/84392209?v=4" width="110px;"/><br /><sub>Toreg87</sub>](https://github.com/Toreg87)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Toreg87 "Code") |
|
||||||
|
| [<img src="https://avatars.githubusercontent.com/u/67638596?v=4" width="110px;"/><br /><sub>Matthew Nickson</sub>](https://github.com/Computroniks)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Computroniks "Code") | [<img src="https://avatars.githubusercontent.com/u/1646397?v=4" width="110px;"/><br /><sub>Jethro Nederhof</sub>](https://jethron.id.au)<br />[💻](https://github.com/snipe/snipe-it/commits?author=jethron "Code") | [<img src="https://avatars.githubusercontent.com/u/23289826?v=4" width="110px;"/><br /><sub>Oskar Stenberg</sub>](https://github.com/01ste02)<br />[💻](https://github.com/snipe/snipe-it/commits?author=01ste02 "Code") | [<img src="https://avatars.githubusercontent.com/u/82208283?v=4" width="110px;"/><br /><sub>Robert-Azelis</sub>](https://github.com/Robert-Azelis)<br />[💻](https://github.com/snipe/snipe-it/commits?author=Robert-Azelis "Code") | [<img src="https://avatars.githubusercontent.com/u/60648387?v=4" width="110px;"/><br /><sub>Alexander William Smith</sub>](https://github.com/alwism)<br />[💻](https://github.com/snipe/snipe-it/commits?author=alwism "Code") |
|
||||||
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
||||||
|
|
||||||
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
|
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!
|
||||||
|
|
154
app.json
Normal file
154
app.json
Normal file
|
@ -0,0 +1,154 @@
|
||||||
|
{
|
||||||
|
"name": "Snipe-IT",
|
||||||
|
"description": "Open source asset management.",
|
||||||
|
"keywords": [
|
||||||
|
"asset management",
|
||||||
|
"it asset"
|
||||||
|
],
|
||||||
|
"website": "https://snipeitapp.com/",
|
||||||
|
"repository": "https://github.com/snipe/snipe-it",
|
||||||
|
"logo": "https://pbs.twimg.com/profile_images/976748875733020672/K-HnZCCK_400x400.jpg",
|
||||||
|
"success_url": "/setup",
|
||||||
|
"env": {
|
||||||
|
"APP_ENV": {
|
||||||
|
"description": "Laravel environment mode. Unless developing the application, this should be production.",
|
||||||
|
"value": "production"
|
||||||
|
},
|
||||||
|
"APP_DEBUG": {
|
||||||
|
"description": "Laravel debug mode. Unless developing the application or actively debugging a problem, this should be set to false.",
|
||||||
|
"value": "false"
|
||||||
|
},
|
||||||
|
"APP_KEY": {
|
||||||
|
"description": "A secret key for verifying the integrity of signed cookies. (See either https://snipe-it.readme.io/docs/generate-your-app-key or generate at https://coderstoolbox.online/toolbox/generate-symfony-secret)",
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"APP_URL": {
|
||||||
|
"description": "URL where your Snipe-IT install will be available at.",
|
||||||
|
"value": "https://your-app-name.herokuapp.com"
|
||||||
|
},
|
||||||
|
"APP_TIMEZONE": {
|
||||||
|
"description": "Which timezone do you want to use for your install? (http://php.net/manual/en/timezones.php)",
|
||||||
|
"value": "UTC"
|
||||||
|
},
|
||||||
|
"APP_LOCALE": {
|
||||||
|
"description": "Which language do you want to use for your install? (https://snipe-it.readme.io/docs/configuration#setting-a-language)",
|
||||||
|
"value": "en"
|
||||||
|
},
|
||||||
|
"MAX_RESULTS": {
|
||||||
|
"description": "The maximum number of search results that can be returned at one time.",
|
||||||
|
"value": "500"
|
||||||
|
},
|
||||||
|
"MAIL_DRIVER": {
|
||||||
|
"description": "Mail driver - Generally SMTP on Heroku - https://snipe-it.readme.io/docs/configuration#required-outgoing-mail-settings",
|
||||||
|
"value": "smtp"
|
||||||
|
},
|
||||||
|
"MAIL_HOST": {
|
||||||
|
"description": "SMTP Server Hostname",
|
||||||
|
"value": "smtp.your.domain.name"
|
||||||
|
},
|
||||||
|
"MAIL_PORT": {
|
||||||
|
"description": "SMTP Server Port",
|
||||||
|
"value": "25"
|
||||||
|
},
|
||||||
|
"MAIL_USERNAME": {
|
||||||
|
"description": "SMTP Server Username",
|
||||||
|
"value": "YOURUSERNAME"
|
||||||
|
},
|
||||||
|
"MAIL_PASSWORD": {
|
||||||
|
"description": "SMTP Server Password",
|
||||||
|
"value": "YOURPASSWORD"
|
||||||
|
},
|
||||||
|
"MAIL_ENCRYPTION": {
|
||||||
|
"description": "Encryption protocol for email sending.",
|
||||||
|
"value": "null"
|
||||||
|
},
|
||||||
|
"MAIL_FROM_ADDR": {
|
||||||
|
"description": "Email from address",
|
||||||
|
"value": "no-reply@domain.name"
|
||||||
|
},
|
||||||
|
"MAIL_FROM_NAME": {
|
||||||
|
"description": "Email from Name",
|
||||||
|
"value": "Snipe-IT"
|
||||||
|
},
|
||||||
|
"MAIL_REPLYTO_ADDR": {
|
||||||
|
"description": "Email Reply-To address",
|
||||||
|
"value": "your@domain.name"
|
||||||
|
},
|
||||||
|
"MAIL_REPLYTO_NAME": {
|
||||||
|
"description": "Email Reply-To Name",
|
||||||
|
"value": "Snipe-IT"
|
||||||
|
},
|
||||||
|
"MAIL_AUTO_EMBED": {
|
||||||
|
"description": "Whether or not to embed images in emails (via CID or base64) versus linking to them.",
|
||||||
|
"value": "true"
|
||||||
|
},
|
||||||
|
"MAIL_AUTO_EMBED_METHOD": {
|
||||||
|
"description": "Method that should be used for attaching inline images.",
|
||||||
|
"value": "base64"
|
||||||
|
},
|
||||||
|
"SESSION_LIFETIME": {
|
||||||
|
"description": "Specify the time in minutes that the session should remain valid.",
|
||||||
|
"value": "12000"
|
||||||
|
},
|
||||||
|
"EXPIRE_ON_CLOSE": {
|
||||||
|
"description": "Specify whether or not the logged in session should be expired when the user closes their browser window.",
|
||||||
|
"value": "false"
|
||||||
|
},
|
||||||
|
"ENCRYPT": {
|
||||||
|
"description": "Specify whether you wish to use encrypted cookies for your Snipe-IT sessions.",
|
||||||
|
"value": "true"
|
||||||
|
},
|
||||||
|
"COOKIE_NAME": {
|
||||||
|
"description": "The name of the cookie set by Snipe-IT for session management.",
|
||||||
|
"value": "snipeit_session"
|
||||||
|
},
|
||||||
|
"COOKIE_DOMAIN": {
|
||||||
|
"description": "The domain name that the session cookie should be sent for.",
|
||||||
|
"value": "your-app-name.herokuapp.com"
|
||||||
|
},
|
||||||
|
"SECURE_COOKIES": {
|
||||||
|
"description": "Should cookies only be sent for HTTPS connections? Generally true on Heroku.",
|
||||||
|
"value": "true"
|
||||||
|
},
|
||||||
|
"LOGIN_MAX_ATTEMPTS": {
|
||||||
|
"description": "The maximum number of failed attempts allowed before the user is throttled.",
|
||||||
|
"value": "5"
|
||||||
|
},
|
||||||
|
"LOGIN_LOCKOUT_DURATION": {
|
||||||
|
"description": "The duration (in seconds) that the user should be blocked from attempting to authenticate again.",
|
||||||
|
"value": "60"
|
||||||
|
},
|
||||||
|
"APP_LOG": {
|
||||||
|
"description": "Driver to send logs to. (errorlog for stderr)",
|
||||||
|
"value": "errorlog"
|
||||||
|
},
|
||||||
|
"ALLOW_IFRAMING": {
|
||||||
|
"description": "Allow Snipe-IT to be loaded using an iFrame?",
|
||||||
|
"value": "false"
|
||||||
|
},
|
||||||
|
"GOOGLE_MAPS_API": {
|
||||||
|
"description": "Include your Google Maps API key here if you'd like Snipe-IT to load maps from Google on your locations and suppliers pages.",
|
||||||
|
"required": false
|
||||||
|
},
|
||||||
|
"BACKUP_ENV": {
|
||||||
|
"description": "Set this to true if you wish to backup your .env file in your Admin > Backups process.",
|
||||||
|
"value": "true"
|
||||||
|
},
|
||||||
|
"ENABLE_HSTS": {
|
||||||
|
"description": "Whether or not to send the HSTS security policy header.",
|
||||||
|
"value": "false"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"formation": {
|
||||||
|
"web": {
|
||||||
|
"quantity": 1,
|
||||||
|
"size": "free"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"image": "heroku/php",
|
||||||
|
"addons": [
|
||||||
|
"cleardb:ignite",
|
||||||
|
"heroku-redis:hobby-dev",
|
||||||
|
"papertrail:choklad"
|
||||||
|
]
|
||||||
|
}
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\LicenseSeat;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\License;
|
use App\Models\License;
|
||||||
|
use App\Models\LicenseSeat;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class CheckinLicensesFromAllUsers extends Command
|
class CheckinLicensesFromAllUsers extends Command
|
||||||
|
@ -41,55 +41,48 @@ class CheckinLicensesFromAllUsers extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
$license_id = $this->option('license_id');
|
$license_id = $this->option('license_id');
|
||||||
$notify = $this->option('notify');
|
$notify = $this->option('notify');
|
||||||
|
|
||||||
if (!$license_id) {
|
if (! $license_id) {
|
||||||
$this->error('ERROR: License ID is required.');
|
$this->error('ERROR: License ID is required.');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! $license = License::where('id', '=', $license_id)->first()) {
|
||||||
if (!$license = License::where('id','=',$license_id)->first()) {
|
|
||||||
$this->error('Invalid license ID');
|
$this->error('Invalid license ID');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info('Checking in ALL seats for '.$license->name);
|
$this->info('Checking in ALL seats for '.$license->name);
|
||||||
|
|
||||||
|
|
||||||
$licenseSeats = LicenseSeat::where('license_id', '=', $license_id)
|
$licenseSeats = LicenseSeat::where('license_id', '=', $license_id)
|
||||||
->whereNotNull('assigned_to')
|
->whereNotNull('assigned_to')
|
||||||
->with('user')
|
->with('user')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$this->info(' There are ' .$licenseSeats->count(). ' seats checked out: ');
|
$this->info(' There are '.$licenseSeats->count().' seats checked out: ');
|
||||||
|
|
||||||
if (!$notify) {
|
if (! $notify) {
|
||||||
$this->info('No mail will be sent.');
|
$this->info('No mail will be sent.');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($licenseSeats as $seat) {
|
foreach ($licenseSeats as $seat) {
|
||||||
$this->info($seat->user->username .' has a license seat for '.$license->name);
|
$this->info($seat->user->username.' has a license seat for '.$license->name);
|
||||||
$seat->assigned_to = null;
|
$seat->assigned_to = null;
|
||||||
|
|
||||||
if ($seat->save()) {
|
if ($seat->save()) {
|
||||||
|
|
||||||
// Override the email address so we don't notify on checkin
|
// Override the email address so we don't notify on checkin
|
||||||
if (!$notify) {
|
if (! $notify) {
|
||||||
$seat->user->email = null;
|
$seat->user->email = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log the checkin
|
// Log the checkin
|
||||||
$seat->logCheckin($seat->user, 'Checked in via cli tool');
|
$seat->logCheckin($seat->user, 'Checked in via cli tool');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,10 @@
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\LicenseSeat;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\License;
|
use App\Models\License;
|
||||||
|
use App\Models\LicenseSeat;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
class CheckoutLicenseToAllUsers extends Command
|
class CheckoutLicenseToAllUsers extends Command
|
||||||
|
@ -41,18 +41,18 @@ class CheckoutLicenseToAllUsers extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
$license_id = $this->option('license_id');
|
$license_id = $this->option('license_id');
|
||||||
$notify = $this->option('notify');
|
$notify = $this->option('notify');
|
||||||
|
|
||||||
if (!$license_id) {
|
if (! $license_id) {
|
||||||
$this->error('ERROR: License ID is required.');
|
$this->error('ERROR: License ID is required.');
|
||||||
return false;
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! $license = License::where('id', '=', $license_id)->with('assignedusers')->first()) {
|
||||||
if (!$license = License::where('id','=',$license_id)->with('assignedusers')->first()) {
|
|
||||||
$this->error('Invalid license ID');
|
$this->error('Invalid license ID');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class CheckoutLicenseToAllUsers extends Command
|
||||||
|
|
||||||
$this->info('Checking out '.$users->count().' of '.$license->getAvailSeatsCountAttribute().' seats for '.$license->name);
|
$this->info('Checking out '.$users->count().' of '.$license->getAvailSeatsCountAttribute().' seats for '.$license->name);
|
||||||
|
|
||||||
if (!$notify) {
|
if (! $notify) {
|
||||||
$this->info('No mail will be sent.');
|
$this->info('No mail will be sent.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,14 +74,14 @@ class CheckoutLicenseToAllUsers extends Command
|
||||||
// to them
|
// to them
|
||||||
|
|
||||||
if ($user->licenses->where('id', '=', $license_id)->count()) {
|
if ($user->licenses->where('id', '=', $license_id)->count()) {
|
||||||
$this->info($user->username .' already has this license checked out to them. Skipping... ');
|
$this->info($user->username.' already has this license checked out to them. Skipping... ');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If the license is valid, check that there is an available seat
|
// If the license is valid, check that there is an available seat
|
||||||
if ($license->availCount()->count() < 1) {
|
if ($license->availCount()->count() < 1) {
|
||||||
$this->error('ERROR: No available seats');
|
$this->error('ERROR: No available seats');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,13 +89,12 @@ class CheckoutLicenseToAllUsers extends Command
|
||||||
// Get the seat ID
|
// Get the seat ID
|
||||||
$licenseSeat = $license->freeSeat();
|
$licenseSeat = $license->freeSeat();
|
||||||
|
|
||||||
|
|
||||||
// Update the seat with checkout info,
|
// Update the seat with checkout info,
|
||||||
$licenseSeat->assigned_to = $user->id;
|
$licenseSeat->assigned_to = $user->id;
|
||||||
if ($licenseSeat->save()) {
|
if ($licenseSeat->save()) {
|
||||||
|
|
||||||
// Temporarily null the user's email address so we don't send mail if we're not supposed to
|
// Temporarily null the user's email address so we don't send mail if we're not supposed to
|
||||||
if (!$notify) {
|
if (! $notify) {
|
||||||
$user->email = null;
|
$user->email = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,10 +102,6 @@ class CheckoutLicenseToAllUsers extends Command
|
||||||
$licenseSeat->logCheckout('Checked out via cli tool', $user);
|
$licenseSeat->logCheckout('Checked out via cli tool', $user);
|
||||||
$this->info('License '.$license_id.' seat '.$licenseSeat->id.' checked out to '.$user->username);
|
$this->info('License '.$license_id.' seat '.$licenseSeat->id.' checked out to '.$user->username);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ class CreateAdmin extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
$first_name = $this->option('first_name');
|
$first_name = $this->option('first_name');
|
||||||
$last_name = $this->option('last_name');
|
$last_name = $this->option('last_name');
|
||||||
$username = $this->option('username');
|
$username = $this->option('username');
|
||||||
|
@ -45,7 +44,7 @@ class CreateAdmin extends Command
|
||||||
$password = $this->option('password');
|
$password = $this->option('password');
|
||||||
$show_in_list = $this->argument('show_in_list');
|
$show_in_list = $this->argument('show_in_list');
|
||||||
|
|
||||||
if (($first_name=='') || ($last_name=='') || ($username=='') || ($email=='') || ($password=='')) {
|
if (($first_name == '') || ($last_name == '') || ($username == '') || ($email == '') || ($password == '')) {
|
||||||
$this->info('ERROR: All fields are required.');
|
$this->info('ERROR: All fields are required.');
|
||||||
} else {
|
} else {
|
||||||
$user = new \App\Models\User;
|
$user = new \App\Models\User;
|
||||||
|
@ -68,12 +67,9 @@ class CreateAdmin extends Command
|
||||||
$errors = $user->getErrors();
|
$errors = $user->getErrors();
|
||||||
|
|
||||||
foreach ($errors->all() as $error) {
|
foreach ($errors->all() as $error) {
|
||||||
$this->info('ERROR:'. $error);
|
$this->info('ERROR:'.$error);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,9 +38,7 @@ class DisableLDAP extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->confirm("\n****************************************************\nThis will disable LDAP support. You will not be able \nto login with an account that does not exist \nlocally in the Snipe-IT local database. \n****************************************************\n\nDo you wish to continue? [y|N]")) {
|
if ($this->confirm("\n****************************************************\nThis will disable LDAP support. You will not be able \nto login with an account that does not exist \nlocally in the Snipe-IT local database. \n****************************************************\n\nDo you wish to continue? [y|N]")) {
|
||||||
|
|
||||||
$setting = Setting::getSettings();
|
$setting = Setting::getSettings();
|
||||||
$setting->ldap_enabled = 0;
|
$setting->ldap_enabled = 0;
|
||||||
if ($setting->save()) {
|
if ($setting->save()) {
|
||||||
|
@ -51,6 +49,5 @@ class DisableLDAP extends Command
|
||||||
} else {
|
} else {
|
||||||
$this->info('Canceled. No actions taken.');
|
$this->info('Canceled. No actions taken.');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,49 +37,43 @@ class FixDoubleEscape extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
$tables = [
|
$tables = [
|
||||||
'\App\Models\Asset' => ['name'],
|
\App\Models\Asset::class => ['name'],
|
||||||
'\App\Models\License' => ['name'],
|
\App\Models\License::class => ['name'],
|
||||||
'\App\Models\Consumable' => ['name'],
|
\App\Models\Consumable::class => ['name'],
|
||||||
'\App\Models\Accessory' => ['name'],
|
\App\Models\Accessory::class => ['name'],
|
||||||
'\App\Models\Component' => ['name'],
|
\App\Models\Component::class => ['name'],
|
||||||
'\App\Models\Company' => ['name'],
|
\App\Models\Company::class => ['name'],
|
||||||
'\App\Models\Manufacturer' => ['name'],
|
\App\Models\Manufacturer::class => ['name'],
|
||||||
'\App\Models\Supplier' => ['name'],
|
\App\Models\Supplier::class => ['name'],
|
||||||
'\App\Models\Statuslabel' => ['name'],
|
\App\Models\Statuslabel::class => ['name'],
|
||||||
'\App\Models\Depreciation' => ['name'],
|
\App\Models\Depreciation::class => ['name'],
|
||||||
'\App\Models\AssetModel' => ['name'],
|
\App\Models\AssetModel::class => ['name'],
|
||||||
'\App\Models\Group' => ['name'],
|
\App\Models\Group::class => ['name'],
|
||||||
'\App\Models\Department' => ['name'],
|
\App\Models\Department::class => ['name'],
|
||||||
'\App\Models\Location' => ['name'],
|
\App\Models\Location::class => ['name'],
|
||||||
'\App\Models\User' => ['first_name', 'last_name'],
|
\App\Models\User::class => ['first_name', 'last_name'],
|
||||||
];
|
];
|
||||||
|
|
||||||
$count = array();
|
$count = [];
|
||||||
|
|
||||||
|
foreach ($tables as $classname => $fields) {
|
||||||
|
$count[$classname] = [];
|
||||||
|
$count[$classname]['classname'] = 0;
|
||||||
|
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
$count[$classname]['classname']++;
|
||||||
|
$count[$classname][$field] = 0;
|
||||||
|
|
||||||
foreach ($tables as $classname => $fields) {
|
foreach ($classname::where("$field", 'LIKE', '%&%')->get() as $row) {
|
||||||
$count[$classname] = array();
|
$this->info('Updating '.$field.' for '.$classname);
|
||||||
$count[$classname]['classname'] = 0;
|
$row->{$field} = html_entity_decode($row->{$field}, ENT_QUOTES);
|
||||||
|
$row->save();
|
||||||
foreach($fields as $field) {
|
$count[$classname][$field]++;
|
||||||
|
|
||||||
$count[$classname]['classname']++;
|
|
||||||
$count[$classname][$field] = 0;
|
|
||||||
|
|
||||||
foreach($classname::where("$field",'LIKE','%&%')->get() as $row) {
|
|
||||||
$this->info('Updating '.$field.' for '.$classname);
|
|
||||||
$row->{$field} = html_entity_decode($row->{$field},ENT_QUOTES);
|
|
||||||
$row->save();
|
|
||||||
$count[$classname][$field]++;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->info('Update complete');
|
$this->info('Update complete');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ class FixMismatchedAssetsAndLogs extends Command
|
||||||
*/
|
*/
|
||||||
private $dryrun = false;
|
private $dryrun = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
*
|
*
|
||||||
|
@ -47,30 +46,29 @@ class FixMismatchedAssetsAndLogs extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
if ($this->option('dryrun')) {
|
if ($this->option('dryrun')) {
|
||||||
$this->dryrun = true;
|
$this->dryrun = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->dryrun) {
|
if ($this->dryrun) {
|
||||||
$this->info('This is a DRY RUN - no changes will be saved.' );
|
$this->info('This is a DRY RUN - no changes will be saved.');
|
||||||
}
|
}
|
||||||
|
|
||||||
$mismatch_count = 0;
|
$mismatch_count = 0;
|
||||||
$assets = Asset::whereNotNull('assigned_to')
|
$assets = Asset::whereNotNull('assigned_to')
|
||||||
->where('assigned_type', '=', 'App\\Models\\User')
|
->where('assigned_type', '=', \App\Models\User::class)
|
||||||
->orderBy('id', 'ASC')->get();
|
->orderBy('id', 'ASC')->get();
|
||||||
foreach ($assets as $asset) {
|
foreach ($assets as $asset) {
|
||||||
|
|
||||||
// get the last checkout of the asset
|
// get the last checkout of the asset
|
||||||
if ($checkout_log = Actionlog::where('target_type', '=', 'App\\Models\\User')
|
if ($checkout_log = Actionlog::where('target_type', '=', \App\Models\User::class)
|
||||||
->where('action_type', '=', 'checkout')
|
->where('action_type', '=', 'checkout')
|
||||||
->where('item_id', '=', $asset->id)
|
->where('item_id', '=', $asset->id)
|
||||||
->orderBy('created_at', 'DESC')
|
->orderBy('created_at', 'DESC')
|
||||||
->first()) {
|
->first()) {
|
||||||
|
|
||||||
// Now check for a subsequent checkin log - we want to ignore those
|
// Now check for a subsequent checkin log - we want to ignore those
|
||||||
if (!$checkin_log = Actionlog::where('target_type', '=', 'App\\Models\\User')
|
if (! $checkin_log = Actionlog::where('target_type', '=', \App\Models\User::class)
|
||||||
->where('action_type', '=', 'checkin from')
|
->where('action_type', '=', 'checkin from')
|
||||||
->where('item_id', '=', $asset->id)
|
->where('item_id', '=', $asset->id)
|
||||||
->whereDate('created_at', '>', $checkout_log->created_at)
|
->whereDate('created_at', '>', $checkout_log->created_at)
|
||||||
|
@ -78,28 +76,24 @@ class FixMismatchedAssetsAndLogs extends Command
|
||||||
->first()) {
|
->first()) {
|
||||||
|
|
||||||
//print_r($asset);
|
//print_r($asset);
|
||||||
if ($checkout_log->target_id != $asset->assigned_to) {
|
if ($checkout_log->target_id != $asset->assigned_to) {
|
||||||
$this->error('Log ID: '.$checkout_log->id.' -- Asset ID '. $checkout_log->item_id.' SHOULD BE checked out to User '.$checkout_log->target_id.' but its assigned_to is '.$asset->assigned_to );
|
$this->error('Log ID: '.$checkout_log->id.' -- Asset ID '.$checkout_log->item_id.' SHOULD BE checked out to User '.$checkout_log->target_id.' but its assigned_to is '.$asset->assigned_to);
|
||||||
|
|
||||||
if (!$this->dryrun) {
|
if (! $this->dryrun) {
|
||||||
$asset->assigned_to = $checkout_log->target_id;
|
$asset->assigned_to = $checkout_log->target_id;
|
||||||
if ($asset->save()) {
|
if ($asset->save()) {
|
||||||
$this->info('Asset record updated.');
|
$this->info('Asset record updated.');
|
||||||
} else {
|
} else {
|
||||||
$this->error('Error updating asset: '.$asset->getErrors());
|
$this->error('Error updating asset: '.$asset->getErrors());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$mismatch_count++;
|
|
||||||
}
|
}
|
||||||
} else {
|
$mismatch_count++;
|
||||||
//$this->info('Asset ID '.$asset->id.': There is a checkin '.$checkin_log->created_at.' after this checkout '.$checkout_log->created_at);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
//$this->info('Asset ID '.$asset->id.': There is a checkin '.$checkin_log->created_at.' after this checkout '.$checkout_log->created_at);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
$this->info($mismatch_count.' mismatched assets.');
|
$this->info($mismatch_count.' mismatched assets.');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Models\Location;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use League\Csv\Reader;
|
use League\Csv\Reader;
|
||||||
use App\Models\Location;
|
|
||||||
|
|
||||||
class ImportLocations extends Command
|
class ImportLocations extends Command
|
||||||
{
|
{
|
||||||
|
@ -39,10 +39,8 @@ class ImportLocations extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
if (! ini_get('auto_detect_line_endings')) {
|
||||||
|
ini_set('auto_detect_line_endings', '1');
|
||||||
if (!ini_get("auto_detect_line_endings")) {
|
|
||||||
ini_set("auto_detect_line_endings", '1');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = $this->argument('filename');
|
$filename = $this->argument('filename');
|
||||||
|
@ -53,18 +51,17 @@ class ImportLocations extends Command
|
||||||
|
|
||||||
// Import parent location names first if they don't exist
|
// Import parent location names first if they don't exist
|
||||||
foreach ($results as $parent_index => $parent_row) {
|
foreach ($results as $parent_index => $parent_row) {
|
||||||
|
|
||||||
if (array_key_exists('Parent Name', $parent_row)) {
|
if (array_key_exists('Parent Name', $parent_row)) {
|
||||||
$parent_name = trim($parent_row['Parent Name']);
|
$parent_name = trim($parent_row['Parent Name']);
|
||||||
if (array_key_exists('Name', $parent_row)) {
|
if (array_key_exists('Name', $parent_row)) {
|
||||||
$this->info('- Parent: ' . $parent_name . ' in row as: ' . trim($parent_row['Parent Name']));
|
$this->info('- Parent: '.$parent_name.' in row as: '.trim($parent_row['Parent Name']));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save parent location name
|
// Save parent location name
|
||||||
// This creates a sort of name-stub that we'll update later on in this script
|
// This creates a sort of name-stub that we'll update later on in this script
|
||||||
$parent_location = Location::firstOrCreate(array('name' => $parent_name));
|
$parent_location = Location::firstOrCreate(['name' => $parent_name]);
|
||||||
if (array_key_exists('Name', $parent_row)) {
|
if (array_key_exists('Name', $parent_row)) {
|
||||||
$this->info('Parent for ' . $parent_row['Name'] . ' is ' . $parent_name . '. Attempting to save ' . $parent_name . '.');
|
$this->info('Parent for '.$parent_row['Name'].' is '.$parent_name.'. Attempting to save '.$parent_name.'.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the record was updated or created.
|
// Check if the record was updated or created.
|
||||||
|
@ -74,18 +71,15 @@ class ImportLocations extends Command
|
||||||
} else {
|
} else {
|
||||||
$this->info('- Parent location '.$parent_name.' was created.');
|
$this->info('- Parent location '.$parent_name.' was created.');
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->info('- No Parent Name provided, so no parent location will be created.');
|
$this->info('- No Parent Name provided, so no parent location will be created.');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info('----- Parents Created.... backfilling additional details... --------');
|
$this->info('----- Parents Created.... backfilling additional details... --------');
|
||||||
// Loop through ALL records and add/update them if there are additional fields
|
// Loop through ALL records and add/update them if there are additional fields
|
||||||
// besides name
|
// besides name
|
||||||
foreach ($results as $index => $row) {
|
foreach ($results as $index => $row) {
|
||||||
|
|
||||||
if (array_key_exists('Parent Name', $row)) {
|
if (array_key_exists('Parent Name', $row)) {
|
||||||
$parent_name = trim($row['Parent Name']);
|
$parent_name = trim($row['Parent Name']);
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,11 +88,12 @@ class ImportLocations extends Command
|
||||||
|
|
||||||
// Set the location attributes to save
|
// Set the location attributes to save
|
||||||
if (array_key_exists('Name', $row)) {
|
if (array_key_exists('Name', $row)) {
|
||||||
$location = Location::firstOrCreate(array('name' => trim($row['Name'])));
|
$location = Location::firstOrCreate(['name' => trim($row['Name'])]);
|
||||||
$location->name = trim($row['Name']);
|
$location->name = trim($row['Name']);
|
||||||
$this->info('Checking location: '.$location->name);
|
$this->info('Checking location: '.$location->name);
|
||||||
} else {
|
} else {
|
||||||
$this->error('Location name is required and is missing from at least one row in this dataset. Check your CSV for extra trailing rows and try again.');
|
$this->error('Location name is required and is missing from at least one row in this dataset. Check your CSV for extra trailing rows and try again.');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (array_key_exists('Currency', $row)) {
|
if (array_key_exists('Currency', $row)) {
|
||||||
|
@ -126,7 +121,6 @@ class ImportLocations extends Command
|
||||||
$location->ldap_ou = trim($row['OU']);
|
$location->ldap_ou = trim($row['OU']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// If a parent name is provided, we created it earlier in the script,
|
// If a parent name is provided, we created it earlier in the script,
|
||||||
// so let's grab that ID
|
// so let's grab that ID
|
||||||
if ($parent_name) {
|
if ($parent_name) {
|
||||||
|
@ -142,21 +136,15 @@ class ImportLocations extends Command
|
||||||
// Check if the record was updated or created.
|
// Check if the record was updated or created.
|
||||||
// This is mostly for clearer debugging.
|
// This is mostly for clearer debugging.
|
||||||
if ($location->exists) {
|
if ($location->exists) {
|
||||||
$this->info('Location ' . $location->name . ' already exists. Updating...');
|
$this->info('Location '.$location->name.' already exists. Updating...');
|
||||||
} else {
|
} else {
|
||||||
$this->info('- Location '.$location->name.' was created. ');
|
$this->info('- Location '.$location->name.' was created. ');
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's a validation error, display that
|
// If there's a validation error, display that
|
||||||
} else {
|
} else {
|
||||||
$this->error('- Non-parent Location '.$location->name.' could not be created: '.$location->getErrors() );
|
$this->error('- Non-parent Location '.$location->name.' could not be created: '.$location->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,11 @@
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\Department;
|
use App\Models\Department;
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use App\Models\Setting;
|
|
||||||
use App\Models\Ldap;
|
use App\Models\Ldap;
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\Location;
|
use App\Models\Location;
|
||||||
|
use App\Models\Setting;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
class LdapSync extends Command
|
class LdapSync extends Command
|
||||||
|
@ -54,7 +54,7 @@ class LdapSync extends Command
|
||||||
$ldap_result_email = Setting::getSettings()->ldap_email;
|
$ldap_result_email = Setting::getSettings()->ldap_email;
|
||||||
$ldap_result_phone = Setting::getSettings()->ldap_phone_field;
|
$ldap_result_phone = Setting::getSettings()->ldap_phone_field;
|
||||||
$ldap_result_jobtitle = Setting::getSettings()->ldap_jobtitle;
|
$ldap_result_jobtitle = Setting::getSettings()->ldap_jobtitle;
|
||||||
$ldap_result_country = Setting::getSettings()->ldap_country;
|
$ldap_result_country = Setting::getSettings()->ldap_country;
|
||||||
$ldap_result_dept = Setting::getSettings()->ldap_dept;
|
$ldap_result_dept = Setting::getSettings()->ldap_dept;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -62,14 +62,15 @@ class LdapSync extends Command
|
||||||
Ldap::bindAdminToLdap($ldapconn);
|
Ldap::bindAdminToLdap($ldapconn);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if ($this->option('json_summary')) {
|
if ($this->option('json_summary')) {
|
||||||
$json_summary = [ "error" => true, "error_message" => $e->getMessage(), "summary" => [] ];
|
$json_summary = ['error' => true, 'error_message' => $e->getMessage(), 'summary' => []];
|
||||||
$this->info(json_encode($json_summary));
|
$this->info(json_encode($json_summary));
|
||||||
}
|
}
|
||||||
LOG::info($e);
|
LOG::info($e);
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$summary = array();
|
$summary = [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($this->option('base_dn') != '') {
|
if ($this->option('base_dn') != '') {
|
||||||
|
@ -81,78 +82,78 @@ class LdapSync extends Command
|
||||||
$results = Ldap::findLdapUsers($search_base);
|
$results = Ldap::findLdapUsers($search_base);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
if ($this->option('json_summary')) {
|
if ($this->option('json_summary')) {
|
||||||
$json_summary = [ "error" => true, "error_message" => $e->getMessage(), "summary" => [] ];
|
$json_summary = ['error' => true, 'error_message' => $e->getMessage(), 'summary' => []];
|
||||||
$this->info(json_encode($json_summary));
|
$this->info(json_encode($json_summary));
|
||||||
}
|
}
|
||||||
LOG::info($e);
|
LOG::info($e);
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Determine which location to assign users to by default. */
|
/* Determine which location to assign users to by default. */
|
||||||
$location = NULL; // FIXME - this would be better called "$default_location", which is more explicit about its purpose
|
$location = null; // FIXME - this would be better called "$default_location", which is more explicit about its purpose
|
||||||
|
|
||||||
if ($this->option('location')!='') {
|
if ($this->option('location') != '') {
|
||||||
$location = Location::where('name', '=', $this->option('location'))->first();
|
$location = Location::where('name', '=', $this->option('location'))->first();
|
||||||
LOG::debug('Location name '.$this->option('location').' passed');
|
LOG::debug('Location name '.$this->option('location').' passed');
|
||||||
LOG::debug('Importing to '.$location->name.' ('.$location->id.')');
|
LOG::debug('Importing to '.$location->name.' ('.$location->id.')');
|
||||||
} elseif ($this->option('location_id')!='') {
|
} elseif ($this->option('location_id') != '') {
|
||||||
$location = Location::where('id', '=', $this->option('location_id'))->first();
|
$location = Location::where('id', '=', $this->option('location_id'))->first();
|
||||||
LOG::debug('Location ID '.$this->option('location_id').' passed');
|
LOG::debug('Location ID '.$this->option('location_id').' passed');
|
||||||
LOG::debug('Importing to '.$location->name.' ('.$location->id.')');
|
LOG::debug('Importing to '.$location->name.' ('.$location->id.')');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($location)) {
|
if (! isset($location)) {
|
||||||
LOG::debug('That location is invalid or a location was not provided, so no location will be assigned by default.');
|
LOG::debug('That location is invalid or a location was not provided, so no location will be assigned by default.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Process locations with explicitly defined OUs, if doing a full import. */
|
/* Process locations with explicitly defined OUs, if doing a full import. */
|
||||||
if ($this->option('base_dn')=='') {
|
if ($this->option('base_dn') == '') {
|
||||||
// Retrieve locations with a mapped OU, and sort them from the shallowest to deepest OU (see #3993)
|
// Retrieve locations with a mapped OU, and sort them from the shallowest to deepest OU (see #3993)
|
||||||
$ldap_ou_locations = Location::where('ldap_ou', '!=', '')->get()->toArray();
|
$ldap_ou_locations = Location::where('ldap_ou', '!=', '')->get()->toArray();
|
||||||
$ldap_ou_lengths = array();
|
$ldap_ou_lengths = [];
|
||||||
|
|
||||||
foreach ($ldap_ou_locations as $ou_loc) {
|
foreach ($ldap_ou_locations as $ou_loc) {
|
||||||
$ldap_ou_lengths[] = strlen($ou_loc["ldap_ou"]);
|
$ldap_ou_lengths[] = strlen($ou_loc['ldap_ou']);
|
||||||
}
|
}
|
||||||
|
|
||||||
array_multisort($ldap_ou_lengths, SORT_ASC, $ldap_ou_locations);
|
array_multisort($ldap_ou_lengths, SORT_ASC, $ldap_ou_locations);
|
||||||
|
|
||||||
if (sizeof($ldap_ou_locations) > 0) {
|
if (count($ldap_ou_locations) > 0) {
|
||||||
LOG::debug('Some locations have special OUs set. Locations will be automatically set for users in those OUs.');
|
LOG::debug('Some locations have special OUs set. Locations will be automatically set for users in those OUs.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject location information fields
|
// Inject location information fields
|
||||||
for ($i = 0; $i < $results["count"]; $i++) {
|
for ($i = 0; $i < $results['count']; $i++) {
|
||||||
$results[$i]["ldap_location_override"] = false;
|
$results[$i]['ldap_location_override'] = false;
|
||||||
$results[$i]["location_id"] = 0;
|
$results[$i]['location_id'] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab subsets based on location-specific DNs, and overwrite location for these users.
|
// Grab subsets based on location-specific DNs, and overwrite location for these users.
|
||||||
foreach ($ldap_ou_locations as $ldap_loc) {
|
foreach ($ldap_ou_locations as $ldap_loc) {
|
||||||
try {
|
try {
|
||||||
$location_users = Ldap::findLdapUsers($ldap_loc["ldap_ou"]);
|
$location_users = Ldap::findLdapUsers($ldap_loc['ldap_ou']);
|
||||||
} catch (\Exception $e) { // FIXME: this is stolen from line 77 or so above
|
} catch (\Exception $e) { // FIXME: this is stolen from line 77 or so above
|
||||||
if ($this->option('json_summary')) {
|
if ($this->option('json_summary')) {
|
||||||
$json_summary = [ "error" => true, "error_message" => trans('admin/users/message.error.ldap_could_not_search')." Location: ".$ldap_loc['name']." (ID: ".$ldap_loc['id'].") cannot connect to \"".$ldap_loc["ldap_ou"]."\" - ".$e->getMessage(), "summary" => [] ];
|
$json_summary = ['error' => true, 'error_message' => trans('admin/users/message.error.ldap_could_not_search').' Location: '.$ldap_loc['name'].' (ID: '.$ldap_loc['id'].') cannot connect to "'.$ldap_loc['ldap_ou'].'" - '.$e->getMessage(), 'summary' => []];
|
||||||
$this->info(json_encode($json_summary));
|
$this->info(json_encode($json_summary));
|
||||||
}
|
}
|
||||||
LOG::info($e);
|
LOG::info($e);
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
$usernames = array();
|
$usernames = [];
|
||||||
for ($i = 0; $i < $location_users["count"]; $i++) {
|
for ($i = 0; $i < $location_users['count']; $i++) {
|
||||||
|
|
||||||
if (array_key_exists($ldap_result_username, $location_users[$i])) {
|
if (array_key_exists($ldap_result_username, $location_users[$i])) {
|
||||||
$location_users[$i]["ldap_location_override"] = true;
|
$location_users[$i]['ldap_location_override'] = true;
|
||||||
$location_users[$i]["location_id"] = $ldap_loc["id"];
|
$location_users[$i]['location_id'] = $ldap_loc['id'];
|
||||||
$usernames[] = $location_users[$i][$ldap_result_username][0];
|
$usernames[] = $location_users[$i][$ldap_result_username][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete located users from the general group.
|
// Delete located users from the general group.
|
||||||
foreach ($results as $key => $generic_entry) {
|
foreach ($results as $key => $generic_entry) {
|
||||||
if ((is_array($generic_entry)) && (array_key_exists($ldap_result_username, $generic_entry))) {
|
if ((is_array($generic_entry)) && (array_key_exists($ldap_result_username, $generic_entry))) {
|
||||||
if (in_array($generic_entry[$ldap_result_username][0], $usernames)) {
|
if (in_array($generic_entry[$ldap_result_username][0], $usernames)) {
|
||||||
unset($results[$key]);
|
unset($results[$key]);
|
||||||
}
|
}
|
||||||
|
@ -166,55 +167,52 @@ class LdapSync extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create user account entries in Snipe-IT */
|
/* Create user account entries in Snipe-IT */
|
||||||
$tmp_pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20);
|
$tmp_pass = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 20);
|
||||||
$pass = bcrypt($tmp_pass);
|
$pass = bcrypt($tmp_pass);
|
||||||
|
|
||||||
for ($i = 0; $i < $results["count"]; $i++) {
|
for ($i = 0; $i < $results['count']; $i++) {
|
||||||
if (empty($ldap_result_active_flag) || $results[$i][$ldap_result_active_flag][0] == "TRUE") {
|
if (empty($ldap_result_active_flag) || $results[$i][$ldap_result_active_flag][0] == 'TRUE') {
|
||||||
|
$item = [];
|
||||||
$item = array();
|
$item['username'] = isset($results[$i][$ldap_result_username][0]) ? $results[$i][$ldap_result_username][0] : '';
|
||||||
$item["username"] = isset($results[$i][$ldap_result_username][0]) ? $results[$i][$ldap_result_username][0] : "";
|
$item['employee_number'] = isset($results[$i][$ldap_result_emp_num][0]) ? $results[$i][$ldap_result_emp_num][0] : '';
|
||||||
$item["employee_number"] = isset($results[$i][$ldap_result_emp_num][0]) ? $results[$i][$ldap_result_emp_num][0] : "";
|
$item['lastname'] = isset($results[$i][$ldap_result_last_name][0]) ? $results[$i][$ldap_result_last_name][0] : '';
|
||||||
$item["lastname"] = isset($results[$i][$ldap_result_last_name][0]) ? $results[$i][$ldap_result_last_name][0] : "";
|
$item['firstname'] = isset($results[$i][$ldap_result_first_name][0]) ? $results[$i][$ldap_result_first_name][0] : '';
|
||||||
$item["firstname"] = isset($results[$i][$ldap_result_first_name][0]) ? $results[$i][$ldap_result_first_name][0] : "";
|
$item['email'] = isset($results[$i][$ldap_result_email][0]) ? $results[$i][$ldap_result_email][0] : '';
|
||||||
$item["email"] = isset($results[$i][$ldap_result_email][0]) ? $results[$i][$ldap_result_email][0] : "" ;
|
$item['ldap_location_override'] = isset($results[$i]['ldap_location_override']) ? $results[$i]['ldap_location_override'] : '';
|
||||||
$item["ldap_location_override"] = isset($results[$i]["ldap_location_override"]) ? $results[$i]["ldap_location_override"]:"";
|
$item['location_id'] = isset($results[$i]['location_id']) ? $results[$i]['location_id'] : '';
|
||||||
$item["location_id"] = isset($results[$i]["location_id"]) ? $results[$i]["location_id"]:"";
|
$item['telephone'] = isset($results[$i][$ldap_result_phone][0]) ? $results[$i][$ldap_result_phone][0] : '';
|
||||||
$item["telephone"] = isset($results[$i][$ldap_result_phone][0]) ? $results[$i][$ldap_result_phone][0] : "";
|
$item['jobtitle'] = isset($results[$i][$ldap_result_jobtitle][0]) ? $results[$i][$ldap_result_jobtitle][0] : '';
|
||||||
$item["jobtitle"] = isset($results[$i][$ldap_result_jobtitle][0]) ? $results[$i][$ldap_result_jobtitle][0] : "";
|
$item['country'] = isset($results[$i][$ldap_result_country][0]) ? $results[$i][$ldap_result_country][0] : '';
|
||||||
$item["country"] = isset($results[$i][$ldap_result_country][0]) ? $results[$i][$ldap_result_country][0] : "";
|
$item['department'] = isset($results[$i][$ldap_result_dept][0]) ? $results[$i][$ldap_result_dept][0] : '';
|
||||||
$item["department"] = isset($results[$i][$ldap_result_dept][0]) ? $results[$i][$ldap_result_dept][0] : "";
|
|
||||||
|
|
||||||
|
|
||||||
$department = Department::firstOrCreate([
|
$department = Department::firstOrCreate([
|
||||||
'name' => $item["department"],
|
'name' => $item['department'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$user = User::where('username', $item['username'])->first();
|
||||||
$user = User::where('username', $item["username"])->first();
|
|
||||||
if ($user) {
|
if ($user) {
|
||||||
// Updating an existing user.
|
// Updating an existing user.
|
||||||
$item["createorupdate"] = 'updated';
|
$item['createorupdate'] = 'updated';
|
||||||
} else {
|
} else {
|
||||||
// Creating a new user.
|
// Creating a new user.
|
||||||
$user = new User;
|
$user = new User;
|
||||||
$user->password = $pass;
|
$user->password = $pass;
|
||||||
$user->activated = 0;
|
$user->activated = 0;
|
||||||
$item["createorupdate"] = 'created';
|
$item['createorupdate'] = 'created';
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->first_name = $item["firstname"];
|
$user->first_name = $item['firstname'];
|
||||||
$user->last_name = $item["lastname"];
|
$user->last_name = $item['lastname'];
|
||||||
$user->username = $item["username"];
|
$user->username = $item['username'];
|
||||||
$user->email = $item["email"];
|
$user->email = $item['email'];
|
||||||
$user->employee_num = e($item["employee_number"]);
|
$user->employee_num = e($item['employee_number']);
|
||||||
$user->phone = $item["telephone"];
|
$user->phone = $item['telephone'];
|
||||||
$user->jobtitle = $item["jobtitle"];
|
$user->jobtitle = $item['jobtitle'];
|
||||||
$user->country = $item["country"];
|
$user->country = $item['country'];
|
||||||
$user->department_id = $department->id;
|
$user->department_id = $department->id;
|
||||||
|
|
||||||
// Sync activated state for Active Directory.
|
// Sync activated state for Active Directory.
|
||||||
if ( array_key_exists('useraccountcontrol', $results[$i]) ) {
|
if (array_key_exists('useraccountcontrol', $results[$i])) {
|
||||||
/* The following is _probably_ the correct logic, but we can't use it because
|
/* The following is _probably_ the correct logic, but we can't use it because
|
||||||
some users may have been dependent upon the previous behavior, and this
|
some users may have been dependent upon the previous behavior, and this
|
||||||
could cause additional access to be available to users they don't want
|
could cause additional access to be available to users they don't want
|
||||||
|
@ -231,7 +229,7 @@ class LdapSync extends Command
|
||||||
} else {
|
} else {
|
||||||
$user->activated = 0;
|
$user->activated = 0;
|
||||||
} */
|
} */
|
||||||
$enabled_accounts = [
|
$enabled_accounts = [
|
||||||
'512', // 0x200 NORMAL_ACCOUNT
|
'512', // 0x200 NORMAL_ACCOUNT
|
||||||
'544', // 0x220 NORMAL_ACCOUNT, PASSWD_NOTREQD
|
'544', // 0x220 NORMAL_ACCOUNT, PASSWD_NOTREQD
|
||||||
'66048', // 0x10200 NORMAL_ACCOUNT, DONT_EXPIRE_PASSWORD
|
'66048', // 0x10200 NORMAL_ACCOUNT, DONT_EXPIRE_PASSWORD
|
||||||
|
@ -240,27 +238,25 @@ class LdapSync extends Command
|
||||||
'262688', // 0x40220 NORMAL_ACCOUNT, PASSWD_NOTREQD, SMARTCARD_REQUIRED
|
'262688', // 0x40220 NORMAL_ACCOUNT, PASSWD_NOTREQD, SMARTCARD_REQUIRED
|
||||||
'328192', // 0x50200 NORMAL_ACCOUNT, SMARTCARD_REQUIRED, DONT_EXPIRE_PASSWORD
|
'328192', // 0x50200 NORMAL_ACCOUNT, SMARTCARD_REQUIRED, DONT_EXPIRE_PASSWORD
|
||||||
'328224', // 0x50220 NORMAL_ACCOUNT, PASSWD_NOT_REQD, SMARTCARD_REQUIRED, DONT_EXPIRE_PASSWORD
|
'328224', // 0x50220 NORMAL_ACCOUNT, PASSWD_NOT_REQD, SMARTCARD_REQUIRED, DONT_EXPIRE_PASSWORD
|
||||||
'4260352',// 0x410200 NORMAL_ACCOUNT, DONT_EXPIRE_PASSWORD, DONT_REQ_PREAUTH
|
'4260352', // 0x410200 NORMAL_ACCOUNT, DONT_EXPIRE_PASSWORD, DONT_REQ_PREAUTH
|
||||||
'1049088',// 0x100200 NORMAL_ACCOUNT, NOT_DELEGATED
|
'1049088', // 0x100200 NORMAL_ACCOUNT, NOT_DELEGATED
|
||||||
];
|
];
|
||||||
$user->activated = ( in_array($results[$i]['useraccountcontrol'][0], $enabled_accounts) ) ? 1 : 0;
|
$user->activated = (in_array($results[$i]['useraccountcontrol'][0], $enabled_accounts)) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we're not using AD, and there isn't an activated flag set, activate all users
|
// If we're not using AD, and there isn't an activated flag set, activate all users
|
||||||
elseif (empty($ldap_result_active_flag)) {
|
elseif (empty($ldap_result_active_flag)) {
|
||||||
$user->activated = 1;
|
$user->activated = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($item['ldap_location_override'] == true) {
|
if ($item['ldap_location_override'] == true) {
|
||||||
$user->location_id = $item['location_id'];
|
$user->location_id = $item['location_id'];
|
||||||
} elseif ((isset($location)) && (!empty($location))) {
|
} elseif ((isset($location)) && (! empty($location))) {
|
||||||
|
|
||||||
if ((is_array($location)) && (array_key_exists('id', $location))) {
|
if ((is_array($location)) && (array_key_exists('id', $location))) {
|
||||||
$user->location_id = $location['id'];
|
$user->location_id = $location['id'];
|
||||||
} elseif (is_object($location)) {
|
} elseif (is_object($location)) {
|
||||||
$user->location_id = $location->id;
|
$user->location_id = $location->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$user->ldap_import = 1;
|
$user->ldap_import = 1;
|
||||||
|
@ -268,31 +264,30 @@ class LdapSync extends Command
|
||||||
$errors = '';
|
$errors = '';
|
||||||
|
|
||||||
if ($user->save()) {
|
if ($user->save()) {
|
||||||
$item["note"] = $item["createorupdate"];
|
$item['note'] = $item['createorupdate'];
|
||||||
$item["status"]='success';
|
$item['status'] = 'success';
|
||||||
} else {
|
} else {
|
||||||
foreach ($user->getErrors()->getMessages() as $key => $err) {
|
foreach ($user->getErrors()->getMessages() as $key => $err) {
|
||||||
$errors .= $err[0];
|
$errors .= $err[0];
|
||||||
}
|
}
|
||||||
$item["note"] = $errors;
|
$item['note'] = $errors;
|
||||||
$item["status"]='error';
|
$item['status'] = 'error';
|
||||||
}
|
}
|
||||||
|
|
||||||
array_push($summary, $item);
|
array_push($summary, $item);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->option('summary')) {
|
if ($this->option('summary')) {
|
||||||
for ($x = 0; $x < count($summary); $x++) {
|
for ($x = 0; $x < count($summary); $x++) {
|
||||||
if ($summary[$x]['status']=='error') {
|
if ($summary[$x]['status'] == 'error') {
|
||||||
$this->error('ERROR: '.$summary[$x]['firstname'].' '.$summary[$x]['lastname'].' (username: '.$summary[$x]['username'].') was not imported: '.$summary[$x]['note']);
|
$this->error('ERROR: '.$summary[$x]['firstname'].' '.$summary[$x]['lastname'].' (username: '.$summary[$x]['username'].') was not imported: '.$summary[$x]['note']);
|
||||||
} else {
|
} else {
|
||||||
$this->info('User '.$summary[$x]['firstname'].' '.$summary[$x]['lastname'].' (username: '.$summary[$x]['username'].') was '.strtoupper($summary[$x]['createorupdate']).'.');
|
$this->info('User '.$summary[$x]['firstname'].' '.$summary[$x]['lastname'].' (username: '.$summary[$x]['username'].') was '.strtoupper($summary[$x]['createorupdate']).'.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ($this->option('json_summary')) {
|
} elseif ($this->option('json_summary')) {
|
||||||
$json_summary = [ "error" => false, "error_message" => "", "summary" => $summary ]; // hardcoding the error to false and the error_message to blank seems a bit weird
|
$json_summary = ['error' => false, 'error_message' => '', 'summary' => $summary]; // hardcoding the error to false and the error_message to blank seems a bit weird
|
||||||
$this->info(json_encode($json_summary));
|
$this->info(json_encode($json_summary));
|
||||||
} else {
|
} else {
|
||||||
return $summary;
|
return $summary;
|
||||||
|
|
|
@ -4,13 +4,13 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Log;
|
use Adldap\Models\User as AdldapUser;
|
||||||
use Exception;
|
use App\Models\Location;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Services\LdapAd;
|
use App\Services\LdapAd;
|
||||||
use App\Models\Location;
|
use Exception;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Adldap\Models\User as AdldapUser;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LDAP / AD sync command.
|
* LDAP / AD sync command.
|
||||||
|
@ -96,9 +96,9 @@ class LdapSyncNg extends Command
|
||||||
public function __construct(LdapAd $ldap)
|
public function __construct(LdapAd $ldap)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->ldap = $ldap;
|
$this->ldap = $ldap;
|
||||||
$this->settings = $this->ldap->ldapSettings;
|
$this->settings = $this->ldap->ldapSettings;
|
||||||
$this->summary = collect();
|
$this->summary = collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,22 +108,21 @@ class LdapSyncNg extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
$dispatcher = \Adldap\Adldap::getEventDispatcher();
|
||||||
$dispatcher = \Adldap\Adldap::getEventDispatcher();
|
|
||||||
|
|
||||||
// Listen for all model events.
|
// Listen for all model events.
|
||||||
$dispatcher->listen('Adldap\Models\Events\*', function ($eventName, array $data) {
|
$dispatcher->listen('Adldap\Models\Events\*', function ($eventName, array $data) {
|
||||||
echo $eventName; // Returns 'Adldap\Models\Events\Updating'
|
echo $eventName; // Returns 'Adldap\Models\Events\Updating'
|
||||||
var_dump($data); // Returns [0] => (object) Adldap\Models\Events\Updating;
|
var_dump($data); // Returns [0] => (object) Adldap\Models\Events\Updating;
|
||||||
\Log::debug("Event: ".$eventName." data - ".print_r($data, true));
|
\Log::debug('Event: '.$eventName.' data - '.print_r($data, true));
|
||||||
});
|
});
|
||||||
$dispatcher->listen('Adldap\Auth\Events\*', function ($eventName, array $data) {
|
$dispatcher->listen('Adldap\Auth\Events\*', function ($eventName, array $data) {
|
||||||
echo $eventName; // Returns 'Adldap\Models\Events\Updating'
|
echo $eventName; // Returns 'Adldap\Models\Events\Updating'
|
||||||
var_dump($data); // Returns [0] => (object) Adldap\Models\Events\Updating;
|
var_dump($data); // Returns [0] => (object) Adldap\Models\Events\Updating;
|
||||||
\Log::debug("Event: ".$eventName." data - ".print_r($data, true));
|
\Log::debug('Event: '.$eventName.' data - '.print_r($data, true));
|
||||||
});
|
});
|
||||||
|
|
||||||
ini_set('max_execution_time', env('LDAP_TIME_LIM', "600")); //600 seconds = 10 minutes
|
ini_set('max_execution_time', env('LDAP_TIME_LIM', '600')); //600 seconds = 10 minutes
|
||||||
ini_set('memory_limit', '500M');
|
ini_set('memory_limit', '500M');
|
||||||
$old_error_reporting = error_reporting(); // grab old error_reporting .ini setting, for later re-enablement
|
$old_error_reporting = error_reporting(); // grab old error_reporting .ini setting, for later re-enablement
|
||||||
error_reporting($old_error_reporting & ~E_DEPRECATED); // disable deprecation warnings, for LDAP in PHP 7.4 (and greater)
|
error_reporting($old_error_reporting & ~E_DEPRECATED); // disable deprecation warnings, for LDAP in PHP 7.4 (and greater)
|
||||||
|
@ -138,7 +137,7 @@ class LdapSyncNg extends Command
|
||||||
/*
|
/*
|
||||||
* Use the default location if set, this is needed for the LDAP users sync page
|
* Use the default location if set, this is needed for the LDAP users sync page
|
||||||
*/
|
*/
|
||||||
if (!$this->option('base_dn') && null == $this->defaultLocation) {
|
if (! $this->option('base_dn') && null == $this->defaultLocation) {
|
||||||
$this->getMappedLocations();
|
$this->getMappedLocations();
|
||||||
}
|
}
|
||||||
$this->processLdapUsers();
|
$this->processLdapUsers();
|
||||||
|
@ -150,6 +149,7 @@ class LdapSyncNg extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
error_reporting($old_error_reporting); // re-enable deprecation warnings.
|
error_reporting($old_error_reporting); // re-enable deprecation warnings.
|
||||||
|
|
||||||
return $this->getSummary();
|
return $this->getSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,17 +205,17 @@ class LdapSyncNg extends Command
|
||||||
'location_id' => $user->location_id,
|
'location_id' => $user->location_id,
|
||||||
];
|
];
|
||||||
// Only update the database if is not a dry run
|
// Only update the database if is not a dry run
|
||||||
if (!$this->dryrun) {
|
if (! $this->dryrun) {
|
||||||
if ($user->isDirty()) { //if nothing on the user changed, don't bother trying to save anything nor put anything in the summary
|
if ($user->isDirty()) { //if nothing on the user changed, don't bother trying to save anything nor put anything in the summary
|
||||||
if ($user->save()) {
|
if ($user->save()) {
|
||||||
$summary['note'] = ($user->wasRecentlyCreated ? 'CREATED' : 'UPDATED');
|
$summary['note'] = ($user->wasRecentlyCreated ? 'CREATED' : 'UPDATED');
|
||||||
$summary['status'] = 'SUCCESS';
|
$summary['status'] = 'SUCCESS';
|
||||||
} else {
|
} else {
|
||||||
$errors = '';
|
$errors = '';
|
||||||
foreach ($user->getErrors()->getMessages() as $error) {
|
foreach ($user->getErrors()->getMessages() as $error) {
|
||||||
$errors .= implode(", ",$error);
|
$errors .= implode(', ', $error);
|
||||||
}
|
}
|
||||||
$summary['note'] = $snipeUser->getDN().' was not imported. REASON: '.$errors;
|
$summary['note'] = $snipeUser->getDN().' was not imported. REASON: '.$errors;
|
||||||
$summary['status'] = 'ERROR';
|
$summary['status'] = 'ERROR';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -224,7 +224,7 @@ class LdapSyncNg extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
// $summary['note'] = ($user->getOriginal('username') ? 'UPDATED' : 'CREATED'); // this seems, kinda, like, superfluous, relative to the $summary['note'] thing above, yeah?
|
// $summary['note'] = ($user->getOriginal('username') ? 'UPDATED' : 'CREATED'); // this seems, kinda, like, superfluous, relative to the $summary['note'] thing above, yeah?
|
||||||
if($summary) { //if the $user wasn't dirty, $summary was set to null so that we will skip the following push()
|
if ($summary) { //if the $user wasn't dirty, $summary was set to null so that we will skip the following push()
|
||||||
$this->summary->push($summary);
|
$this->summary->push($summary);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,14 +235,13 @@ class LdapSyncNg extends Command
|
||||||
* @author Wes Hulette <jwhulette@gmail.com>
|
* @author Wes Hulette <jwhulette@gmail.com>
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
private function processLdapUsers(): void
|
private function processLdapUsers(): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
\Log::debug("CAL:LING GET LDAP SUSERS");
|
\Log::debug('CAL:LING GET LDAP SUSERS');
|
||||||
$ldapUsers = $this->ldap->getLdapUsers();
|
$ldapUsers = $this->ldap->getLdapUsers();
|
||||||
\Log::debug("END CALLING GET LDAP USERS");
|
\Log::debug('END CALLING GET LDAP USERS');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->outputError($e);
|
$this->outputError($e);
|
||||||
exit($e->getMessage());
|
exit($e->getMessage());
|
||||||
|
|
|
@ -2,10 +2,9 @@
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
class MergeUsersByUsername extends Command
|
class MergeUsersByUsername extends Command
|
||||||
{
|
{
|
||||||
|
@ -44,7 +43,7 @@ class MergeUsersByUsername extends Command
|
||||||
$users = User::where('username', 'LIKE', '%@%')->whereNull('deleted_at')->get();
|
$users = User::where('username', 'LIKE', '%@%')->whereNull('deleted_at')->get();
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$parts = explode("@", $user->username);
|
$parts = explode('@', $user->username);
|
||||||
$bad_users = User::where('username', '=', $parts[0])->whereNull('deleted_at')->with('assets', 'manager', 'userlog', 'licenses', 'consumables', 'accessories', 'managedLocations')->get();
|
$bad_users = User::where('username', '=', $parts[0])->whereNull('deleted_at')->with('assets', 'manager', 'userlog', 'licenses', 'consumables', 'accessories', 'managedLocations')->get();
|
||||||
|
|
||||||
foreach ($bad_users as $bad_user) {
|
foreach ($bad_users as $bad_user) {
|
||||||
|
@ -52,61 +51,55 @@ class MergeUsersByUsername extends Command
|
||||||
|
|
||||||
// Walk the list of assets
|
// Walk the list of assets
|
||||||
foreach ($bad_user->assets as $asset) {
|
foreach ($bad_user->assets as $asset) {
|
||||||
$this->info( 'Updating asset '.$asset->asset_tag.' '.$asset->id.' to user '.$user->id);
|
$this->info('Updating asset '.$asset->asset_tag.' '.$asset->id.' to user '.$user->id);
|
||||||
$asset->assigned_to = $user->id;
|
$asset->assigned_to = $user->id;
|
||||||
if (!$asset->save()) {
|
if (! $asset->save()) {
|
||||||
$this->error( 'Could not update assigned_to field on asset '.$asset->asset_tag.' '.$asset->id.' to user '.$user->id);
|
$this->error('Could not update assigned_to field on asset '.$asset->asset_tag.' '.$asset->id.' to user '.$user->id);
|
||||||
$this->error( 'Error saving: '.$asset->getErrors());
|
$this->error('Error saving: '.$asset->getErrors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk the list of licenses
|
// Walk the list of licenses
|
||||||
foreach ($bad_user->licenses as $license) {
|
foreach ($bad_user->licenses as $license) {
|
||||||
$this->info( 'Updating license '.$license->name.' '.$license->id.' to user '.$user->id);
|
$this->info('Updating license '.$license->name.' '.$license->id.' to user '.$user->id);
|
||||||
$bad_user->licenses()->updateExistingPivot($license->id, ['assigned_to' => $user->id]);
|
$bad_user->licenses()->updateExistingPivot($license->id, ['assigned_to' => $user->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk the list of consumables
|
// Walk the list of consumables
|
||||||
foreach ($bad_user->consumables as $consumable) {
|
foreach ($bad_user->consumables as $consumable) {
|
||||||
$this->info( 'Updating consumable '.$consumable->id.' to user '.$user->id);
|
$this->info('Updating consumable '.$consumable->id.' to user '.$user->id);
|
||||||
$bad_user->consumables()->updateExistingPivot($consumable->id, ['assigned_to' => $user->id]);
|
$bad_user->consumables()->updateExistingPivot($consumable->id, ['assigned_to' => $user->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk the list of accessories
|
// Walk the list of accessories
|
||||||
foreach ($bad_user->accessories as $accessory) {
|
foreach ($bad_user->accessories as $accessory) {
|
||||||
$this->info( 'Updating accessory '.$accessory->id.' to user '.$user->id);
|
$this->info('Updating accessory '.$accessory->id.' to user '.$user->id);
|
||||||
$bad_user->accessories()->updateExistingPivot($accessory->id, ['assigned_to' => $user->id]);
|
$bad_user->accessories()->updateExistingPivot($accessory->id, ['assigned_to' => $user->id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk the list of logs
|
// Walk the list of logs
|
||||||
foreach ($bad_user->userlog as $log) {
|
foreach ($bad_user->userlog as $log) {
|
||||||
$this->info( 'Updating action log record '.$log->id.' to user '.$user->id);
|
$this->info('Updating action log record '.$log->id.' to user '.$user->id);
|
||||||
$log->target_id = $user->id;
|
$log->target_id = $user->id;
|
||||||
$log->save();
|
$log->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update any manager IDs
|
// Update any manager IDs
|
||||||
$this->info( 'Updating managed user records to user '.$user->id);
|
$this->info('Updating managed user records to user '.$user->id);
|
||||||
User::where('manager_id', '=', $bad_user->id)->update(['manager_id' => $user->id]);
|
User::where('manager_id', '=', $bad_user->id)->update(['manager_id' => $user->id]);
|
||||||
|
|
||||||
|
|
||||||
// Update location manager IDs
|
// Update location manager IDs
|
||||||
foreach ($bad_user->managedLocations as $managedLocation) {
|
foreach ($bad_user->managedLocations as $managedLocation) {
|
||||||
$this->info( 'Updating managed location record '.$managedLocation->name.' to manager '.$user->id);
|
$this->info('Updating managed location record '.$managedLocation->name.' to manager '.$user->id);
|
||||||
$managedLocation->manager_id = $user->id;
|
$managedLocation->manager_id = $user->id;
|
||||||
$managedLocation->save();
|
$managedLocation->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the user as deleted
|
// Mark the user as deleted
|
||||||
$this->info( 'Marking the user as deleted');
|
$this->info('Marking the user as deleted');
|
||||||
$bad_user->deleted_at = Carbon::now()->timestamp;
|
$bad_user->deleted_at = Carbon::now()->timestamp;
|
||||||
$bad_user->save();
|
$bad_user->save();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
@ -39,39 +38,37 @@ class MoveUploadsToNewDisk extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
if (config('filesystems.default') == 'local') {
|
||||||
if (config('filesystems.default')=='local') {
|
|
||||||
$this->error('Your current disk is set to local so we cannot proceed.');
|
$this->error('Your current disk is set to local so we cannot proceed.');
|
||||||
$this->warn("Please configure your .env settings for S3. \nChange your PUBLIC_FILESYSTEM_DISK value to 's3_public' and your PRIVATE_FILESYSTEM_DISK to s3_private.");
|
$this->warn("Please configure your .env settings for S3. \nChange your PUBLIC_FILESYSTEM_DISK value to 's3_public' and your PRIVATE_FILESYSTEM_DISK to s3_private.");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$delete_local = $this->argument('delete_local');
|
$delete_local = $this->argument('delete_local');
|
||||||
|
|
||||||
$public_uploads['accessories'] = glob('public/accessories'."/*.*");
|
$public_uploads['accessories'] = glob('public/accessories'.'/*.*');
|
||||||
$public_uploads['assets'] = glob('public/assets'."/*.*");
|
$public_uploads['assets'] = glob('public/assets'.'/*.*');
|
||||||
$public_uploads['avatars'] = glob('public/avatars'."/*.*");
|
$public_uploads['avatars'] = glob('public/avatars'.'/*.*');
|
||||||
$public_uploads['categories'] = glob('public/categories'."/*.*");
|
$public_uploads['categories'] = glob('public/categories'.'/*.*');
|
||||||
$public_uploads['companies'] = glob('public/companies'."/*.*");
|
$public_uploads['companies'] = glob('public/companies'.'/*.*');
|
||||||
$public_uploads['components'] = glob('public/components'."/*.*");
|
$public_uploads['components'] = glob('public/components'.'/*.*');
|
||||||
$public_uploads['consumables'] = glob('public/consumables'."/*.*");
|
$public_uploads['consumables'] = glob('public/consumables'.'/*.*');
|
||||||
$public_uploads['departments'] = glob('public/departments'."/*.*");
|
$public_uploads['departments'] = glob('public/departments'.'/*.*');
|
||||||
$public_uploads['locations'] = glob('public/locations'."/*.*");
|
$public_uploads['locations'] = glob('public/locations'.'/*.*');
|
||||||
$public_uploads['manufacturers'] = glob('public/manufacturers'."/*.*");
|
$public_uploads['manufacturers'] = glob('public/manufacturers'.'/*.*');
|
||||||
$public_uploads['suppliers'] = glob('public/suppliers'."/*.*");
|
$public_uploads['suppliers'] = glob('public/suppliers'.'/*.*');
|
||||||
$public_uploads['assetmodels'] = glob('public/models'."/*.*");
|
$public_uploads['assetmodels'] = glob('public/models'.'/*.*');
|
||||||
|
|
||||||
|
|
||||||
// iterate files
|
// iterate files
|
||||||
foreach($public_uploads as $public_type => $public_upload)
|
foreach ($public_uploads as $public_type => $public_upload) {
|
||||||
{
|
|
||||||
$type_count = 0;
|
$type_count = 0;
|
||||||
$this->info("- There are ".count($public_upload).' PUBLIC '.$public_type.' files.');
|
$this->info('- There are '.count($public_upload).' PUBLIC '.$public_type.' files.');
|
||||||
|
|
||||||
for ($i = 0; $i < count($public_upload); $i++) {
|
for ($i = 0; $i < count($public_upload); $i++) {
|
||||||
$type_count++;
|
$type_count++;
|
||||||
$filename = basename($public_upload[$i]);
|
$filename = basename($public_upload[$i]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Storage::disk('public')->put('uploads/'.public_type.'/'.$filename, file_get_contents($public_upload[$i]));
|
Storage::disk('public')->put('uploads/'.public_type.'/'.$filename, file_get_contents($public_upload[$i]));
|
||||||
$new_url = Storage::disk('public')->url('uploads/'.$public_type.'/'.$filename, $filename);
|
$new_url = Storage::disk('public')->url('uploads/'.$public_type.'/'.$filename, $filename);
|
||||||
$this->info($type_count.'. PUBLIC: '.$filename.' was copied to '.$new_url);
|
$this->info($type_count.'. PUBLIC: '.$filename.' was copied to '.$new_url);
|
||||||
|
@ -79,13 +76,11 @@ class MoveUploadsToNewDisk extends Command
|
||||||
\Log::debug($e);
|
\Log::debug($e);
|
||||||
$this->error($e);
|
$this->error($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$logos = glob("public/uploads/setting*.*");
|
$logos = glob('public/uploads/setting*.*');
|
||||||
$this->info("- There are ".count($logos).' files that might be logos.');
|
$this->info('- There are '.count($logos).' files that might be logos.');
|
||||||
$type_count = 0;
|
$type_count = 0;
|
||||||
|
|
||||||
foreach ($logos as $logo) {
|
foreach ($logos as $logo) {
|
||||||
|
@ -96,41 +91,35 @@ class MoveUploadsToNewDisk extends Command
|
||||||
$this->info($type_count.'. LOGO: '.$filename.' was copied to '.env('PUBLIC_AWS_URL').'/uploads/'.$filename);
|
$this->info($type_count.'. LOGO: '.$filename.' was copied to '.env('PUBLIC_AWS_URL').'/uploads/'.$filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
$private_uploads['assets'] = glob('storage/private_uploads/assets'."/*.*");
|
$private_uploads['assets'] = glob('storage/private_uploads/assets'.'/*.*');
|
||||||
$private_uploads['signatures'] = glob('storage/private_uploads/signatures'."/*.*");
|
$private_uploads['signatures'] = glob('storage/private_uploads/signatures'.'/*.*');
|
||||||
$private_uploads['audits'] = glob('storage/private_uploads/audits'."/*.*");
|
$private_uploads['audits'] = glob('storage/private_uploads/audits'.'/*.*');
|
||||||
$private_uploads['assetmodels'] = glob('storage/private_uploads/assetmodels'."/*.*");
|
$private_uploads['assetmodels'] = glob('storage/private_uploads/assetmodels'.'/*.*');
|
||||||
$private_uploads['imports'] = glob('storage/private_uploads/imports'."/*.*");
|
$private_uploads['imports'] = glob('storage/private_uploads/imports'.'/*.*');
|
||||||
$private_uploads['licenses'] = glob('storage/private_uploads/licenses'."/*.*");
|
$private_uploads['licenses'] = glob('storage/private_uploads/licenses'.'/*.*');
|
||||||
$private_uploads['users'] = glob('storage/private_uploads/users'."/*.*");
|
$private_uploads['users'] = glob('storage/private_uploads/users'.'/*.*');
|
||||||
$private_uploads['backups'] = glob('storage/private_uploads/users'."/*.*");
|
$private_uploads['backups'] = glob('storage/private_uploads/users'.'/*.*');
|
||||||
|
|
||||||
|
foreach ($private_uploads as $private_type => $private_upload) {
|
||||||
foreach($private_uploads as $private_type => $private_upload)
|
$this->info('- There are '.count($private_upload).' PRIVATE '.$private_type.' files.');
|
||||||
{
|
|
||||||
$this->info("- There are ".count($private_upload).' PRIVATE '.$private_type.' files.');
|
|
||||||
|
|
||||||
$type_count = 0;
|
$type_count = 0;
|
||||||
for ($x = 0; $x < count($private_upload); $x++) {
|
for ($x = 0; $x < count($private_upload); $x++) {
|
||||||
$type_count++;
|
$type_count++;
|
||||||
$filename = basename($private_upload[$x]);
|
$filename = basename($private_upload[$x]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Storage::put($private_type.'/'.$filename, file_get_contents($private_upload[$i]));
|
Storage::put($private_type.'/'.$filename, file_get_contents($private_upload[$i]));
|
||||||
$new_url = Storage::url($private_type.'/'.$filename, $filename);
|
$new_url = Storage::url($private_type.'/'.$filename, $filename);
|
||||||
$this->info($type_count.'. PRIVATE: '.$filename.' was copied to '.$new_url);
|
$this->info($type_count.'. PRIVATE: '.$filename.' was copied to '.$new_url);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::debug($e);
|
\Log::debug($e);
|
||||||
$this->error($e);
|
$this->error($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($delete_local == 'true') {
|
||||||
if ($delete_local=='true') {
|
|
||||||
$public_delete_count = 0;
|
$public_delete_count = 0;
|
||||||
$private_delete_count = 0;
|
$private_delete_count = 0;
|
||||||
|
|
||||||
|
@ -139,10 +128,8 @@ class MoveUploadsToNewDisk extends Command
|
||||||
$this->warn("\nTHIS WILL DELETE ALL OF YOUR LOCAL UPLOADED FILES. \n\nThis cannot be undone, so you should take a backup of your system before you proceed.\n");
|
$this->warn("\nTHIS WILL DELETE ALL OF YOUR LOCAL UPLOADED FILES. \n\nThis cannot be undone, so you should take a backup of your system before you proceed.\n");
|
||||||
$this->error('!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
|
$this->error('!!!!!!!!!!!!!!!!!!!!!!!!!!!!! WARNING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
|
||||||
|
|
||||||
if ($this->confirm("Do you wish to continue?")) {
|
if ($this->confirm('Do you wish to continue?')) {
|
||||||
|
foreach ($public_uploads as $public_type => $public_upload) {
|
||||||
foreach($public_uploads as $public_type => $public_upload) {
|
|
||||||
|
|
||||||
for ($i = 0; $i < count($public_upload); $i++) {
|
for ($i = 0; $i < count($public_upload); $i++) {
|
||||||
$filename = $public_upload[$i];
|
$filename = $public_upload[$i];
|
||||||
try {
|
try {
|
||||||
|
@ -152,13 +139,10 @@ class MoveUploadsToNewDisk extends Command
|
||||||
\Log::debug($e);
|
\Log::debug($e);
|
||||||
$this->error($e);
|
$this->error($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($private_uploads as $private_type => $private_upload)
|
foreach ($private_uploads as $private_type => $private_upload) {
|
||||||
{
|
|
||||||
|
|
||||||
for ($i = 0; $i < count($private_upload); $i++) {
|
for ($i = 0; $i < count($private_upload); $i++) {
|
||||||
$filename = $private_upload[$i];
|
$filename = $private_upload[$i];
|
||||||
try {
|
try {
|
||||||
|
@ -168,16 +152,11 @@ class MoveUploadsToNewDisk extends Command
|
||||||
\Log::debug($e);
|
\Log::debug($e);
|
||||||
$this->error($e);
|
$this->error($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info($public_delete_count." PUBLIC local files and ".$private_delete_count." PRIVATE local files were deleted from your filesystem.");
|
$this->info($public_delete_count.' PUBLIC local files and '.$private_delete_count.' PRIVATE local files were deleted from your filesystem.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
@ -13,7 +14,6 @@ ini_set('memory_limit', env('IMPORT_MEMORY_LIMIT', '500M'));
|
||||||
*/
|
*/
|
||||||
class ObjectImportCommand extends Command
|
class ObjectImportCommand extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command name.
|
* The console command name.
|
||||||
*
|
*
|
||||||
|
@ -37,7 +37,9 @@ class ObjectImportCommand extends Command
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
private $bar;
|
private $bar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
|
@ -55,7 +57,6 @@ class ObjectImportCommand extends Command
|
||||||
->setShouldNotify($this->option('send-welcome'))
|
->setShouldNotify($this->option('send-welcome'))
|
||||||
->setUsernameFormat($this->option('username_format'));
|
->setUsernameFormat($this->option('username_format'));
|
||||||
|
|
||||||
|
|
||||||
// This $logFile/useFiles() bit is currently broken, so commenting it out for now
|
// This $logFile/useFiles() bit is currently broken, so commenting it out for now
|
||||||
// $logFile = $this->option('logfile');
|
// $logFile = $this->option('logfile');
|
||||||
// \Log::useFiles($logFile);
|
// \Log::useFiles($logFile);
|
||||||
|
@ -64,29 +65,28 @@ class ObjectImportCommand extends Command
|
||||||
|
|
||||||
$this->bar = null;
|
$this->bar = null;
|
||||||
|
|
||||||
if (!empty($this->errors)) {
|
if (! empty($this->errors)) {
|
||||||
$this->comment("The following Errors were encountered.");
|
$this->comment('The following Errors were encountered.');
|
||||||
foreach ($this->errors as $asset => $error) {
|
foreach ($this->errors as $asset => $error) {
|
||||||
$this->comment('Error: Item: ' . $asset . ' failed validation: ' . json_encode($error));
|
$this->comment('Error: Item: '.$asset.' failed validation: '.json_encode($error));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->comment("All Items imported successfully!");
|
$this->comment('All Items imported successfully!');
|
||||||
}
|
}
|
||||||
$this->comment("");
|
$this->comment('');
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function errorCallback($item, $field, $errorString)
|
public function errorCallback($item, $field, $errorString)
|
||||||
{
|
{
|
||||||
$this->errors[$item->name][$field] = $errorString;
|
$this->errors[$item->name][$field] = $errorString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function progress($count)
|
public function progress($count)
|
||||||
{
|
{
|
||||||
if (!$this->bar) {
|
if (! $this->bar) {
|
||||||
$this->bar = $this->output->createProgressBar($count);
|
$this->bar = $this->output->createProgressBar($count);
|
||||||
}
|
}
|
||||||
static $index =0;
|
static $index = 0;
|
||||||
$index++;
|
$index++;
|
||||||
if ($index < $count) {
|
if ($index < $count) {
|
||||||
$this->bar->advance();
|
$this->bar->advance();
|
||||||
|
@ -94,12 +94,12 @@ class ObjectImportCommand extends Command
|
||||||
$this->bar->finish();
|
$this->bar->finish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tracks the current item for error messages
|
// Tracks the current item for error messages
|
||||||
private $updating;
|
private $updating;
|
||||||
// An array of errors encountered while parsing
|
// An array of errors encountered while parsing
|
||||||
private $errors;
|
private $errors;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a message to file, configurable by the --log-file parameter.
|
* Log a message to file, configurable by the --log-file parameter.
|
||||||
* If a warning message is passed, we'll spit it to the console as well.
|
* If a warning message is passed, we'll spit it to the console as well.
|
||||||
|
@ -108,7 +108,7 @@ class ObjectImportCommand extends Command
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
* @param string $string
|
* @param string $string
|
||||||
* @param string $level
|
* @param string $level
|
||||||
*/
|
*/
|
||||||
public function log($string, $level = 'info')
|
public function log($string, $level = 'info')
|
||||||
{
|
{
|
||||||
if ($level === 'warning') {
|
if ($level === 'warning') {
|
||||||
|
@ -121,6 +121,7 @@ class ObjectImportCommand extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the console command arguments.
|
* Get the console command arguments.
|
||||||
*
|
*
|
||||||
|
@ -130,12 +131,11 @@ class ObjectImportCommand extends Command
|
||||||
*/
|
*/
|
||||||
protected function getArguments()
|
protected function getArguments()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('filename', InputArgument::REQUIRED, 'File for the CSV import.'),
|
['filename', InputArgument::REQUIRED, 'File for the CSV import.'],
|
||||||
);
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the console command options.
|
* Get the console command options.
|
||||||
*
|
*
|
||||||
|
@ -145,16 +145,15 @@ class ObjectImportCommand extends Command
|
||||||
*/
|
*/
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
return array(
|
return [
|
||||||
array('email_format', null, InputOption::VALUE_REQUIRED, 'The format of the email addresses that should be generated. Options are firstname.lastname, firstname, filastname', null),
|
['email_format', null, InputOption::VALUE_REQUIRED, 'The format of the email addresses that should be generated. Options are firstname.lastname, firstname, filastname', null],
|
||||||
array('username_format', null, InputOption::VALUE_REQUIRED, 'The format of the username that should be generated. Options are firstname.lastname, firstname, filastname, email', null),
|
['username_format', null, InputOption::VALUE_REQUIRED, 'The format of the username that should be generated. Options are firstname.lastname, firstname, filastname, email', null],
|
||||||
array('logfile', null, InputOption::VALUE_REQUIRED, 'The path to log output to. storage/logs/importer.log by default', storage_path('logs/importer.log') ),
|
['logfile', null, InputOption::VALUE_REQUIRED, 'The path to log output to. storage/logs/importer.log by default', storage_path('logs/importer.log')],
|
||||||
array('item-type', null, InputOption::VALUE_REQUIRED, 'Item Type To import. Valid Options are Asset, Consumable, Accessory, License, or User', 'Asset'),
|
['item-type', null, InputOption::VALUE_REQUIRED, 'Item Type To import. Valid Options are Asset, Consumable, Accessory, License, or User', 'Asset'],
|
||||||
array('web-importer', null, InputOption::VALUE_NONE, 'Internal: packages output for use with the web importer'),
|
['web-importer', null, InputOption::VALUE_NONE, 'Internal: packages output for use with the web importer'],
|
||||||
array('user_id', null, InputOption::VALUE_REQUIRED, 'ID of user creating items', 1),
|
['user_id', null, InputOption::VALUE_REQUIRED, 'ID of user creating items', 1],
|
||||||
array('update', null, InputOption::VALUE_NONE, 'If a matching item is found, update item information'),
|
['update', null, InputOption::VALUE_NONE, 'If a matching item is found, update item information'],
|
||||||
array('send-welcome', null, InputOption::VALUE_NONE, 'Whether to send a welcome email to any new users that are created.'),
|
['send-welcome', null, InputOption::VALUE_NONE, 'Whether to send a welcome email to any new users that are created.'],
|
||||||
);
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,23 +2,9 @@
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\Accessory;
|
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\AssetModel;
|
use App\Models\CustomField;
|
||||||
use App\Models\Category;
|
use Schema;
|
||||||
use App\Models\Company;
|
|
||||||
use App\Models\Component;
|
|
||||||
use App\Models\Consumable;
|
|
||||||
use App\Models\Department;
|
|
||||||
use App\Models\Depreciation;
|
|
||||||
use App\Models\Group;
|
|
||||||
use App\Models\Import;
|
|
||||||
use App\Models\License;
|
|
||||||
use App\Models\LicenseSeat;
|
|
||||||
use App\Models\Location;
|
|
||||||
use App\Models\Manufacturer;
|
|
||||||
use App\Models\Statuslabel;
|
|
||||||
use App\Models\Supplier;
|
|
||||||
use DB;
|
use DB;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
@ -29,15 +15,14 @@ class PaveIt extends Command
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'snipeit:pave
|
protected $signature = 'snipeit:pave {--force : Skip the interactive yes/no prompt for confirmation}';
|
||||||
{--soft : Perform a "Soft" Delete, leaving all migrations, table structure, and the first user in place.}';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $description = 'Pave the database to start over. This should ALMOST NEVER BE USED. (It is primarily a quick tool for developers.)';
|
protected $description = 'Clear the database tables, leaving all migrations, table structure, and the first user in place. (It is primarily a quick tool for developers.) If you want to destroy all tables as well, use php artisan db:wipe.';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command instance.
|
* Create a new command instance.
|
||||||
|
@ -56,106 +41,51 @@ class PaveIt extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
if ($this->confirm("\n****************************************************\nTHIS WILL DELETE ALL OF THE DATA IN YOUR DATABASE. \nThere is NO undo. This WILL destroy ALL of your data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) {
|
|
||||||
if ($this->option('soft')) {
|
|
||||||
Accessory::getQuery()->delete();
|
|
||||||
Asset::getQuery()->delete();
|
|
||||||
Category::getQuery()->delete();
|
|
||||||
Company::getQuery()->delete();
|
|
||||||
Component::getQuery()->delete();
|
|
||||||
Consumable::getQuery()->delete();
|
|
||||||
Department::getQuery()->delete();
|
|
||||||
Depreciation::getQuery()->delete();
|
|
||||||
License::getQuery()->delete();
|
|
||||||
LicenseSeat::getQuery()->delete();
|
|
||||||
Location::getQuery()->delete();
|
|
||||||
Manufacturer::getQuery()->delete();
|
|
||||||
AssetModel::getQuery()->delete();
|
|
||||||
Statuslabel::getQuery()->delete();
|
|
||||||
Supplier::getQuery()->delete();
|
|
||||||
Group::getQuery()->delete();
|
|
||||||
Import::getQuery()->delete();
|
|
||||||
|
|
||||||
DB::statement('delete from accessories_users');
|
if (!$this->option('force')) {
|
||||||
DB::statement('delete from asset_logs');
|
$confirmation = $this->confirm("\n****************************************************\nTHIS WILL DELETE ALL OF THE DATA IN YOUR DATABASE. \nThere is NO undo. This WILL destroy ALL of your data, \nINCLUDING ANY non-Snipe-IT tables you have in this database. \n****************************************************\n\nDo you wish to continue? No backsies! ");
|
||||||
DB::statement('delete from asset_maintenances');
|
if (!$confirmation) {
|
||||||
DB::statement('delete from login_attempts');
|
$this->error('ABORTING');
|
||||||
DB::statement('delete from asset_uploads');
|
exit(-1);
|
||||||
DB::statement('delete from action_logs');
|
|
||||||
DB::statement('delete from checkout_requests');
|
|
||||||
DB::statement('delete from checkout_acceptances');
|
|
||||||
DB::statement('delete from consumables_users');
|
|
||||||
DB::statement('delete from custom_field_custom_fieldset');
|
|
||||||
DB::statement('delete from custom_fields');
|
|
||||||
DB::statement('delete from custom_fieldsets');
|
|
||||||
DB::statement('delete from components_assets');
|
|
||||||
DB::statement('delete from kits');
|
|
||||||
DB::statement('delete from kits_accessories');
|
|
||||||
DB::statement('delete from kits_consumables');
|
|
||||||
DB::statement('delete from kits_licenses');
|
|
||||||
DB::statement('delete from kits_models');
|
|
||||||
DB::statement('delete from login_attempts');
|
|
||||||
DB::statement('delete from models_custom_fields');
|
|
||||||
DB::statement('delete from permission_groups');
|
|
||||||
DB::statement('delete from password_resets');
|
|
||||||
DB::statement('delete from requested_assets');
|
|
||||||
DB::statement('delete from requests');
|
|
||||||
DB::statement('delete from throttle');
|
|
||||||
DB::statement('delete from users_groups');
|
|
||||||
DB::statement('delete from users WHERE id!=1');
|
|
||||||
} else {
|
|
||||||
\DB::statement('drop table IF EXISTS accessories_users');
|
|
||||||
\DB::statement('drop table IF EXISTS accessories');
|
|
||||||
\DB::statement('drop table IF EXISTS asset_logs');
|
|
||||||
\DB::statement('drop table IF EXISTS action_logs');
|
|
||||||
\DB::statement('drop table IF EXISTS asset_maintenances');
|
|
||||||
\DB::statement('drop table IF EXISTS asset_uploads');
|
|
||||||
\DB::statement('drop table IF EXISTS assets');
|
|
||||||
\DB::statement('drop table IF EXISTS categories');
|
|
||||||
\DB::statement('drop table IF EXISTS checkout_requests');
|
|
||||||
\DB::statement('drop table IF EXISTS checkout_acceptances');
|
|
||||||
\DB::statement('drop table IF EXISTS companies');
|
|
||||||
\DB::statement('drop table IF EXISTS components');
|
|
||||||
\DB::statement('drop table IF EXISTS components_assets');
|
|
||||||
\DB::statement('drop table IF EXISTS consumables_users');
|
|
||||||
\DB::statement('drop table IF EXISTS consumables');
|
|
||||||
\DB::statement('drop table IF EXISTS custom_field_custom_fieldset');
|
|
||||||
\DB::statement('drop table IF EXISTS custom_fields');
|
|
||||||
\DB::statement('drop table IF EXISTS custom_fieldsets');
|
|
||||||
\DB::statement('drop table IF EXISTS depreciations');
|
|
||||||
\DB::statement('drop table IF EXISTS departments');
|
|
||||||
\DB::statement('drop table IF EXISTS groups');
|
|
||||||
\DB::statement('drop table IF EXISTS history');
|
|
||||||
\DB::statement('drop table IF EXISTS kits');
|
|
||||||
\DB::statement('drop table IF EXISTS kits_accessories');
|
|
||||||
\DB::statement('drop table IF EXISTS kits_consumables');
|
|
||||||
\DB::statement('drop table IF EXISTS kits_licenses');
|
|
||||||
\DB::statement('drop table IF EXISTS kits_models');
|
|
||||||
\DB::statement('drop table IF EXISTS models_custom_fields');
|
|
||||||
\DB::statement('drop table IF EXISTS permission_groups');
|
|
||||||
\DB::statement('drop table IF EXISTS license_seats');
|
|
||||||
\DB::statement('drop table IF EXISTS licenses');
|
|
||||||
\DB::statement('drop table IF EXISTS locations');
|
|
||||||
\DB::statement('drop table IF EXISTS login_attempts');
|
|
||||||
\DB::statement('drop table IF EXISTS manufacturers');
|
|
||||||
\DB::statement('drop table IF EXISTS models');
|
|
||||||
\DB::statement('drop table IF EXISTS migrations');
|
|
||||||
\DB::statement('drop table IF EXISTS oauth_access_tokens');
|
|
||||||
\DB::statement('drop table IF EXISTS oauth_auth_codes');
|
|
||||||
\DB::statement('drop table IF EXISTS oauth_clients');
|
|
||||||
\DB::statement('drop table IF EXISTS oauth_personal_access_clients');
|
|
||||||
\DB::statement('drop table IF EXISTS oauth_refresh_tokens');
|
|
||||||
\DB::statement('drop table IF EXISTS password_resets');
|
|
||||||
\DB::statement('drop table IF EXISTS requested_assets');
|
|
||||||
\DB::statement('drop table IF EXISTS requests');
|
|
||||||
\DB::statement('drop table IF EXISTS settings');
|
|
||||||
\DB::statement('drop table IF EXISTS status_labels');
|
|
||||||
\DB::statement('drop table IF EXISTS suppliers');
|
|
||||||
\DB::statement('drop table IF EXISTS throttle');
|
|
||||||
\DB::statement('drop table IF EXISTS users_groups');
|
|
||||||
\DB::statement('drop table IF EXISTS users');
|
|
||||||
\DB::statement('drop table IF EXISTS imports');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// List all the tables in the database so we don't have to worry about missing some as the app grows
|
||||||
|
$tables = DB::connection()->getDoctrineSchemaManager()->listTableNames();
|
||||||
|
|
||||||
|
$except_tables = [
|
||||||
|
'oauth_access_tokens',
|
||||||
|
'oauth_clients',
|
||||||
|
'oauth_personal_access_clients',
|
||||||
|
'migrations',
|
||||||
|
'settings',
|
||||||
|
'users',
|
||||||
|
];
|
||||||
|
|
||||||
|
// We only need to find out what these are so we can nuke these columns on the assets table.
|
||||||
|
$custom_fields = CustomField::get();
|
||||||
|
foreach ($custom_fields as $custom_field) {
|
||||||
|
$this->info('DROP the '.$custom_field->db_column.' column from assets as well.');
|
||||||
|
|
||||||
|
if (\Schema::hasColumn('assets', $custom_field->db_column)) {
|
||||||
|
\Schema::table('assets', function ($table) use ($custom_field) {
|
||||||
|
$table->dropColumn($custom_field->db_column);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($tables as $table) {
|
||||||
|
if (in_array($table, $except_tables)) {
|
||||||
|
$this->info($table. ' is SKIPPED.');
|
||||||
|
} else {
|
||||||
|
\DB::statement('truncate '.$table);
|
||||||
|
$this->info($table. ' is TRUNCATED.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Leave in the demo oauth keys so we don't have to reset them every day in the demos
|
||||||
|
\DB::statement('delete from oauth_clients WHERE id > 2');
|
||||||
|
\DB::statement('delete from oauth_access_tokens WHERE id > 2');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -50,7 +50,7 @@ class Purge extends Command
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$force = $this->option('force');
|
$force = $this->option('force');
|
||||||
if (($this->confirm("\n****************************************************\nTHIS WILL PURGE ALL SOFT-DELETED ITEMS IN YOUR SYSTEM. \nThere is NO undo. This WILL permanently destroy \nALL of your deleted data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) || $force == 'true') {
|
if (($this->confirm("\n****************************************************\nTHIS WILL PURGE ALL SOFT-DELETED ITEMS IN YOUR SYSTEM. \nThere is NO undo. This WILL permanently destroy \nALL of your deleted data. \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) || $force == 'true') {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete assets
|
* Delete assets
|
||||||
|
@ -80,9 +80,8 @@ class Purge extends Command
|
||||||
$location->forceDelete();
|
$location->forceDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$accessories = Accessory::whereNotNull('deleted_at')->withTrashed()->get();
|
$accessories = Accessory::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
$accessory_assoc=0;
|
$accessory_assoc = 0;
|
||||||
$this->info($accessories->count().' accessories purged.');
|
$this->info($accessories->count().' accessories purged.');
|
||||||
foreach ($accessories as $accessory) {
|
foreach ($accessories as $accessory) {
|
||||||
$this->info('- Accessory "'.$accessory->name.'" deleted.');
|
$this->info('- Accessory "'.$accessory->name.'" deleted.');
|
||||||
|
@ -92,7 +91,6 @@ class Purge extends Command
|
||||||
}
|
}
|
||||||
$this->info($accessory_assoc.' corresponding log records purged.');
|
$this->info($accessory_assoc.' corresponding log records purged.');
|
||||||
|
|
||||||
|
|
||||||
$consumables = Consumable::whereNotNull('deleted_at')->withTrashed()->get();
|
$consumables = Consumable::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
$this->info($consumables->count().' consumables purged.');
|
$this->info($consumables->count().' consumables purged.');
|
||||||
foreach ($consumables as $consumable) {
|
foreach ($consumables as $consumable) {
|
||||||
|
@ -101,7 +99,6 @@ class Purge extends Command
|
||||||
$consumable->forceDelete();
|
$consumable->forceDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$components = Component::whereNotNull('deleted_at')->withTrashed()->get();
|
$components = Component::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
$this->info($components->count().' components purged.');
|
$this->info($components->count().' components purged.');
|
||||||
foreach ($components as $component) {
|
foreach ($components as $component) {
|
||||||
|
@ -126,7 +123,6 @@ class Purge extends Command
|
||||||
$model->forceDelete();
|
$model->forceDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$categories = Category::whereNotNull('deleted_at')->withTrashed()->get();
|
$categories = Category::whereNotNull('deleted_at')->withTrashed()->get();
|
||||||
$this->info($categories->count().' categories purged.');
|
$this->info($categories->count().' categories purged.');
|
||||||
foreach ($categories as $category) {
|
foreach ($categories as $category) {
|
||||||
|
@ -165,11 +161,8 @@ class Purge extends Command
|
||||||
$this->info('- Status Label "'.$status_label->name.'" deleted.');
|
$this->info('- Status Label "'.$status_label->name.'" deleted.');
|
||||||
$status_label->forceDelete();
|
$status_label->forceDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->info('Action canceled. Nothing was purged.');
|
$this->info('Action canceled. Nothing was purged.');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ class PurgeLoginAttempts extends Command
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
if ($this->confirm("\n****************************************************\nTHIS WILL DELETE ALL OF THE YOUR LOGIN ATTEMPT RECORDS. \nThere is NO undo! \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) {
|
if ($this->confirm("\n****************************************************\nTHIS WILL DELETE ALL OF THE YOUR LOGIN ATTEMPT RECORDS. \nThere is NO undo! \n****************************************************\n\nDo you wish to continue? No backsies! [y|N]")) {
|
||||||
\DB::statement('delete from login_attempts');
|
\DB::statement('delete from login_attempts');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,15 +48,13 @@ class ReEncodeCustomFieldNames extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
if ($this->confirm('This will regenerate all of the custom field database fieldnames in your database. THIS WILL CHANGE YOUR SCHEMA AND SHOULD NOT BE DONE WITHOUT MAKING A BACKUP FIRST. Do you wish to continue?')) {
|
||||||
if ($this->confirm('This will regenerate all of the custom field database fieldnames in your database. THIS WILL CHANGE YOUR SCHEMA AND SHOULD NOT BE DONE WITHOUT MAKING A BACKUP FIRST. Do you wish to continue?'))
|
|
||||||
{
|
|
||||||
|
|
||||||
/** Get all of the custom fields */
|
/** Get all of the custom fields */
|
||||||
$fields = CustomField::get();
|
$fields = CustomField::get();
|
||||||
|
|
||||||
$asset_columns = \DB::getSchemaBuilder()->getColumnListing('assets');
|
$asset_columns = \DB::getSchemaBuilder()->getColumnListing('assets');
|
||||||
$custom_field_columns = array();
|
$custom_field_columns = [];
|
||||||
|
|
||||||
/** Loop through the columns on the assets table */
|
/** Loop through the columns on the assets table */
|
||||||
foreach ($asset_columns as $asset_column) {
|
foreach ($asset_columns as $asset_column) {
|
||||||
|
@ -71,18 +69,16 @@ class ReEncodeCustomFieldNames extends Command
|
||||||
* Then use that ID as the array key for use comparing the actual assets field name
|
* Then use that ID as the array key for use comparing the actual assets field name
|
||||||
* and the db_column value from the custom fields table.
|
* and the db_column value from the custom fields table.
|
||||||
*/
|
*/
|
||||||
$last_part = substr(strrchr($asset_column, "_snipeit_"), 1);
|
$last_part = substr(strrchr($asset_column, '_snipeit_'), 1);
|
||||||
$custom_field_columns[$last_part] = $asset_column;
|
$custom_field_columns[$last_part] = $asset_column;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
|
$this->info($field->name.' ('.$field->id.') column should be '.$field->convertUnicodeDbSlug().'');
|
||||||
$this->info($field->name .' ('.$field->id.') column should be '. $field->convertUnicodeDbSlug().'');
|
|
||||||
|
|
||||||
/** The assets table has the column it should have, all is well */
|
/** The assets table has the column it should have, all is well */
|
||||||
if (\Schema::hasColumn('assets', $field->convertUnicodeDbSlug()))
|
if (\Schema::hasColumn('assets', $field->convertUnicodeDbSlug())) {
|
||||||
{
|
|
||||||
$this->info('-- ✓ This field exists - all good');
|
$this->info('-- ✓ This field exists - all good');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -90,24 +86,23 @@ class ReEncodeCustomFieldNames extends Command
|
||||||
* what $field->convertUnicodeDbSlug() is *now* expecting.
|
* what $field->convertUnicodeDbSlug() is *now* expecting.
|
||||||
*/
|
*/
|
||||||
} else {
|
} else {
|
||||||
$this->warn('-- X Field mismatch: updating... ');
|
$this->warn('-- X Field mismatch: updating... ');
|
||||||
|
|
||||||
/** Make sure the custom_field_columns array has the ID */
|
/** Make sure the custom_field_columns array has the ID */
|
||||||
if (array_key_exists($field->id, $custom_field_columns)) {
|
if (array_key_exists($field->id, $custom_field_columns)) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the asset schema to the corrected fieldname that will be recognized by the
|
* Update the asset schema to the corrected fieldname that will be recognized by the
|
||||||
* system elsewhere that we use $field->convertUnicodeDbSlug()
|
* system elsewhere that we use $field->convertUnicodeDbSlug()
|
||||||
*/
|
*/
|
||||||
\Schema::table('assets', function($table) use ($custom_field_columns, $field) {
|
\Schema::table('assets', function ($table) use ($custom_field_columns, $field) {
|
||||||
$table->renameColumn($custom_field_columns[$field->id], $field->convertUnicodeDbSlug());
|
$table->renameColumn($custom_field_columns[$field->id], $field->convertUnicodeDbSlug());
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->warn('-- ✓ Field updated from '.$custom_field_columns[$field->id].' to '.$field->convertUnicodeDbSlug());
|
$this->warn('-- ✓ Field updated from '.$custom_field_columns[$field->id].' to '.$field->convertUnicodeDbSlug());
|
||||||
|
} else {
|
||||||
} else {
|
$this->warn('-- X WARNING: There is no field on the assets table ending in '.$field->id.'. This may require more in-depth investigation and may mean the schema was altered manually.');
|
||||||
$this->warn('-- X WARNING: There is no field on the assets table ending in '.$field->id.'. This may require more in-depth investigation and may mean the schema was altered manually.');
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update the db_column property in the custom fields table, just in case it doesn't match the other
|
/** Update the db_column property in the custom fields table, just in case it doesn't match the other
|
||||||
|
@ -115,12 +110,7 @@ class ReEncodeCustomFieldNames extends Command
|
||||||
*/
|
*/
|
||||||
$field->db_column = $field->convertUnicodeDbSlug();
|
$field->db_column = $field->convertUnicodeDbSlug();
|
||||||
$field->save();
|
$field->save();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,37 +44,35 @@ class RecryptFromMcrypt extends Command
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// Check and see if they have a legacy app key listed in their .env
|
// Check and see if they have a legacy app key listed in their .env
|
||||||
// If not, we can try to use the current APP_KEY if looks like it's old
|
// If not, we can try to use the current APP_KEY if looks like it's old
|
||||||
$legacy_key = env('LEGACY_APP_KEY');
|
$legacy_key = env('LEGACY_APP_KEY');
|
||||||
$key_parts = explode(':', $legacy_key);
|
$key_parts = explode(':', $legacy_key);
|
||||||
$legacy_cipher = env('LEGACY_CIPHER', 'rijndael-256');
|
$legacy_cipher = env('LEGACY_CIPHER', 'rijndael-256');
|
||||||
$errors = array();
|
$errors = [];
|
||||||
|
|
||||||
if (!$legacy_key) {
|
if (! $legacy_key) {
|
||||||
$this->error('ERROR: You do not have a LEGACY_APP_KEY set in your .env file. Please locate your old APP_KEY and ADD a line to your .env file like: LEGACY_APP_KEY=YOUR_OLD_APP_KEY');
|
$this->error('ERROR: You do not have a LEGACY_APP_KEY set in your .env file. Please locate your old APP_KEY and ADD a line to your .env file like: LEGACY_APP_KEY=YOUR_OLD_APP_KEY');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Do some basic legacy app key length checks
|
// Do some basic legacy app key length checks
|
||||||
if (strlen($legacy_key) == 32) {
|
if (strlen($legacy_key) == 32) {
|
||||||
$legacy_length_check = true;
|
$legacy_length_check = true;
|
||||||
} elseif (array_key_exists('1', $key_parts) && (strlen($key_parts[1])==44)) {
|
} elseif (array_key_exists('1', $key_parts) && (strlen($key_parts[1]) == 44)) {
|
||||||
$legacy_key = base64_decode($key_parts[1],true);
|
$legacy_key = base64_decode($key_parts[1], true);
|
||||||
$legacy_length_check = true;
|
$legacy_length_check = true;
|
||||||
} else {
|
} else {
|
||||||
$legacy_length_check = false;
|
$legacy_length_check = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Check that the app key is 32 characters
|
// Check that the app key is 32 characters
|
||||||
if ($legacy_length_check === true) {
|
if ($legacy_length_check === true) {
|
||||||
$this->comment('INFO: Your LEGACY_APP_KEY looks correct. Okay to continue.');
|
$this->comment('INFO: Your LEGACY_APP_KEY looks correct. Okay to continue.');
|
||||||
} else {
|
} else {
|
||||||
$this->error('ERROR: Your LEGACY_APP_KEY is not the correct length (32 characters or base64 followed by 44 characters for later versions). Please locate your old APP_KEY and use that as your LEGACY_APP_KEY in your .env file to continue.');
|
$this->error('ERROR: Your LEGACY_APP_KEY is not the correct length (32 characters or base64 followed by 44 characters for later versions). Please locate your old APP_KEY and use that as your LEGACY_APP_KEY in your .env file to continue.');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +82,7 @@ class RecryptFromMcrypt extends Command
|
||||||
|
|
||||||
$force = ($this->option('force')) ? true : false;
|
$force = ($this->option('force')) ? true : false;
|
||||||
|
|
||||||
if ($force || ($this->confirm("Are you SURE you wish to continue?"))) {
|
if ($force || ($this->confirm('Are you SURE you wish to continue?'))) {
|
||||||
|
|
||||||
$backup_file = 'backups/env-backups/'.'app_key-'.date('Y-m-d-gis');
|
$backup_file = 'backups/env-backups/'.'app_key-'.date('Y-m-d-gis');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -95,15 +92,14 @@ class RecryptFromMcrypt extends Command
|
||||||
$this->info('WARNING: Could not backup app keys');
|
$this->info('WARNING: Could not backup app keys');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($legacy_cipher) {
|
||||||
if ($legacy_cipher){
|
$mcrypter = new McryptEncrypter($legacy_key, $legacy_cipher);
|
||||||
$mcrypter = new McryptEncrypter($legacy_key,$legacy_cipher);
|
} else {
|
||||||
}else{
|
|
||||||
$mcrypter = new McryptEncrypter($legacy_key);
|
$mcrypter = new McryptEncrypter($legacy_key);
|
||||||
}
|
}
|
||||||
$settings = Setting::getSettings();
|
$settings = Setting::getSettings();
|
||||||
|
|
||||||
if ($settings->ldap_pword=='') {
|
if ($settings->ldap_pword == '') {
|
||||||
$this->comment('INFO: No LDAP password found. Skipping... ');
|
$this->comment('INFO: No LDAP password found. Skipping... ');
|
||||||
} else {
|
} else {
|
||||||
$decrypted_ldap_pword = $mcrypter->decrypt($settings->ldap_pword);
|
$decrypted_ldap_pword = $mcrypter->decrypt($settings->ldap_pword);
|
||||||
|
@ -111,30 +107,28 @@ class RecryptFromMcrypt extends Command
|
||||||
$settings->save();
|
$settings->save();
|
||||||
}
|
}
|
||||||
/** @var CustomField[] $custom_fields */
|
/** @var CustomField[] $custom_fields */
|
||||||
$custom_fields = CustomField::where('field_encrypted','=', 1)->get();
|
$custom_fields = CustomField::where('field_encrypted', '=', 1)->get();
|
||||||
$this->comment('INFO: Retrieving encrypted custom fields...');
|
$this->comment('INFO: Retrieving encrypted custom fields...');
|
||||||
|
|
||||||
$query = Asset::withTrashed();
|
$query = Asset::withTrashed();
|
||||||
|
|
||||||
foreach ($custom_fields as $custom_field) {
|
foreach ($custom_fields as $custom_field) {
|
||||||
$this->comment('FIELD TO RECRYPT: '.$custom_field->name .' ('.$custom_field->db_column.')');
|
$this->comment('FIELD TO RECRYPT: '.$custom_field->name.' ('.$custom_field->db_column.')');
|
||||||
$query->orWhereNotNull($custom_field->db_column);
|
$query->orWhereNotNull($custom_field->db_column);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get all assets with a value in any of the fields that were encrypted
|
// Get all assets with a value in any of the fields that were encrypted
|
||||||
/** @var Asset[] $assets */
|
/** @var Asset[] $assets */
|
||||||
$assets = $query->get();
|
$assets = $query->get();
|
||||||
|
|
||||||
$bar = $this->output->createProgressBar(count($assets));
|
$bar = $this->output->createProgressBar(count($assets));
|
||||||
|
|
||||||
|
|
||||||
foreach ($assets as $asset) {
|
foreach ($assets as $asset) {
|
||||||
foreach ($custom_fields as $encrypted_field) {
|
foreach ($custom_fields as $encrypted_field) {
|
||||||
$columnName = $encrypted_field->db_column;
|
$columnName = $encrypted_field->db_column;
|
||||||
|
|
||||||
// Make sure the value isn't null
|
// Make sure the value isn't null
|
||||||
if ($asset->{$columnName}!='') {
|
if ($asset->{$columnName} != '') {
|
||||||
// Try to decrypt the payload using the legacy app key
|
// Try to decrypt the payload using the legacy app key
|
||||||
try {
|
try {
|
||||||
$decrypted_field = $mcrypter->decrypt($asset->{$columnName});
|
$decrypted_field = $mcrypter->decrypt($asset->{$columnName});
|
||||||
|
@ -144,14 +138,11 @@ class RecryptFromMcrypt extends Command
|
||||||
$errors[] = ' - ERROR: Could not decrypt field ['.$encrypted_field->name.']: '.$e->getMessage();
|
$errors[] = ' - ERROR: Could not decrypt field ['.$encrypted_field->name.']: '.$e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
$asset->save();
|
$asset->save();
|
||||||
$bar->advance();
|
$bar->advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$bar->finish();
|
$bar->finish();
|
||||||
|
|
||||||
if (count($errors) > 0) {
|
if (count($errors) > 0) {
|
||||||
|
@ -162,6 +153,5 @@ class RecryptFromMcrypt extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,30 +40,26 @@ class RegenerateAssetTags extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
if ($this->confirm('This will regenerate all of the asset tags within your system. This action is data-destructive and should be used with caution. Do you wish to continue?')) {
|
||||||
if ($this->confirm('This will regenerate all of the asset tags within your system. This action is data-destructive and should be used with caution. Do you wish to continue?'))
|
|
||||||
{
|
|
||||||
|
|
||||||
$output['info'] = [];
|
$output['info'] = [];
|
||||||
$output['warn'] = [];
|
$output['warn'] = [];
|
||||||
$output['error'] = [];
|
$output['error'] = [];
|
||||||
$settings = Setting::getSettings();
|
$settings = Setting::getSettings();
|
||||||
|
|
||||||
$start_tag = ($this->option('start')) ? $this->option('start') : (($settings->next_auto_tag_base) ? Setting::getSettings()->next_auto_tag_base : 1) ;
|
$start_tag = ($this->option('start')) ? $this->option('start') : (($settings->next_auto_tag_base) ? Setting::getSettings()->next_auto_tag_base : 1);
|
||||||
|
|
||||||
$this->info('Starting at '.$start_tag);
|
$this->info('Starting at '.$start_tag);
|
||||||
|
|
||||||
$total_assets = Asset::orderBy('id','asc')->get();
|
$total_assets = Asset::orderBy('id', 'asc')->get();
|
||||||
$bar = $this->output->createProgressBar(count($total_assets));
|
$bar = $this->output->createProgressBar(count($total_assets));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Artisan::call('backup:run');
|
Artisan::call('backup:run');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$output['error'][] = $e;
|
$output['error'][] = $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($total_assets as $asset) {
|
foreach ($total_assets as $asset) {
|
||||||
|
|
||||||
$start_tag++;
|
$start_tag++;
|
||||||
$output['info'][] = 'Asset tag:'.$asset->asset_tag;
|
$output['info'][] = 'Asset tag:'.$asset->asset_tag;
|
||||||
$asset->asset_tag = $settings->auto_increment_prefix.$settings->auto_increment_prefix.$start_tag;
|
$asset->asset_tag = $settings->auto_increment_prefix.$settings->auto_increment_prefix.$start_tag;
|
||||||
|
@ -81,24 +77,21 @@ class RegenerateAssetTags extends Command
|
||||||
$bar->finish();
|
$bar->finish();
|
||||||
$this->info("\n");
|
$this->info("\n");
|
||||||
|
|
||||||
|
if (($this->option('output') == 'all') || ($this->option('output') == 'info')) {
|
||||||
if (($this->option('output')=='all') || ($this->option('output')=='info')) {
|
|
||||||
foreach ($output['info'] as $key => $output_text) {
|
foreach ($output['info'] as $key => $output_text) {
|
||||||
$this->info($output_text);
|
$this->info($output_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (($this->option('output')=='all') || ($this->option('output')=='warn')) {
|
if (($this->option('output') == 'all') || ($this->option('output') == 'warn')) {
|
||||||
foreach ($output['warn'] as $key => $output_text) {
|
foreach ($output['warn'] as $key => $output_text) {
|
||||||
$this->warn($output_text);
|
$this->warn($output_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (($this->option('output')=='all') || ($this->option('output')=='error')) {
|
if (($this->option('output') == 'all') || ($this->option('output') == 'error')) {
|
||||||
foreach ($output['error'] as $key => $output_text) {
|
foreach ($output['error'] as $key => $output_text) {
|
||||||
$this->error($output_text);
|
$this->error($output_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,8 @@ class ResetDemoSettings extends Command
|
||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
\Storage::disk('local_public')->put('snipe-logo.png', file_get_contents(public_path('img/demo/snipe-logo.png')));
|
\Storage::disk('public')->put('snipe-logo.png', file_get_contents(public_path('img/demo/snipe-logo.png')));
|
||||||
\Storage::disk('local_public')->put('snipe-logo-lg.png', file_get_contents(public_path('img/demo/snipe-logo-lg.png')));
|
\Storage::disk('public')->put('snipe-logo-lg.png', file_get_contents(public_path('img/demo/snipe-logo-lg.png')));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,16 +43,15 @@ class RestoreDeletedUsers extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
$start_date = $this->option('start_date');
|
$start_date = $this->option('start_date');
|
||||||
$end_date = $this->option('end_date');
|
$end_date = $this->option('end_date');
|
||||||
$asset_totals = 0;
|
$asset_totals = 0;
|
||||||
$license_totals = 0;
|
$license_totals = 0;
|
||||||
$user_count = 0;
|
$user_count = 0;
|
||||||
|
|
||||||
|
if (($start_date == '') || ($end_date == '')) {
|
||||||
if (($start_date=='') || ($end_date=='')) {
|
|
||||||
$this->info('ERROR: All fields are required.');
|
$this->info('ERROR: All fields are required.');
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,15 +62,15 @@ class RestoreDeletedUsers extends Command
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$user_count++;
|
$user_count++;
|
||||||
$user_logs = Actionlog::where('target_id', $user->id)->where('target_type',User::class)
|
$user_logs = Actionlog::where('target_id', $user->id)->where('target_type', User::class)
|
||||||
->where('action_type','checkout')->with('item')->get();
|
->where('action_type', 'checkout')->with('item')->get();
|
||||||
|
|
||||||
$this->info($user_count.'. '.$user->username.' ('.$user->id.') was deleted at '.$user->deleted_at. ' and has '.$user_logs->count().' checkouts associated.');
|
$this->info($user_count.'. '.$user->username.' ('.$user->id.') was deleted at '.$user->deleted_at.' and has '.$user_logs->count().' checkouts associated.');
|
||||||
|
|
||||||
foreach ($user_logs as $user_log) {
|
foreach ($user_logs as $user_log) {
|
||||||
$this->info(' * '.$user_log->item_type.': '.$user_log->item->name.' - item_id: '.$user_log->item_id);
|
$this->info(' * '.$user_log->item_type.': '.$user_log->item->name.' - item_id: '.$user_log->item_id);
|
||||||
|
|
||||||
if ($user_log->item_type==Asset::class) {
|
if ($user_log->item_type == Asset::class) {
|
||||||
$asset_totals++;
|
$asset_totals++;
|
||||||
|
|
||||||
DB::table('assets')
|
DB::table('assets')
|
||||||
|
@ -79,11 +78,10 @@ class RestoreDeletedUsers extends Command
|
||||||
->update(['assigned_to' => $user->id, 'assigned_type'=> User::class]);
|
->update(['assigned_to' => $user->id, 'assigned_type'=> User::class]);
|
||||||
|
|
||||||
$this->info(' ** Asset '.$user_log->item->id.' ('.$user_log->item->asset_tag.') restored to user '.$user->id.'');
|
$this->info(' ** Asset '.$user_log->item->id.' ('.$user_log->item->asset_tag.') restored to user '.$user->id.'');
|
||||||
|
} elseif ($user_log->item_type == License::class) {
|
||||||
} elseif ($user_log->item_type==License::class) {
|
|
||||||
$license_totals++;
|
$license_totals++;
|
||||||
|
|
||||||
$avail_seat = DB::table('license_seats')->where('license_id','=',$user_log->item->id)
|
$avail_seat = DB::table('license_seats')->where('license_id', '=', $user_log->item->id)
|
||||||
->whereNull('assigned_to')->whereNull('asset_id')->whereBetween('updated_at', [$start_date, $end_date])->first();
|
->whereNull('assigned_to')->whereNull('asset_id')->whereBetween('updated_at', [$start_date, $end_date])->first();
|
||||||
if ($avail_seat) {
|
if ($avail_seat) {
|
||||||
$this->info(' ** Allocating seat '.$avail_seat->id.' for this License');
|
$this->info(' ** Allocating seat '.$avail_seat->id.' for this License');
|
||||||
|
@ -91,27 +89,17 @@ class RestoreDeletedUsers extends Command
|
||||||
DB::table('license_seats')
|
DB::table('license_seats')
|
||||||
->where('id', $avail_seat->id)
|
->where('id', $avail_seat->id)
|
||||||
->update(['assigned_to' => $user->id]);
|
->update(['assigned_to' => $user->id]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->warn('ERROR: No available seats for '.$user_log->item->name);
|
$this->warn('ERROR: No available seats for '.$user_log->item->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->warn('Restoring user '.$user->username.'!');
|
$this->warn('Restoring user '.$user->username.'!');
|
||||||
$user->restore();
|
$user->restore();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info($asset_totals.' assets affected');
|
$this->info($asset_totals.' assets affected');
|
||||||
$this->info($license_totals.' licenses affected');
|
$this->info($license_totals.' licenses affected');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
use ZipArchive;
|
use ZipArchive;
|
||||||
|
|
||||||
class RestoreFromBackup extends Command
|
class RestoreFromBackup extends Command
|
||||||
|
@ -43,20 +42,20 @@ class RestoreFromBackup extends Command
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$dir = getcwd();
|
$dir = getcwd();
|
||||||
print "Current working directory is: $dir\n";
|
echo "Current working directory is: $dir\n";
|
||||||
//
|
//
|
||||||
$filename = $this->argument('filename');
|
$filename = $this->argument('filename');
|
||||||
|
|
||||||
if (!$filename) {
|
if (! $filename) {
|
||||||
return $this->error("Missing required filename");
|
return $this->error('Missing required filename');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->option('force') && !$this->confirm('Are you sure you wish to restore from the given backup file? This can lead to MASSIVE DATA LOSS!')) {
|
if (! $this->option('force') && ! $this->confirm('Are you sure you wish to restore from the given backup file? This can lead to MASSIVE DATA LOSS!')) {
|
||||||
return $this->error("Data loss not confirmed");
|
return $this->error('Data loss not confirmed');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config('database.default') != 'mysql') {
|
if (config('database.default') != 'mysql') {
|
||||||
return $this->error("DB_CONNECTION must be MySQL in order to perform a restore. Detected: ".config('database.default'));
|
return $this->error('DB_CONNECTION must be MySQL in order to perform a restore. Detected: '.config('database.default'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$za = new ZipArchive();
|
$za = new ZipArchive();
|
||||||
|
@ -64,21 +63,20 @@ class RestoreFromBackup extends Command
|
||||||
$errcode = $za->open($filename/* , ZipArchive::RDONLY */); // that constant only exists in PHP 7.4 and higher
|
$errcode = $za->open($filename/* , ZipArchive::RDONLY */); // that constant only exists in PHP 7.4 and higher
|
||||||
if ($errcode !== true) {
|
if ($errcode !== true) {
|
||||||
$errors = [
|
$errors = [
|
||||||
ZipArchive::ER_EXISTS => "File already exists.",
|
ZipArchive::ER_EXISTS => 'File already exists.',
|
||||||
ZipArchive::ER_INCONS => "Zip archive inconsistent.",
|
ZipArchive::ER_INCONS => 'Zip archive inconsistent.',
|
||||||
ZipArchive::ER_INVAL => "Invalid argument.",
|
ZipArchive::ER_INVAL => 'Invalid argument.',
|
||||||
ZipArchive::ER_MEMORY => "Malloc failure.",
|
ZipArchive::ER_MEMORY => 'Malloc failure.',
|
||||||
ZipArchive::ER_NOENT => "No such file.",
|
ZipArchive::ER_NOENT => 'No such file.',
|
||||||
ZipArchive::ER_NOZIP => "Not a zip archive.",
|
ZipArchive::ER_NOZIP => 'Not a zip archive.',
|
||||||
ZipArchive::ER_OPEN => "Can't open file.",
|
ZipArchive::ER_OPEN => "Can't open file.",
|
||||||
ZipArchive::ER_READ => "Read error.",
|
ZipArchive::ER_READ => 'Read error.',
|
||||||
ZipArchive::ER_SEEK => "Seek error."
|
ZipArchive::ER_SEEK => 'Seek error.',
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->error("Could not access file: ".$filename." - ".array_key_exists($errcode,$errors) ? $errors[$errcode] : " Unknown reason: $errcode");
|
return $this->error('Could not access file: '.$filename.' - '.array_key_exists($errcode, $errors) ? $errors[$errcode] : " Unknown reason: $errcode");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$private_dirs = [
|
$private_dirs = [
|
||||||
'storage/private_uploads/assets', // these are asset _files_, not the pictures.
|
'storage/private_uploads/assets', // these are asset _files_, not the pictures.
|
||||||
'storage/private_uploads/audits',
|
'storage/private_uploads/audits',
|
||||||
|
@ -86,11 +84,11 @@ class RestoreFromBackup extends Command
|
||||||
'storage/private_uploads/assetmodels',
|
'storage/private_uploads/assetmodels',
|
||||||
'storage/private_uploads/users',
|
'storage/private_uploads/users',
|
||||||
'storage/private_uploads/licenses',
|
'storage/private_uploads/licenses',
|
||||||
'storage/private_uploads/signatures'
|
'storage/private_uploads/signatures',
|
||||||
];
|
];
|
||||||
$private_files = [
|
$private_files = [
|
||||||
'storage/oauth-private.key',
|
'storage/oauth-private.key',
|
||||||
'storage/oauth-public.key'
|
'storage/oauth-public.key',
|
||||||
];
|
];
|
||||||
$public_dirs = [
|
$public_dirs = [
|
||||||
'public/uploads/companies',
|
'public/uploads/companies',
|
||||||
|
@ -108,16 +106,16 @@ class RestoreFromBackup extends Command
|
||||||
'public/uploads/models',
|
'public/uploads/models',
|
||||||
'public/uploads/categories',
|
'public/uploads/categories',
|
||||||
'public/uploads/avatars',
|
'public/uploads/avatars',
|
||||||
'public/uploads/manufacturers'
|
'public/uploads/manufacturers',
|
||||||
];
|
];
|
||||||
|
|
||||||
$public_files = [
|
$public_files = [
|
||||||
'public/uploads/logo.*',
|
'public/uploads/logo.*',
|
||||||
'public/uploads/setting-email_logo*',
|
'public/uploads/setting-email_logo*',
|
||||||
'public/uploads/setting-label_logo*',
|
'public/uploads/setting-label_logo*',
|
||||||
'public/uploads/setting-logo*',
|
'public/uploads/setting-logo*',
|
||||||
'public/uploads/favicon.*',
|
'public/uploads/favicon.*',
|
||||||
'public/uploads/favicon-uploaded.*'
|
'public/uploads/favicon-uploaded.*',
|
||||||
];
|
];
|
||||||
|
|
||||||
$all_files = $private_dirs + $public_dirs;
|
$all_files = $private_dirs + $public_dirs;
|
||||||
|
@ -127,64 +125,64 @@ class RestoreFromBackup extends Command
|
||||||
|
|
||||||
$interesting_files = [];
|
$interesting_files = [];
|
||||||
$boring_files = [];
|
$boring_files = [];
|
||||||
|
|
||||||
for ($i=0; $i<$za->numFiles;$i++) {
|
for ($i = 0; $i < $za->numFiles; $i++) {
|
||||||
$stat_results = $za->statIndex($i);
|
$stat_results = $za->statIndex($i);
|
||||||
// echo "index: $i\n";
|
// echo "index: $i\n";
|
||||||
// print_r($stat_results);
|
// print_r($stat_results);
|
||||||
|
|
||||||
$raw_path = $stat_results['name'];
|
$raw_path = $stat_results['name'];
|
||||||
if(strpos($raw_path,'\\')!==false) { //found a backslash, swap it to forward-slash
|
if (strpos($raw_path, '\\') !== false) { //found a backslash, swap it to forward-slash
|
||||||
$raw_path = strtr($raw_path,'\\','/');
|
$raw_path = strtr($raw_path, '\\', '/');
|
||||||
//print "Translating file: ".$stat_results['name']." to: ".$raw_path."\n";
|
//print "Translating file: ".$stat_results['name']." to: ".$raw_path."\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
// skip macOS resource fork files (?!?!?!)
|
// skip macOS resource fork files (?!?!?!)
|
||||||
if(strpos($raw_path,"__MACOSX")!==false && strpos($raw_path,"._") !== false) {
|
if (strpos($raw_path, '__MACOSX') !== false && strpos($raw_path, '._') !== false) {
|
||||||
//print "SKIPPING macOS Resource fork file: $raw_path\n";
|
//print "SKIPPING macOS Resource fork file: $raw_path\n";
|
||||||
$boring_files[] = $raw_path;
|
$boring_files[] = $raw_path;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(@pathinfo($raw_path)['extension'] == "sql") {
|
if (@pathinfo($raw_path)['extension'] == 'sql') {
|
||||||
print "Found a sql file!\n";
|
echo "Found a sql file!\n";
|
||||||
$sqlfiles[] = $raw_path;
|
$sqlfiles[] = $raw_path;
|
||||||
$sqlfile_indices[] = $i;
|
$sqlfile_indices[] = $i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(array_merge($private_dirs,$public_dirs) as $dir) {
|
foreach (array_merge($private_dirs, $public_dirs) as $dir) {
|
||||||
$last_pos = strrpos($raw_path,$dir.'/');
|
$last_pos = strrpos($raw_path, $dir.'/');
|
||||||
if($last_pos !== false ) {
|
if ($last_pos !== false) {
|
||||||
//print("INTERESTING - last_pos is $last_pos when searching $raw_path for $dir - last_pos+strlen(\$dir) is: ".($last_pos+strlen($dir))." and strlen(\$rawpath) is: ".strlen($raw_path)."\n");
|
//print("INTERESTING - last_pos is $last_pos when searching $raw_path for $dir - last_pos+strlen(\$dir) is: ".($last_pos+strlen($dir))." and strlen(\$rawpath) is: ".strlen($raw_path)."\n");
|
||||||
//print("We would copy $raw_path to $dir.\n"); //FIXME append to a path?
|
//print("We would copy $raw_path to $dir.\n"); //FIXME append to a path?
|
||||||
$interesting_files[$raw_path] = ['dest' =>$dir, 'index' => $i];
|
$interesting_files[$raw_path] = ['dest' =>$dir, 'index' => $i];
|
||||||
continue 2;
|
continue 2;
|
||||||
if($last_pos + strlen($dir) +1 == strlen($raw_path)) {
|
if ($last_pos + strlen($dir) + 1 == strlen($raw_path)) {
|
||||||
// we don't care about that; we just want files with the appropriate prefix
|
// we don't care about that; we just want files with the appropriate prefix
|
||||||
//print("FOUND THE EXACT DIRECTORY: $dir AT: $raw_path!!!\n");
|
//print("FOUND THE EXACT DIRECTORY: $dir AT: $raw_path!!!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$good_extensions = ["png","gif","jpg","svg","jpeg","doc","docx","pdf","txt",
|
$good_extensions = ['png', 'gif', 'jpg', 'svg', 'jpeg', 'doc', 'docx', 'pdf', 'txt',
|
||||||
"zip","rar","xls","xlsx","lic","xml","rtf", "webp","key","ico"];
|
'zip', 'rar', 'xls', 'xlsx', 'lic', 'xml', 'rtf', 'webp', 'key', 'ico', ];
|
||||||
foreach(array_merge($private_files, $public_files) as $file) {
|
foreach (array_merge($private_files, $public_files) as $file) {
|
||||||
$has_wildcard = (strpos($file,"*") !== false);
|
$has_wildcard = (strpos($file, '*') !== false);
|
||||||
if($has_wildcard) {
|
if ($has_wildcard) {
|
||||||
$file = substr($file,0,-1); //trim last character (which should be the wildcard)
|
$file = substr($file, 0, -1); //trim last character (which should be the wildcard)
|
||||||
}
|
}
|
||||||
$last_pos = strrpos($raw_path,$file); // no trailing slash!
|
$last_pos = strrpos($raw_path, $file); // no trailing slash!
|
||||||
if($last_pos !== false ) {
|
if ($last_pos !== false) {
|
||||||
$extension = strtolower(pathinfo($raw_path, PATHINFO_EXTENSION));
|
$extension = strtolower(pathinfo($raw_path, PATHINFO_EXTENSION));
|
||||||
if(!in_array($extension, $good_extensions)) {
|
if (! in_array($extension, $good_extensions)) {
|
||||||
$this->warn("Potentially unsafe file ".$raw_path." is being skipped");
|
$this->warn('Potentially unsafe file '.$raw_path.' is being skipped');
|
||||||
$boring_files[] = $raw_path;
|
$boring_files[] = $raw_path;
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
//print("INTERESTING - last_pos is $last_pos when searching $raw_path for $file - last_pos+strlen(\$file) is: ".($last_pos+strlen($file))." and strlen(\$rawpath) is: ".strlen($raw_path)."\n");
|
//print("INTERESTING - last_pos is $last_pos when searching $raw_path for $file - last_pos+strlen(\$file) is: ".($last_pos+strlen($file))." and strlen(\$rawpath) is: ".strlen($raw_path)."\n");
|
||||||
//no wildcards found in $file, process 'normally'
|
//no wildcards found in $file, process 'normally'
|
||||||
if($last_pos + strlen($file) == strlen($raw_path) || $has_wildcard) { //again, no trailing slash. or this is a wildcard and we just take it.
|
if ($last_pos + strlen($file) == strlen($raw_path) || $has_wildcard) { //again, no trailing slash. or this is a wildcard and we just take it.
|
||||||
// print("FOUND THE EXACT FILE: $file AT: $raw_path!!!\n"); //we *do* care about this, though.
|
// print("FOUND THE EXACT FILE: $file AT: $raw_path!!!\n"); //we *do* care about this, though.
|
||||||
$interesting_files[$raw_path] = ['dest' => dirname($file),'index' => $i];
|
$interesting_files[$raw_path] = ['dest' => dirname($file), 'index' => $i];
|
||||||
continue 2;
|
continue 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,11 +192,11 @@ class RestoreFromBackup extends Command
|
||||||
|
|
||||||
// print_r($interesting_files);exit(-1);
|
// print_r($interesting_files);exit(-1);
|
||||||
|
|
||||||
if( count($sqlfiles) != 1) {
|
if (count($sqlfiles) != 1) {
|
||||||
return $this->error("There should be exactly *one* sql backup file found, found: ".( count($sqlfiles) == 0 ? "None" : implode(", ",$sqlfiles)));
|
return $this->error('There should be exactly *one* sql backup file found, found: '.(count($sqlfiles) == 0 ? 'None' : implode(', ', $sqlfiles)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if( strpos($sqlfiles[0], "db-dumps") === false ) {
|
if (strpos($sqlfiles[0], 'db-dumps') === false) {
|
||||||
//return $this->error("SQL backup file is missing 'db-dumps' component of full pathname: ".$sqlfiles[0]);
|
//return $this->error("SQL backup file is missing 'db-dumps' component of full pathname: ".$sqlfiles[0]);
|
||||||
//older Snipe-IT installs don't have the db-dumps subdirectory component
|
//older Snipe-IT installs don't have the db-dumps subdirectory component
|
||||||
}
|
}
|
||||||
|
@ -207,14 +205,14 @@ class RestoreFromBackup extends Command
|
||||||
$pipes = [];
|
$pipes = [];
|
||||||
|
|
||||||
$env_vars = getenv();
|
$env_vars = getenv();
|
||||||
$env_vars['MYSQL_PWD'] = config("database.connections.mysql.password");
|
$env_vars['MYSQL_PWD'] = config('database.connections.mysql.password');
|
||||||
$proc_results = proc_open("mysql -h ".escapeshellarg(config('database.connections.mysql.host'))." -u ".escapeshellarg(config('database.connections.mysql.username'))." ".escapeshellarg(config('database.connections.mysql.database')), // yanked -p since we pass via ENV
|
$proc_results = proc_open('mysql -h '.escapeshellarg(config('database.connections.mysql.host')).' -u '.escapeshellarg(config('database.connections.mysql.username')).' '.escapeshellarg(config('database.connections.mysql.database')), // yanked -p since we pass via ENV
|
||||||
[0 => ['pipe','r'],1 => ['pipe','w'],2 => ['pipe','w']],
|
[0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']],
|
||||||
$pipes,
|
$pipes,
|
||||||
null,
|
null,
|
||||||
$env_vars); // this is not super-duper awesome-secure, but definitely more secure than showing it on the CLI, or dropping temporary files with passwords in them.
|
$env_vars); // this is not super-duper awesome-secure, but definitely more secure than showing it on the CLI, or dropping temporary files with passwords in them.
|
||||||
if($proc_results === false) {
|
if ($proc_results === false) {
|
||||||
return $this->error("Unable to invoke mysql via CLI");
|
return $this->error('Unable to invoke mysql via CLI');
|
||||||
}
|
}
|
||||||
|
|
||||||
// $this->info("Stdout says? ".fgets($pipes[1])); //FIXME: I think we might need to set non-blocking mode to use this properly?
|
// $this->info("Stdout says? ".fgets($pipes[1])); //FIXME: I think we might need to set non-blocking mode to use this properly?
|
||||||
|
@ -232,17 +230,19 @@ class RestoreFromBackup extends Command
|
||||||
$this->info($stdout);
|
$this->info($stdout);
|
||||||
$stderr = fgets($pipes[2]);
|
$stderr = fgets($pipes[2]);
|
||||||
$this->info($stderr);
|
$this->info($stderr);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(($buffer = fgets($sql_contents)) !== false ) {
|
while (($buffer = fgets($sql_contents)) !== false) {
|
||||||
//$this->info("Buffer is: '$buffer'");
|
//$this->info("Buffer is: '$buffer'");
|
||||||
$bytes_written = fwrite($pipes[0],$buffer);
|
$bytes_written = fwrite($pipes[0], $buffer);
|
||||||
if($bytes_written === false) {
|
if ($bytes_written === false) {
|
||||||
$stdout = fgets($pipes[1]);
|
$stdout = fgets($pipes[1]);
|
||||||
$this->info($stdout);
|
$this->info($stdout);
|
||||||
$stderr = fgets($pipes[2]);
|
$stderr = fgets($pipes[2]);
|
||||||
$this->info($stderr);
|
$this->info($stderr);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -257,41 +257,40 @@ class RestoreFromBackup extends Command
|
||||||
|
|
||||||
//wait, have to do fclose() on all pipes first?
|
//wait, have to do fclose() on all pipes first?
|
||||||
$close_results = proc_close($proc_results);
|
$close_results = proc_close($proc_results);
|
||||||
if($close_results != 0) {
|
if ($close_results != 0) {
|
||||||
return $this->error("There may have been a problem with the database import: Error number ".$close_results);
|
return $this->error('There may have been a problem with the database import: Error number '.$close_results);
|
||||||
}
|
}
|
||||||
|
|
||||||
//and now copy the files over too (right?)
|
//and now copy the files over too (right?)
|
||||||
//FIXME - we don't prune the filesystem space yet!!!!
|
//FIXME - we don't prune the filesystem space yet!!!!
|
||||||
if($this->option('no-progress')) {
|
if ($this->option('no-progress')) {
|
||||||
$bar = null;
|
$bar = null;
|
||||||
} else {
|
} else {
|
||||||
$bar = $this->output->createProgressBar(count($interesting_files));
|
$bar = $this->output->createProgressBar(count($interesting_files));
|
||||||
}
|
}
|
||||||
foreach($interesting_files AS $pretty_file_name => $file_details) {
|
foreach ($interesting_files as $pretty_file_name => $file_details) {
|
||||||
$ugly_file_name = $za->statIndex($file_details['index'])['name'];
|
$ugly_file_name = $za->statIndex($file_details['index'])['name'];
|
||||||
$fp = $za->getStream($ugly_file_name);
|
$fp = $za->getStream($ugly_file_name);
|
||||||
//$this->info("Weird problem, here are file details? ".print_r($file_details,true));
|
//$this->info("Weird problem, here are file details? ".print_r($file_details,true));
|
||||||
$migrated_file = fopen($file_details['dest']."/".basename($pretty_file_name),"w");
|
$migrated_file = fopen($file_details['dest'].'/'.basename($pretty_file_name), 'w');
|
||||||
while(($buffer = fgets($fp))!== false) {
|
while (($buffer = fgets($fp)) !== false) {
|
||||||
fwrite($migrated_file,$buffer);
|
fwrite($migrated_file, $buffer);
|
||||||
}
|
}
|
||||||
fclose($migrated_file);
|
fclose($migrated_file);
|
||||||
fclose($fp);
|
fclose($fp);
|
||||||
//$this->info("Wrote $ugly_file_name to $pretty_file_name");
|
//$this->info("Wrote $ugly_file_name to $pretty_file_name");
|
||||||
if($bar) {
|
if ($bar) {
|
||||||
$bar->advance();
|
$bar->advance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if($bar) {
|
if ($bar) {
|
||||||
$bar->finish();
|
$bar->finish();
|
||||||
$this->line("");
|
$this->line('');
|
||||||
} else {
|
} else {
|
||||||
$this->info(count($interesting_files)." files were succesfully transferred");
|
$this->info(count($interesting_files).' files were succesfully transferred');
|
||||||
}
|
}
|
||||||
foreach($boring_files as $boring_file) {
|
foreach ($boring_files as $boring_file) {
|
||||||
$this->warn($boring_file." was skipped.");
|
$this->warn($boring_file.' was skipped.');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use Artisan;
|
|
||||||
use App\Models\CustomField;
|
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
|
use App\Models\CustomField;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use \Illuminate\Encryption\Encrypter;
|
use Artisan;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Encryption\Encrypter;
|
||||||
|
|
||||||
class RotateAppKey extends Command
|
class RotateAppKey extends Command
|
||||||
{
|
{
|
||||||
|
@ -42,9 +42,7 @@ class RotateAppKey extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
if ($this->confirm("\n****************************************************\nTHIS WILL MODIFY YOUR APP_KEY AND DE-CRYPT YOUR ENCRYPTED CUSTOM FIELDS AND \nRE-ENCRYPT THEM WITH A NEWLY GENERATED KEY. \n\nThere is NO undo. \n\nMake SURE you have a database backup and a backup of your .env generated BEFORE running this command. \n\nIf you do not save the newly generated APP_KEY to your .env in this process, \nyour encrypted data will no longer be decryptable. \n\nAre you SURE you wish to continue, and have confirmed you have a database backup and an .env backup? ")) {
|
if ($this->confirm("\n****************************************************\nTHIS WILL MODIFY YOUR APP_KEY AND DE-CRYPT YOUR ENCRYPTED CUSTOM FIELDS AND \nRE-ENCRYPT THEM WITH A NEWLY GENERATED KEY. \n\nThere is NO undo. \n\nMake SURE you have a database backup and a backup of your .env generated BEFORE running this command. \n\nIf you do not save the newly generated APP_KEY to your .env in this process, \nyour encrypted data will no longer be decryptable. \n\nAre you SURE you wish to continue, and have confirmed you have a database backup and an .env backup? ")) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Get the existing app_key and ciphers
|
// Get the existing app_key and ciphers
|
||||||
// We put them in a variable since we clear the cache partway through here.
|
// We put them in a variable since we clear the cache partway through here.
|
||||||
|
@ -73,33 +71,26 @@ class RotateAppKey extends Command
|
||||||
|
|
||||||
$fields = CustomField::where('field_encrypted', '1')->get();
|
$fields = CustomField::where('field_encrypted', '1')->get();
|
||||||
|
|
||||||
|
|
||||||
foreach ($fields as $field) {
|
foreach ($fields as $field) {
|
||||||
|
|
||||||
$assets = Asset::whereNotNull($field->db_column)->get();
|
$assets = Asset::whereNotNull($field->db_column)->get();
|
||||||
|
|
||||||
foreach ($assets as $asset) {
|
foreach ($assets as $asset) {
|
||||||
|
|
||||||
$asset->{$field->db_column} = $oldEncrypter->decrypt($asset->{$field->db_column});
|
$asset->{$field->db_column} = $oldEncrypter->decrypt($asset->{$field->db_column});
|
||||||
$this->line('DECRYPTED: '. $field->db_column);
|
$this->line('DECRYPTED: '.$field->db_column);
|
||||||
$asset->{$field->db_column} = $newEncrypter->encrypt($asset->{$field->db_column});
|
$asset->{$field->db_column} = $newEncrypter->encrypt($asset->{$field->db_column});
|
||||||
$this->line('ENCRYPTED: '.$field->db_column);
|
$this->line('ENCRYPTED: '.$field->db_column);
|
||||||
$asset->save();
|
$asset->save();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle the LDAP password if one is provided
|
// Handle the LDAP password if one is provided
|
||||||
$setting = Setting::first();
|
$setting = Setting::first();
|
||||||
if ($setting->ldap_pword!='') {
|
if ($setting->ldap_pword != '') {
|
||||||
$setting->ldap_pword = $oldEncrypter->decrypt($setting->ldap_pword);
|
$setting->ldap_pword = $oldEncrypter->decrypt($setting->ldap_pword);
|
||||||
$setting->ldap_pword = $newEncrypter->encrypt($setting->ldap_pword);
|
$setting->ldap_pword = $newEncrypter->encrypt($setting->ldap_pword);
|
||||||
$setting->save();
|
$setting->save();
|
||||||
$this->warn('LDAP password has been re-encrypted.');
|
$this->warn('LDAP password has been re-encrypted.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->info('This operation has been canceled. No changes have been made.');
|
$this->info('This operation has been canceled. No changes have been made.');
|
||||||
}
|
}
|
||||||
|
@ -113,7 +104,6 @@ class RotateAppKey extends Command
|
||||||
*/
|
*/
|
||||||
protected function writeNewEnvironmentFileWith($key)
|
protected function writeNewEnvironmentFileWith($key)
|
||||||
{
|
{
|
||||||
|
|
||||||
file_put_contents($this->laravel->environmentFilePath(), preg_replace(
|
file_put_contents($this->laravel->environmentFilePath(), preg_replace(
|
||||||
$this->keyReplacementPattern(),
|
$this->keyReplacementPattern(),
|
||||||
'APP_KEY='.$key,
|
'APP_KEY='.$key,
|
||||||
|
@ -129,7 +119,7 @@ class RotateAppKey extends Command
|
||||||
protected function keyReplacementPattern()
|
protected function keyReplacementPattern()
|
||||||
{
|
{
|
||||||
$escaped = preg_quote('='.$this->laravel['config']['app.key'], '/');
|
$escaped = preg_quote('='.$this->laravel['config']['app.key'], '/');
|
||||||
|
|
||||||
return "/^APP_KEY{$escaped}/m";
|
return "/^APP_KEY{$escaped}/m";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,22 +39,16 @@ class SendCurrentInventoryToUsers extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
$users = User::whereNull('deleted_at')->whereNotNull('email')->with('assets', 'accessories', 'licenses')->get();
|
$users = User::whereNull('deleted_at')->whereNotNull('email')->with('assets', 'accessories', 'licenses')->get();
|
||||||
|
|
||||||
$count = 0;
|
$count = 0;
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
|
if (($user->assets->count() > 0) || ($user->accessories->count() > 0) || ($user->licenses->count() > 0)) {
|
||||||
if (($user->assets->count() > 0) || ($user->accessories->count() > 0) || ($user->licenses->count() > 0))
|
|
||||||
{
|
|
||||||
$count++;
|
$count++;
|
||||||
$user->notify((new CurrentInventory($user)));
|
$user->notify((new CurrentInventory($user)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info($count.' users notified.');
|
$this->info($count.' users notified.');
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,12 @@
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
|
use App\Models\Recipients\AlertRecipient;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Notifications\ExpectedCheckinAdminNotification;
|
use App\Notifications\ExpectedCheckinAdminNotification;
|
||||||
use App\Notifications\ExpectedCheckinNotification;
|
use App\Notifications\ExpectedCheckinNotification;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use App\Models\Recipients\AlertRecipient;
|
|
||||||
|
|
||||||
class SendExpectedCheckinAlerts extends Command
|
class SendExpectedCheckinAlerts extends Command
|
||||||
{
|
{
|
||||||
|
@ -41,12 +41,12 @@ class SendExpectedCheckinAlerts extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$settings = Setting::getSettings();
|
$settings = Setting::getSettings();
|
||||||
$whenNotify = Carbon::now()->addDays(7);
|
$whenNotify = Carbon::now()->addDays(7);
|
||||||
$assets = Asset::with('assignedTo')->whereNotNull('assigned_to')->whereNotNull('expected_checkin')->where('expected_checkin', '<=', $whenNotify)->get();
|
$assets = Asset::with('assignedTo')->whereNotNull('assigned_to')->whereNotNull('expected_checkin')->where('expected_checkin', '<=', $whenNotify)->get();
|
||||||
|
|
||||||
$this->info($whenNotify . ' is deadline');
|
$this->info($whenNotify.' is deadline');
|
||||||
$this->info($assets->count() . ' assets');
|
$this->info($assets->count().' assets');
|
||||||
|
|
||||||
foreach ($assets as $asset) {
|
foreach ($assets as $asset) {
|
||||||
if ($asset->assigned && $asset->checkedOutToUser()) {
|
if ($asset->assigned && $asset->checkedOutToUser()) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ class SendExpirationAlerts extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
$settings = Setting::getSettings();
|
$settings = Setting::getSettings();
|
||||||
$threshold = $settings->alert_interval;
|
$threshold = $settings->alert_interval;
|
||||||
|
|
||||||
if (($settings->alert_email != '') && ($settings->alerts_enabled == 1)) {
|
if (($settings->alert_email != '') && ($settings->alerts_enabled == 1)) {
|
||||||
|
|
|
@ -4,13 +4,13 @@ namespace App\Console\Commands;
|
||||||
|
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\License;
|
use App\Models\License;
|
||||||
|
use App\Models\Recipients;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Notifications\ExpiringAssetsNotification;
|
use App\Notifications\ExpiringAssetsNotification;
|
||||||
use App\Models\Recipients;
|
|
||||||
use DB;
|
|
||||||
use Illuminate\Console\Command;
|
|
||||||
use App\Notifications\SendUpcomingAuditNotification;
|
use App\Notifications\SendUpcomingAuditNotification;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use DB;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
class SendUpcomingAuditReport extends Command
|
class SendUpcomingAuditReport extends Command
|
||||||
{
|
{
|
||||||
|
@ -54,7 +54,6 @@ class SendUpcomingAuditReport extends Command
|
||||||
return new \App\Models\Recipients\AlertRecipient($item);
|
return new \App\Models\Recipients\AlertRecipient($item);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// Assets due for auditing
|
// Assets due for auditing
|
||||||
|
|
||||||
$assets = Asset::whereNotNull('next_audit_date')
|
$assets = Asset::whereNotNull('next_audit_date')
|
||||||
|
@ -62,7 +61,6 @@ class SendUpcomingAuditReport extends Command
|
||||||
->orderBy('last_audit_date', 'asc')->get();
|
->orderBy('last_audit_date', 'asc')->get();
|
||||||
|
|
||||||
if ($assets->count() > 0) {
|
if ($assets->count() > 0) {
|
||||||
|
|
||||||
$this->info(trans_choice('mail.upcoming-audits', $assets->count(),
|
$this->info(trans_choice('mail.upcoming-audits', $assets->count(),
|
||||||
['count' => $assets->count(), 'threshold' => $settings->audit_warning_days]));
|
['count' => $assets->count(), 'threshold' => $settings->audit_warning_days]));
|
||||||
\Notification::send($recipients, new SendUpcomingAuditNotification($assets, $settings->audit_warning_days));
|
\Notification::send($recipients, new SendUpcomingAuditNotification($assets, $settings->audit_warning_days));
|
||||||
|
@ -70,14 +68,11 @@ class SendUpcomingAuditReport extends Command
|
||||||
} else {
|
} else {
|
||||||
$this->info('No assets to be audited. No report sent.');
|
$this->info('No assets to be audited. No report sent.');
|
||||||
}
|
}
|
||||||
|
} elseif ($settings->alert_email == '') {
|
||||||
|
|
||||||
|
|
||||||
} elseif ($settings->alert_email=='') {
|
|
||||||
$this->error('Could not send email. No alert email configured in settings');
|
$this->error('Could not send email. No alert email configured in settings');
|
||||||
} elseif (!$settings->audit_warning_days) {
|
} elseif (! $settings->audit_warning_days) {
|
||||||
$this->error('No audit warning days set in Admin Notifications. No mail will be sent.');
|
$this->error('No audit warning days set in Admin Notifications. No mail will be sent.');
|
||||||
} elseif ($settings->alerts_enabled!=1) {
|
} elseif ($settings->alerts_enabled != 1) {
|
||||||
$this->info('Alerts are disabled in the settings. No mail will be sent');
|
$this->info('Alerts are disabled in the settings. No mail will be sent');
|
||||||
} else {
|
} else {
|
||||||
$this->error('Something went wrong. :( ');
|
$this->error('Something went wrong. :( ');
|
||||||
|
@ -85,7 +80,5 @@ class SendUpcomingAuditReport extends Command
|
||||||
$this->error('Admin Audit Warning Setting: '.$settings->audit_warning_days);
|
$this->error('Admin Audit Warning Setting: '.$settings->audit_warning_days);
|
||||||
$this->error('Admin Alerts Emnabled: '.$settings->alerts_enabled);
|
$this->error('Admin Alerts Emnabled: '.$settings->alerts_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,14 +45,14 @@ class SyncAssetCounters extends Command
|
||||||
if ($assets) {
|
if ($assets) {
|
||||||
if ($assets->count() > 0) {
|
if ($assets->count() > 0) {
|
||||||
$bar = $this->output->createProgressBar($assets->count());
|
$bar = $this->output->createProgressBar($assets->count());
|
||||||
|
|
||||||
foreach ($assets as $asset) {
|
foreach ($assets as $asset) {
|
||||||
$asset->checkin_counter = (int) $asset->checkins_count;
|
$asset->checkin_counter = (int) $asset->checkins_count;
|
||||||
$asset->checkout_counter = (int) $asset->checkouts_count;
|
$asset->checkout_counter = (int) $asset->checkouts_count;
|
||||||
$asset->requests_counter = (int) $asset->user_requests_count;
|
$asset->requests_counter = (int) $asset->user_requests_count;
|
||||||
$asset->unsetEventDispatcher();
|
$asset->unsetEventDispatcher();
|
||||||
$asset->save();
|
$asset->save();
|
||||||
$output['info'][] = 'Asset: ' . $asset->id . ' has ' . $asset->checkin_counter . ' checkins, ' . $asset->checkout_counter . ' checkouts, and ' . $asset->requests_counter . ' requests';
|
$output['info'][] = 'Asset: '.$asset->id.' has '.$asset->checkin_counter.' checkins, '.$asset->checkout_counter.' checkouts, and '.$asset->requests_counter.' requests';
|
||||||
$bar->advance();
|
$bar->advance();
|
||||||
}
|
}
|
||||||
$bar->finish();
|
$bar->finish();
|
||||||
|
@ -62,15 +62,10 @@ class SyncAssetCounters extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
$time_elapsed_secs = microtime(true) - $start;
|
$time_elapsed_secs = microtime(true) - $start;
|
||||||
$this->info('Sync executed in ' . $time_elapsed_secs . ' seconds');
|
$this->info('Sync executed in '.$time_elapsed_secs.' seconds');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$this->info('No assets to sync');
|
$this->info('No assets to sync');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ class SyncAssetLocations extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
$output['info'] = [];
|
$output['info'] = [];
|
||||||
$output['warn'] = [];
|
$output['warn'] = [];
|
||||||
$output['error'] = [];
|
$output['error'] = [];
|
||||||
|
@ -51,96 +50,89 @@ class SyncAssetLocations extends Command
|
||||||
$output['info'][] = 'There are '.$rtd_assets->count().' unassigned assets.';
|
$output['info'][] = 'There are '.$rtd_assets->count().' unassigned assets.';
|
||||||
|
|
||||||
foreach ($rtd_assets as $rtd_asset) {
|
foreach ($rtd_assets as $rtd_asset) {
|
||||||
$output['info'][] = 'Setting Unassigned Asset ' . $rtd_asset->id . ' ('.$rtd_asset->asset_tag.') to location: ' . $rtd_asset->rtd_location_id . " because their default location is: " . $rtd_asset->rtd_location_id;
|
$output['info'][] = 'Setting Unassigned Asset '.$rtd_asset->id.' ('.$rtd_asset->asset_tag.') to location: '.$rtd_asset->rtd_location_id.' because their default location is: '.$rtd_asset->rtd_location_id;
|
||||||
$rtd_asset->location_id=$rtd_asset->rtd_location_id;
|
$rtd_asset->location_id = $rtd_asset->rtd_location_id;
|
||||||
$rtd_asset->unsetEventDispatcher();
|
$rtd_asset->unsetEventDispatcher();
|
||||||
$rtd_asset->save();
|
$rtd_asset->save();
|
||||||
$bar->advance();
|
$bar->advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
$assigned_user_assets = Asset::where('assigned_type','App\Models\User')->whereNotNull('assigned_to')->whereNull('deleted_at')->get();
|
$assigned_user_assets = Asset::where('assigned_type', \App\Models\User::class)->whereNotNull('assigned_to')->whereNull('deleted_at')->get();
|
||||||
$output['info'][] = 'There are '.$assigned_user_assets->count().' assets checked out to users.';
|
$output['info'][] = 'There are '.$assigned_user_assets->count().' assets checked out to users.';
|
||||||
foreach ($assigned_user_assets as $assigned_user_asset) {
|
foreach ($assigned_user_assets as $assigned_user_asset) {
|
||||||
if (($assigned_user_asset->assignedTo) && ($assigned_user_asset->assignedTo->userLoc)) {
|
if (($assigned_user_asset->assignedTo) && ($assigned_user_asset->assignedTo->userLoc)) {
|
||||||
$new_location = $assigned_user_asset->assignedTo->userLoc->id;
|
$new_location = $assigned_user_asset->assignedTo->userLoc->id;
|
||||||
$output['info'][] ='Setting User Asset ' . $assigned_user_asset->id . ' ('.$assigned_user_asset->asset_tag.') to ' . $assigned_user_asset->assignedTo->userLoc->name . ' which is id: ' . $new_location;
|
$output['info'][] = 'Setting User Asset '.$assigned_user_asset->id.' ('.$assigned_user_asset->asset_tag.') to '.$assigned_user_asset->assignedTo->userLoc->name.' which is id: '.$new_location;
|
||||||
} else {
|
} else {
|
||||||
$output['warn'][] ='Asset ' . $assigned_user_asset->id . ' ('.$assigned_user_asset->asset_tag.') still has no location! ';
|
$output['warn'][] = 'Asset '.$assigned_user_asset->id.' ('.$assigned_user_asset->asset_tag.') still has no location! ';
|
||||||
$new_location = $assigned_user_asset->rtd_location_id;
|
$new_location = $assigned_user_asset->rtd_location_id;
|
||||||
}
|
}
|
||||||
$assigned_user_asset->location_id=$new_location;
|
$assigned_user_asset->location_id = $new_location;
|
||||||
$assigned_user_asset->unsetEventDispatcher();
|
$assigned_user_asset->unsetEventDispatcher();
|
||||||
$assigned_user_asset->save();
|
$assigned_user_asset->save();
|
||||||
$bar->advance();
|
$bar->advance();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$assigned_location_assets = Asset::where('assigned_type','App\Models\Location')
|
$assigned_location_assets = Asset::where('assigned_type', \App\Models\Location::class)
|
||||||
->whereNotNull('assigned_to')->whereNull('deleted_at')->get();
|
->whereNotNull('assigned_to')->whereNull('deleted_at')->get();
|
||||||
$output['info'][] = 'There are '.$assigned_location_assets->count().' assets checked out to locations.';
|
$output['info'][] = 'There are '.$assigned_location_assets->count().' assets checked out to locations.';
|
||||||
|
|
||||||
foreach ($assigned_location_assets as $assigned_location_asset) {
|
foreach ($assigned_location_assets as $assigned_location_asset) {
|
||||||
if ($assigned_location_asset->assignedTo) {
|
if ($assigned_location_asset->assignedTo) {
|
||||||
$assigned_location_asset->location_id = $assigned_location_asset->assignedTo->id;
|
$assigned_location_asset->location_id = $assigned_location_asset->assignedTo->id;
|
||||||
$output['info'][] ='Setting Location Assigned asset ' . $assigned_location_asset->id . ' ('.$assigned_location_asset->asset_tag.') that is checked out to '.$assigned_location_asset->assignedTo->name.' (#'.$assigned_location_asset->assignedTo->id.') to location: ' . $assigned_location_asset->assetLoc()->id;
|
$output['info'][] = 'Setting Location Assigned asset '.$assigned_location_asset->id.' ('.$assigned_location_asset->asset_tag.') that is checked out to '.$assigned_location_asset->assignedTo->name.' (#'.$assigned_location_asset->assignedTo->id.') to location: '.$assigned_location_asset->assetLoc()->id;
|
||||||
$assigned_location_asset->unsetEventDispatcher();
|
$assigned_location_asset->unsetEventDispatcher();
|
||||||
$assigned_location_asset->save();
|
$assigned_location_asset->save();
|
||||||
} else {
|
} else {
|
||||||
$output['warn'][] ='Asset ' . $assigned_location_asset->id . ' ('.$assigned_location_asset->asset_tag.') did not return a valid associated location - perhaps it was deleted?';
|
$output['warn'][] = 'Asset '.$assigned_location_asset->id.' ('.$assigned_location_asset->asset_tag.') did not return a valid associated location - perhaps it was deleted?';
|
||||||
}
|
}
|
||||||
$bar->advance();
|
$bar->advance();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Assigned to assets
|
// Assigned to assets
|
||||||
$assigned_asset_assets = Asset::where('assigned_type','App\Models\Asset')
|
$assigned_asset_assets = Asset::where('assigned_type', \App\Models\Asset::class)
|
||||||
->whereNotNull('assigned_to')->whereNull('deleted_at')->get();
|
->whereNotNull('assigned_to')->whereNull('deleted_at')->get();
|
||||||
$output['info'][] ='Asset-assigned assets: '.$assigned_asset_assets->count();
|
$output['info'][] = 'Asset-assigned assets: '.$assigned_asset_assets->count();
|
||||||
|
|
||||||
foreach ($assigned_asset_assets as $assigned_asset_asset) {
|
foreach ($assigned_asset_assets as $assigned_asset_asset) {
|
||||||
|
|
||||||
// Check to make sure there aren't any invalid relationships
|
// Check to make sure there aren't any invalid relationships
|
||||||
if ($assigned_asset_asset->assetLoc()) {
|
if ($assigned_asset_asset->assetLoc()) {
|
||||||
$assigned_asset_asset->location_id = $assigned_asset_asset->assetLoc()->id;
|
$assigned_asset_asset->location_id = $assigned_asset_asset->assetLoc()->id;
|
||||||
$output['info'][] ='Setting Asset Assigned asset ' . $assigned_asset_asset->assetLoc()->id. ' ('.$assigned_asset_asset->asset_tag.') location to: ' . $assigned_asset_asset->assetLoc()->id;
|
$output['info'][] = 'Setting Asset Assigned asset '.$assigned_asset_asset->assetLoc()->id.' ('.$assigned_asset_asset->asset_tag.') location to: '.$assigned_asset_asset->assetLoc()->id;
|
||||||
$assigned_asset_asset->unsetEventDispatcher();
|
$assigned_asset_asset->unsetEventDispatcher();
|
||||||
$assigned_asset_asset->save();
|
$assigned_asset_asset->save();
|
||||||
} else {
|
} else {
|
||||||
$output['warn'][] ='Asset Assigned asset ' . $assigned_asset_asset->id. ' ('.$assigned_asset_asset->asset_tag.') does not seem to have a valid location';
|
$output['warn'][] = 'Asset Assigned asset '.$assigned_asset_asset->id.' ('.$assigned_asset_asset->asset_tag.') does not seem to have a valid location';
|
||||||
}
|
|
||||||
|
|
||||||
$bar->advance();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$unlocated_assets = Asset::whereNull("location_id")->whereNull('deleted_at')->get();
|
$bar->advance();
|
||||||
$output['info'][] ='Assets still without a location: '.$unlocated_assets->count();
|
}
|
||||||
foreach($unlocated_assets as $unlocated_asset) {
|
|
||||||
$output['warn'][] ='Asset: '.$unlocated_asset->id.' still has no location. ';
|
$unlocated_assets = Asset::whereNull('location_id')->whereNull('deleted_at')->get();
|
||||||
|
$output['info'][] = 'Assets still without a location: '.$unlocated_assets->count();
|
||||||
|
foreach ($unlocated_assets as $unlocated_asset) {
|
||||||
|
$output['warn'][] = 'Asset: '.$unlocated_asset->id.' still has no location. ';
|
||||||
$bar->advance();
|
$bar->advance();
|
||||||
}
|
}
|
||||||
|
|
||||||
$bar->finish();
|
$bar->finish();
|
||||||
$this->info("\n");
|
$this->info("\n");
|
||||||
|
|
||||||
|
if (($this->option('output') == 'all') || ($this->option('output') == 'info')) {
|
||||||
if (($this->option('output')=='all') || ($this->option('output')=='info')) {
|
|
||||||
foreach ($output['info'] as $key => $output_text) {
|
foreach ($output['info'] as $key => $output_text) {
|
||||||
$this->info($output_text);
|
$this->info($output_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (($this->option('output')=='all') || ($this->option('output')=='warn')) {
|
if (($this->option('output') == 'all') || ($this->option('output') == 'warn')) {
|
||||||
foreach ($output['warn'] as $key => $output_text) {
|
foreach ($output['warn'] as $key => $output_text) {
|
||||||
$this->warn($output_text);
|
$this->warn($output_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (($this->option('output')=='all') || ($this->option('output')=='error')) {
|
if (($this->option('output') == 'all') || ($this->option('output') == 'error')) {
|
||||||
foreach ($output['error'] as $key => $output_text) {
|
foreach ($output['error'] as $key => $output_text) {
|
||||||
$this->error($output_text);
|
$this->error($output_text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ use Illuminate\Console\Command;
|
||||||
|
|
||||||
class SystemBackup extends Command
|
class SystemBackup extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command name.
|
* The console command name.
|
||||||
*
|
*
|
||||||
|
@ -40,6 +39,5 @@ class SystemBackup extends Command
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
$this->call('backup:run');
|
$this->call('backup:run');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,6 @@ class Version extends Command
|
||||||
*/
|
*/
|
||||||
public function handle()
|
public function handle()
|
||||||
{
|
{
|
||||||
|
|
||||||
$use_branch = $this->option('branch');
|
$use_branch = $this->option('branch');
|
||||||
$use_type = $this->option('type');
|
$use_type = $this->option('type');
|
||||||
$git_branch = trim(shell_exec('git rev-parse --abbrev-ref HEAD'));
|
$git_branch = trim(shell_exec('git rev-parse --abbrev-ref HEAD'));
|
||||||
|
@ -54,72 +53,66 @@ class Version extends Command
|
||||||
$this->line('Type is: '.$use_type);
|
$this->line('Type is: '.$use_type);
|
||||||
$this->line('Current version is: '.$full_hash_version);
|
$this->line('Current version is: '.$full_hash_version);
|
||||||
|
|
||||||
if (count($version)==3) {
|
if (count($version) == 3) {
|
||||||
$this->line('This does not look like an alpha/beta release.');
|
$this->line('This does not look like an alpha/beta release.');
|
||||||
} else {
|
} else {
|
||||||
if (array_key_exists('3',$version)) {
|
if (array_key_exists('3', $version)) {
|
||||||
$this->line('The current version looks like a beta release.');
|
$this->line('The current version looks like a beta release.');
|
||||||
$prerelease_version = $version[1];
|
$prerelease_version = $version[1];
|
||||||
$hash_version = $version[3];
|
$hash_version = $version[3];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$app_version_raw = explode('.', $app_version);
|
$app_version_raw = explode('.', $app_version);
|
||||||
|
|
||||||
$maj = str_replace('v', '', $app_version_raw[0]);
|
$maj = str_replace('v', '', $app_version_raw[0]);
|
||||||
$min = $app_version_raw[1];
|
$min = $app_version_raw[1];
|
||||||
$patch = '';
|
$patch = '';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// This is a major release that might not have a third .0
|
// This is a major release that might not have a third .0
|
||||||
if (array_key_exists(2, $app_version_raw)) {
|
if (array_key_exists(2, $app_version_raw)) {
|
||||||
$patch = $app_version_raw[2];
|
$patch = $app_version_raw[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($use_type=='major') {
|
if ($use_type == 'major') {
|
||||||
$app_version = "v".($maj + 1).".$min.$patch";
|
$app_version = 'v'.($maj + 1).".$min.$patch";
|
||||||
} elseif ($use_type=='minor') {
|
} elseif ($use_type == 'minor') {
|
||||||
$app_version = "v"."$maj.".($min + 1).".$patch";
|
$app_version = 'v'."$maj.".($min + 1).".$patch";
|
||||||
} elseif ($use_type=='pre') {
|
} elseif ($use_type == 'pre') {
|
||||||
$pre_raw = str_replace('beta','', $prerelease_version);
|
$pre_raw = str_replace('beta', '', $prerelease_version);
|
||||||
$pre_raw = str_replace('alpha','', $pre_raw);
|
$pre_raw = str_replace('alpha', '', $pre_raw);
|
||||||
$pre_raw = str_ireplace('rc','', $pre_raw);
|
$pre_raw = str_ireplace('rc', '', $pre_raw);
|
||||||
$pre_raw = $pre_raw++;
|
$pre_raw = $pre_raw++;
|
||||||
$this->line('Setting the pre-release to '. $prerelease_version.'-'.$pre_raw);
|
$this->line('Setting the pre-release to '.$prerelease_version.'-'.$pre_raw);
|
||||||
$app_version = "v"."$maj.".($min + 1).".$patch";
|
$app_version = 'v'."$maj.".($min + 1).".$patch";
|
||||||
} elseif ($use_type=='patch') {
|
} elseif ($use_type == 'patch') {
|
||||||
$app_version = "v" . "$maj.$min." . ($patch + 1);
|
$app_version = 'v'."$maj.$min.".($patch + 1);
|
||||||
// If nothing is passed, leave the version as it is, just increment the build
|
// If nothing is passed, leave the version as it is, just increment the build
|
||||||
} else {
|
} else {
|
||||||
$app_version = "v" . "$maj.$min." . $patch;
|
$app_version = 'v'."$maj.$min.".$patch;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if this tag already exists, or if this prior to a release
|
// Determine if this tag already exists, or if this prior to a release
|
||||||
$this->line('Running: git rev-parse master '.$current_app_version);
|
$this->line('Running: git rev-parse master '.$current_app_version);
|
||||||
// $pre_release = trim(shell_exec('git rev-parse '.$use_branch.' '.$current_app_version.' 2>&1 1> /dev/null'));
|
// $pre_release = trim(shell_exec('git rev-parse '.$use_branch.' '.$current_app_version.' 2>&1 1> /dev/null'));
|
||||||
|
|
||||||
if ($use_branch=='develop') {
|
if ($use_branch == 'develop') {
|
||||||
$app_version = $app_version.'-pre';
|
$app_version = $app_version.'-pre';
|
||||||
}
|
}
|
||||||
|
|
||||||
$full_app_version = $app_version.' - build '.$build_version.'-'.$hash_version;
|
$full_app_version = $app_version.' - build '.$build_version.'-'.$hash_version;
|
||||||
|
|
||||||
|
|
||||||
$array = var_export(
|
$array = var_export(
|
||||||
array(
|
[
|
||||||
'app_version' => $app_version,
|
'app_version' => $app_version,
|
||||||
'full_app_version' => $full_app_version,
|
'full_app_version' => $full_app_version,
|
||||||
'build_version' => $build_version,
|
'build_version' => $build_version,
|
||||||
'prerelease_version' => $prerelease_version,
|
'prerelease_version' => $prerelease_version,
|
||||||
'hash_version' => $hash_version,
|
'hash_version' => $hash_version,
|
||||||
'full_hash' => $full_hash_version,
|
'full_hash' => $full_hash_version,
|
||||||
'branch' => $git_branch),
|
'branch' => $git_branch, ],
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Construct our file content
|
// Construct our file content
|
||||||
$content = <<<CON
|
$content = <<<CON
|
||||||
|
@ -129,7 +122,6 @@ CON;
|
||||||
|
|
||||||
// And finally write the file and output the current version
|
// And finally write the file and output the current version
|
||||||
\File::put($versionFile, $content);
|
\File::put($versionFile, $content);
|
||||||
$this->info('Setting NEW version: '. $full_app_version.' ('.$git_branch.')');
|
$this->info('Setting NEW version: '.$full_app_version.' ('.$git_branch.')');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||||
|
|
||||||
class Kernel extends ConsoleKernel
|
class Kernel extends ConsoleKernel
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the application's command schedule.
|
* Define the application's command schedule.
|
||||||
*
|
*
|
||||||
|
|
|
@ -18,6 +18,6 @@ class CheckoutAccepted
|
||||||
*/
|
*/
|
||||||
public function __construct(CheckoutAcceptance $acceptance)
|
public function __construct(CheckoutAcceptance $acceptance)
|
||||||
{
|
{
|
||||||
$this->acceptance = $acceptance;
|
$this->acceptance = $acceptance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ use Illuminate\Queue\SerializesModels;
|
||||||
class CheckoutDeclined
|
class CheckoutDeclined
|
||||||
{
|
{
|
||||||
use Dispatchable, SerializesModels;
|
use Dispatchable, SerializesModels;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new event instance.
|
* Create a new event instance.
|
||||||
*
|
*
|
||||||
|
@ -18,6 +18,6 @@ class CheckoutDeclined
|
||||||
*/
|
*/
|
||||||
public function __construct(CheckoutAcceptance $acceptance)
|
public function __construct(CheckoutAcceptance $acceptance)
|
||||||
{
|
{
|
||||||
$this->acceptance = $acceptance;
|
$this->acceptance = $acceptance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ class CheckoutableCheckedIn
|
||||||
{
|
{
|
||||||
$this->checkoutable = $checkoutable;
|
$this->checkoutable = $checkoutable;
|
||||||
$this->checkedOutTo = $checkedOutTo;
|
$this->checkedOutTo = $checkedOutTo;
|
||||||
$this->checkedInBy = $checkedInBy;
|
$this->checkedInBy = $checkedInBy;
|
||||||
$this->note = $note;
|
$this->note = $note;
|
||||||
$this->action_date = $action_date ?? date('Y-m-d');
|
$this->action_date = $action_date ?? date('Y-m-d');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,6 @@ class CheckoutableCheckedOut
|
||||||
$this->checkoutable = $checkoutable;
|
$this->checkoutable = $checkoutable;
|
||||||
$this->checkedOutTo = $checkedOutTo;
|
$this->checkedOutTo = $checkedOutTo;
|
||||||
$this->checkedOutBy = $checkedOutBy;
|
$this->checkedOutBy = $checkedOutBy;
|
||||||
$this->note = $note;
|
$this->note = $note;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,17 @@ use Exception;
|
||||||
|
|
||||||
class CheckoutNotAllowed extends Exception
|
class CheckoutNotAllowed extends Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
private $errorMessage;
|
private $errorMessage;
|
||||||
|
|
||||||
function __construct($errorMessage = null)
|
public function __construct($errorMessage = null)
|
||||||
{
|
{
|
||||||
$this->errorMessage = $errorMessage;
|
$this->errorMessage = $errorMessage;
|
||||||
|
|
||||||
parent::__construct($errorMessage);
|
parent::__construct($errorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return is_null($this->errorMessage) ? "A checkout is not allowed under these circumstances" : $this->errorMessage;
|
return is_null($this->errorMessage) ? 'A checkout is not allowed under these circumstances' : $this->errorMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,30 +2,22 @@
|
||||||
|
|
||||||
namespace App\Exceptions;
|
namespace App\Exceptions;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use Illuminate\Auth\AuthenticationException;
|
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
use Log;
|
use Log;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* A list of the exception types that should not be reported.
|
* A list of the exception types that are not reported.
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $dontReport = [
|
protected $dontReport = [
|
||||||
\Illuminate\Auth\AuthenticationException::class,
|
//
|
||||||
\Illuminate\Auth\Access\AuthorizationException::class,
|
|
||||||
\Symfony\Component\HttpKernel\Exception\HttpException::class,
|
|
||||||
\Illuminate\Database\Eloquent\ModelNotFoundException::class,
|
|
||||||
\Illuminate\Session\TokenMismatchException::class,
|
|
||||||
\Illuminate\Validation\ValidationException::class,
|
|
||||||
\Intervention\Image\Exception\NotSupportedException::class,
|
|
||||||
\League\OAuth2\Server\Exception\OAuthServerException::class,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,25 +25,26 @@ class Handler extends ExceptionHandler
|
||||||
*
|
*
|
||||||
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
|
||||||
*
|
*
|
||||||
* @param \Exception $exception
|
* @param \Throwable $exception
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function report(Exception $exception)
|
public function report(Throwable $exception)
|
||||||
{
|
{
|
||||||
if ($this->shouldReport($exception)) {
|
if ($this->shouldReport($exception)) {
|
||||||
\Log::error($exception);
|
Log::error($exception);
|
||||||
return parent::report($exception);
|
return parent::report($exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render an exception into an HTTP response.
|
* Render an exception into an HTTP response.
|
||||||
|
*
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @param \Illuminate\Http\Request $request
|
||||||
* @param \Exception $e
|
* @param \Exception $e
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function render($request, Exception $e)
|
public function render($request, Throwable $e)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,31 +89,26 @@ class Handler extends ExceptionHandler
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an authentication exception into an unauthenticated response.
|
* A list of the inputs that are never flashed for validation exceptions.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @var array
|
||||||
* @param \Illuminate\Auth\AuthenticationException $exception
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
*/
|
||||||
protected function unauthenticated($request, AuthenticationException $exception)
|
protected $dontFlash = [
|
||||||
{
|
'current_password',
|
||||||
if ($request->expectsJson()) {
|
'password',
|
||||||
return response()->json(['error' => 'Unauthorized or unauthenticated.'], 401);
|
'password_confirmation',
|
||||||
}
|
];
|
||||||
|
|
||||||
return redirect()->guest('login');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a validation exception into a JSON response.
|
* Register the exception handling callbacks for the application.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Http\Request $request
|
* @return void
|
||||||
* @param \Illuminate\Validation\ValidationException $exception
|
|
||||||
* @return \Illuminate\Http\JsonResponse
|
|
||||||
*/
|
*/
|
||||||
protected function invalidJson($request, ValidationException $exception)
|
public function register()
|
||||||
{
|
{
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $exception->errors(), 400));
|
$this->reportable(function (Throwable $e) {
|
||||||
|
//
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,15 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Helpers;
|
namespace App\Helpers;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
class StorageHelper
|
class StorageHelper
|
||||||
{
|
{
|
||||||
static function downloader($filename, $disk = 'default') {
|
public static function downloader($filename, $disk = 'default')
|
||||||
if($disk == 'default') {
|
{
|
||||||
|
if ($disk == 'default') {
|
||||||
$disk = config('filesystems.default');
|
$disk = config('filesystems.default');
|
||||||
}
|
}
|
||||||
switch(config("filesystems.disks.$disk.driver")) {
|
switch (config("filesystems.disks.$disk.driver")) {
|
||||||
case 'local':
|
case 'local':
|
||||||
return response()->download(Storage::disk($disk)->path($filename)); //works for PRIVATE or public?!
|
return response()->download(Storage::disk($disk)->path($filename)); //works for PRIVATE or public?!
|
||||||
|
|
||||||
|
@ -20,4 +22,4 @@ class StorageHelper
|
||||||
return Storage::disk($disk)->download($filename);
|
return Storage::disk($disk)->download($filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Accessories;
|
namespace App\Http\Controllers\Accessories;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
@ -30,10 +31,10 @@ class AccessoriesController extends Controller
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$this->authorize('index', Accessory::class);
|
$this->authorize('index', Accessory::class);
|
||||||
|
|
||||||
return view('accessories/index');
|
return view('accessories/index');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view with a form to create a new Accessory.
|
* Returns a view with a form to create a new Accessory.
|
||||||
*
|
*
|
||||||
|
@ -45,11 +46,11 @@ class AccessoriesController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('create', Accessory::class);
|
$this->authorize('create', Accessory::class);
|
||||||
$category_type = 'accessory';
|
$category_type = 'accessory';
|
||||||
|
|
||||||
return view('accessories/edit')->with('category_type', $category_type)
|
return view('accessories/edit')->with('category_type', $category_type)
|
||||||
->with('item', new Accessory);
|
->with('item', new Accessory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate and save new Accessory from form post
|
* Validate and save new Accessory from form post
|
||||||
*
|
*
|
||||||
|
@ -74,18 +75,19 @@ class AccessoriesController extends Controller
|
||||||
$accessory->manufacturer_id = request('manufacturer_id');
|
$accessory->manufacturer_id = request('manufacturer_id');
|
||||||
$accessory->model_number = request('model_number');
|
$accessory->model_number = request('model_number');
|
||||||
$accessory->purchase_date = request('purchase_date');
|
$accessory->purchase_date = request('purchase_date');
|
||||||
$accessory->purchase_cost = Helper::ParseFloat(request('purchase_cost'));
|
$accessory->purchase_cost = Helper::ParseCurrency(request('purchase_cost'));
|
||||||
$accessory->qty = request('qty');
|
$accessory->qty = request('qty');
|
||||||
$accessory->user_id = Auth::user()->id;
|
$accessory->user_id = Auth::user()->id;
|
||||||
$accessory->supplier_id = request('supplier_id');
|
$accessory->supplier_id = request('supplier_id');
|
||||||
|
|
||||||
$accessory = $request->handleImages($accessory);
|
$accessory = $request->handleImages($accessory);
|
||||||
|
|
||||||
// Was the accessory created?
|
// Was the accessory created?
|
||||||
if ($accessory->save()) {
|
if ($accessory->save()) {
|
||||||
// Redirect to the new accessory page
|
// Redirect to the new accessory page
|
||||||
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.create.success'));
|
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.create.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()->withInput()->withErrors($accessory->getErrors());
|
return redirect()->back()->withInput()->withErrors($accessory->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +104,7 @@ class AccessoriesController extends Controller
|
||||||
|
|
||||||
if ($item = Accessory::find($accessoryId)) {
|
if ($item = Accessory::find($accessoryId)) {
|
||||||
$this->authorize($item);
|
$this->authorize($item);
|
||||||
|
|
||||||
return view('accessories/edit', compact('item'))->with('category_type', 'accessory');
|
return view('accessories/edit', compact('item'))->with('category_type', 'accessory');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,7 +140,7 @@ class AccessoriesController extends Controller
|
||||||
$accessory->order_number = request('order_number');
|
$accessory->order_number = request('order_number');
|
||||||
$accessory->model_number = request('model_number');
|
$accessory->model_number = request('model_number');
|
||||||
$accessory->purchase_date = request('purchase_date');
|
$accessory->purchase_date = request('purchase_date');
|
||||||
$accessory->purchase_cost = request('purchase_cost');
|
$accessory->purchase_cost = Helper::ParseCurrency(request('purchase_cost'));
|
||||||
$accessory->qty = request('qty');
|
$accessory->qty = request('qty');
|
||||||
$accessory->supplier_id = request('supplier_id');
|
$accessory->supplier_id = request('supplier_id');
|
||||||
|
|
||||||
|
@ -147,6 +150,7 @@ class AccessoriesController extends Controller
|
||||||
if ($accessory->save()) {
|
if ($accessory->save()) {
|
||||||
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.update.success'));
|
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.update.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()->withInput()->withErrors($accessory->getErrors());
|
return redirect()->back()->withInput()->withErrors($accessory->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,11 +172,11 @@ class AccessoriesController extends Controller
|
||||||
|
|
||||||
|
|
||||||
if ($accessory->hasUsers() > 0) {
|
if ($accessory->hasUsers() > 0) {
|
||||||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.assoc_users', array('count'=> $accessory->hasUsers())));
|
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.assoc_users', ['count'=> $accessory->hasUsers()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($accessory->image) {
|
if ($accessory->image) {
|
||||||
try {
|
try {
|
||||||
Storage::disk('public')->delete('accessories'.'/'.$accessory->image);
|
Storage::disk('public')->delete('accessories'.'/'.$accessory->image);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::debug($e);
|
\Log::debug($e);
|
||||||
|
@ -180,6 +184,7 @@ class AccessoriesController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$accessory->delete();
|
$accessory->delete();
|
||||||
|
|
||||||
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.delete.success'));
|
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.delete.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,6 +207,7 @@ class AccessoriesController extends Controller
|
||||||
if (isset($accessory->id)) {
|
if (isset($accessory->id)) {
|
||||||
return view('accessories/view', compact('accessory'));
|
return view('accessories/view', compact('accessory'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist', ['id' => $accessoryID]));
|
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist', ['id' => $accessoryID]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ class AccessoryCheckinController extends Controller
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param integer $accessoryUserId
|
* @param int $accessoryUserId
|
||||||
* @param string $backto
|
* @param string $backto
|
||||||
* @return View
|
* @return View
|
||||||
* @internal param int $accessoryId
|
* @internal param int $accessoryId
|
||||||
|
@ -33,6 +33,7 @@ class AccessoryCheckinController extends Controller
|
||||||
|
|
||||||
$accessory = Accessory::find($accessory_user->accessory_id);
|
$accessory = Accessory::find($accessory_user->accessory_id);
|
||||||
$this->authorize('checkin', $accessory);
|
$this->authorize('checkin', $accessory);
|
||||||
|
|
||||||
return view('accessories/checkin', compact('accessory'))->with('backto', $backto);
|
return view('accessories/checkin', compact('accessory'))->with('backto', $backto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ class AccessoryCheckinController extends Controller
|
||||||
*/
|
*/
|
||||||
public function store(Request $request, $accessoryUserId = null, $backto = null)
|
public function store(Request $request, $accessoryUserId = null, $backto = null)
|
||||||
{
|
{
|
||||||
// Check if the accessory exists
|
// Check if the accessory exists
|
||||||
if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) {
|
if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) {
|
||||||
// Redirect to the accessory management page with error
|
// Redirect to the accessory management page with error
|
||||||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
|
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist'));
|
||||||
|
@ -60,7 +61,7 @@ class AccessoryCheckinController extends Controller
|
||||||
$this->authorize('checkin', $accessory);
|
$this->authorize('checkin', $accessory);
|
||||||
|
|
||||||
$checkin_at = date('Y-m-d');
|
$checkin_at = date('Y-m-d');
|
||||||
if($request->filled('checkin_at')){
|
if ($request->filled('checkin_at')) {
|
||||||
$checkin_at = $request->input('checkin_at');
|
$checkin_at = $request->input('checkin_at');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ class AccessoryCheckinController extends Controller
|
||||||
|
|
||||||
event(new CheckoutableCheckedIn($accessory, User::find($return_to), Auth::user(), $request->input('note'), $checkin_at));
|
event(new CheckoutableCheckedIn($accessory, User::find($return_to), Auth::user(), $request->input('note'), $checkin_at));
|
||||||
|
|
||||||
return redirect()->route("accessories.show", $accessory->id)->with('success', trans('admin/accessories/message.checkin.success'));
|
return redirect()->route('accessories.show', $accessory->id)->with('success', trans('admin/accessories/message.checkin.success'));
|
||||||
}
|
}
|
||||||
// Redirect to the accessory management page with error
|
// Redirect to the accessory management page with error
|
||||||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.checkin.error'));
|
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.checkin.error'));
|
||||||
|
|
|
@ -14,7 +14,6 @@ use Illuminate\Support\Facades\Input;
|
||||||
|
|
||||||
class AccessoryCheckoutController extends Controller
|
class AccessoryCheckoutController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the form to checkout an Accessory to a user.
|
* Return the form to checkout an Accessory to a user.
|
||||||
*
|
*
|
||||||
|
@ -32,7 +31,6 @@ class AccessoryCheckoutController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($accessory->category) {
|
if ($accessory->category) {
|
||||||
|
|
||||||
$this->authorize('checkout', $accessory);
|
$this->authorize('checkout', $accessory);
|
||||||
|
|
||||||
// Get the dropdown of users and then pass it to the checkout view
|
// Get the dropdown of users and then pass it to the checkout view
|
||||||
|
@ -56,7 +54,7 @@ class AccessoryCheckoutController extends Controller
|
||||||
*/
|
*/
|
||||||
public function store(Request $request, $accessoryId)
|
public function store(Request $request, $accessoryId)
|
||||||
{
|
{
|
||||||
// Check if the accessory exists
|
// Check if the accessory exists
|
||||||
if (is_null($accessory = Accessory::find($accessoryId))) {
|
if (is_null($accessory = Accessory::find($accessoryId))) {
|
||||||
// Redirect to the accessory management page with error
|
// Redirect to the accessory management page with error
|
||||||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.user_not_found'));
|
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.user_not_found'));
|
||||||
|
@ -64,11 +62,11 @@ class AccessoryCheckoutController extends Controller
|
||||||
|
|
||||||
$this->authorize('checkout', $accessory);
|
$this->authorize('checkout', $accessory);
|
||||||
|
|
||||||
if (!$user = User::find($request->input('assigned_to'))) {
|
if (! $user = User::find($request->input('assigned_to'))) {
|
||||||
return redirect()->route('checkout/accessory', $accessory->id)->with('error', trans('admin/accessories/message.checkout.user_does_not_exist'));
|
return redirect()->route('checkout/accessory', $accessory->id)->with('error', trans('admin/accessories/message.checkout.user_does_not_exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the accessory data
|
// Update the accessory data
|
||||||
$accessory->assigned_to = e($request->input('assigned_to'));
|
$accessory->assigned_to = e($request->input('assigned_to'));
|
||||||
|
|
||||||
$accessory->users()->attach($accessory->id, [
|
$accessory->users()->attach($accessory->id, [
|
||||||
|
@ -76,14 +74,14 @@ class AccessoryCheckoutController extends Controller
|
||||||
'created_at' => Carbon::now(),
|
'created_at' => Carbon::now(),
|
||||||
'user_id' => Auth::id(),
|
'user_id' => Auth::id(),
|
||||||
'assigned_to' => $request->get('assigned_to'),
|
'assigned_to' => $request->get('assigned_to'),
|
||||||
'note' => $request->input('note')
|
'note' => $request->input('note'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
DB::table('accessories_users')->where('assigned_to', '=', $accessory->assigned_to)->where('accessory_id', '=', $accessory->id)->first();
|
DB::table('accessories_users')->where('assigned_to', '=', $accessory->assigned_to)->where('accessory_id', '=', $accessory->id)->first();
|
||||||
|
|
||||||
event(new CheckoutableCheckedOut($accessory, $user, Auth::user(), $request->input('note')));
|
event(new CheckoutableCheckedOut($accessory, $user, Auth::user(), $request->input('note')));
|
||||||
|
|
||||||
// Redirect to the new accessory page
|
// Redirect to the new accessory page
|
||||||
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.checkout.success'));
|
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.checkout.success'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Account;
|
namespace App\Http\Controllers\Account;
|
||||||
|
|
||||||
use App\Events\CheckoutAccepted;
|
use App\Events\CheckoutAccepted;
|
||||||
|
@ -14,14 +15,15 @@ use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class AcceptanceController extends Controller {
|
class AcceptanceController extends Controller
|
||||||
|
{
|
||||||
/**
|
/**
|
||||||
* Show a listing of pending checkout acceptances for the current user
|
* Show a listing of pending checkout acceptances for the current user
|
||||||
*
|
*
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function index() {
|
public function index()
|
||||||
|
{
|
||||||
$acceptances = CheckoutAcceptance::forUser(Auth::user())->pending()->get();
|
$acceptances = CheckoutAcceptance::forUser(Auth::user())->pending()->get();
|
||||||
|
|
||||||
return view('account/accept.index', compact('acceptances'));
|
return view('account/accept.index', compact('acceptances'));
|
||||||
|
@ -29,12 +31,12 @@ class AcceptanceController extends Controller {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows a form to either accept or decline the checkout acceptance
|
* Shows a form to either accept or decline the checkout acceptance
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function create($id) {
|
public function create($id)
|
||||||
|
{
|
||||||
$acceptance = CheckoutAcceptance::find($id);
|
$acceptance = CheckoutAcceptance::find($id);
|
||||||
|
|
||||||
if (is_null($acceptance)) {
|
if (is_null($acceptance)) {
|
||||||
|
@ -43,28 +45,28 @@ class AcceptanceController extends Controller {
|
||||||
|
|
||||||
if (! $acceptance->isPending()) {
|
if (! $acceptance->isPending()) {
|
||||||
return redirect()->route('account.accept')->with('error', trans('admin/users/message.error.asset_already_accepted'));
|
return redirect()->route('account.accept')->with('error', trans('admin/users/message.error.asset_already_accepted'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $acceptance->isCheckedOutTo(Auth::user())) {
|
if (! $acceptance->isCheckedOutTo(Auth::user())) {
|
||||||
return redirect()->route('account.accept')->with('error', trans('admin/users/message.error.incorrect_user_accepted'));
|
return redirect()->route('account.accept')->with('error', trans('admin/users/message.error.incorrect_user_accepted'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Company::isCurrentUserHasAccess($acceptance->checkoutable)) {
|
if (! Company::isCurrentUserHasAccess($acceptance->checkoutable)) {
|
||||||
return redirect()->route('account.accept')->with('error', trans('general.insufficient_permissions'));
|
return redirect()->route('account.accept')->with('error', trans('general.insufficient_permissions'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('account/accept.create', compact('acceptance'));
|
return view('account/accept.create', compact('acceptance'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores the accept/decline of the checkout acceptance
|
* Stores the accept/decline of the checkout acceptance
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return Redirect
|
* @return Redirect
|
||||||
*/
|
*/
|
||||||
public function store(Request $request, $id) {
|
public function store(Request $request, $id)
|
||||||
|
{
|
||||||
$acceptance = CheckoutAcceptance::find($id);
|
$acceptance = CheckoutAcceptance::find($id);
|
||||||
|
|
||||||
if (is_null($acceptance)) {
|
if (is_null($acceptance)) {
|
||||||
|
@ -73,55 +75,50 @@ class AcceptanceController extends Controller {
|
||||||
|
|
||||||
if (! $acceptance->isPending()) {
|
if (! $acceptance->isPending()) {
|
||||||
return redirect()->route('account.accept')->with('error', trans('admin/users/message.error.asset_already_accepted'));
|
return redirect()->route('account.accept')->with('error', trans('admin/users/message.error.asset_already_accepted'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $acceptance->isCheckedOutTo(Auth::user())) {
|
if (! $acceptance->isCheckedOutTo(Auth::user())) {
|
||||||
return redirect()->route('account.accept')->with('error', trans('admin/users/message.error.incorrect_user_accepted'));
|
return redirect()->route('account.accept')->with('error', trans('admin/users/message.error.incorrect_user_accepted'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Company::isCurrentUserHasAccess($acceptance->checkoutable)) {
|
if (! Company::isCurrentUserHasAccess($acceptance->checkoutable)) {
|
||||||
return redirect()->route('account.accept')->with('error', trans('general.insufficient_permissions'));
|
return redirect()->route('account.accept')->with('error', trans('general.insufficient_permissions'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$request->filled('asset_acceptance')) {
|
if (! $request->filled('asset_acceptance')) {
|
||||||
return redirect()->back()->with('error', trans('admin/users/message.error.accept_or_decline'));
|
return redirect()->back()->with('error', trans('admin/users/message.error.accept_or_decline'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the signature and save it
|
* Get the signature and save it
|
||||||
*/
|
*/
|
||||||
|
if (! Storage::exists('private_uploads/signatures')) {
|
||||||
if (!Storage::exists('private_uploads/signatures')) Storage::makeDirectory('private_uploads/signatures', 775);
|
Storage::makeDirectory('private_uploads/signatures', 775);
|
||||||
|
}
|
||||||
|
|
||||||
$sig_filename = '';
|
$sig_filename = '';
|
||||||
if ($request->filled('signature_output')) {
|
if ($request->filled('signature_output')) {
|
||||||
$sig_filename = "siglog-" .Str::uuid() . '-'.date('Y-m-d-his').".png";
|
$sig_filename = 'siglog-'.Str::uuid().'-'.date('Y-m-d-his').'.png';
|
||||||
$data_uri = e($request->input('signature_output'));
|
$data_uri = e($request->input('signature_output'));
|
||||||
$encoded_image = explode(",", $data_uri);
|
$encoded_image = explode(',', $data_uri);
|
||||||
$decoded_image = base64_decode($encoded_image[1]);
|
$decoded_image = base64_decode($encoded_image[1]);
|
||||||
Storage::put('private_uploads/signatures/'.$sig_filename, (string)$decoded_image);
|
Storage::put('private_uploads/signatures/'.$sig_filename, (string) $decoded_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($request->input('asset_acceptance') == 'accepted') {
|
if ($request->input('asset_acceptance') == 'accepted') {
|
||||||
|
|
||||||
$acceptance->accept($sig_filename);
|
$acceptance->accept($sig_filename);
|
||||||
|
|
||||||
event(new CheckoutAccepted($acceptance));
|
event(new CheckoutAccepted($acceptance));
|
||||||
|
|
||||||
$return_msg = trans('admin/users/message.accepted');
|
$return_msg = trans('admin/users/message.accepted');
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
$acceptance->decline($sig_filename);
|
||||||
$acceptance->decline($sig_filename);
|
|
||||||
|
|
||||||
event(new CheckoutDeclined($acceptance));
|
event(new CheckoutDeclined($acceptance));
|
||||||
|
|
||||||
$return_msg = trans('admin/users/message.declined');
|
$return_msg = trans('admin/users/message.declined');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->to('account/accept')->with('success', $return_msg);
|
return redirect()->to('account/accept')->with('success', $return_msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,9 +10,10 @@ class ActionlogController extends Controller
|
||||||
public function displaySig($filename)
|
public function displaySig($filename)
|
||||||
{
|
{
|
||||||
$this->authorize('view', \App\Models\Asset::class);
|
$this->authorize('view', \App\Models\Asset::class);
|
||||||
$file = config('app.private_uploads') . '/signatures/' . $filename;
|
$file = config('app.private_uploads').'/signatures/'.$filename;
|
||||||
$filetype = Helper::checkUploadIsImage($file);
|
$filetype = Helper::checkUploadIsImage($file);
|
||||||
$contents = file_get_contents($file);
|
$contents = file_get_contents($file);
|
||||||
|
|
||||||
return Response::make($contents)->header('Content-Type', $filetype);
|
return Response::make($contents)->header('Content-Type', $filetype);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ use App\Http\Transformers\SelectlistTransformer;
|
||||||
use App\Models\Accessory;
|
use App\Models\Accessory;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Carbon\Carbon;
|
|
||||||
use Auth;
|
use Auth;
|
||||||
|
use Carbon\Carbon;
|
||||||
use DB;
|
use DB;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Http\Requests\ImageUploadRequest;
|
use App\Http\Requests\ImageUploadRequest;
|
||||||
|
@ -27,28 +27,43 @@ class AccessoriesController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('view', Accessory::class);
|
$this->authorize('view', Accessory::class);
|
||||||
$allowed_columns = ['id','name','model_number','eol','notes','created_at','min_amt','company_id'];
|
$allowed_columns = ['id', 'name', 'model_number', 'eol', 'notes', 'created_at', 'min_amt', 'company_id'];
|
||||||
|
|
||||||
|
// This array is what determines which fields should be allowed to be sorted on ON the table itself, no relations
|
||||||
|
// Relations will be handled in query scopes a little further down.
|
||||||
|
$allowed_columns =
|
||||||
|
[
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'model_number',
|
||||||
|
'eol',
|
||||||
|
'notes',
|
||||||
|
'created_at',
|
||||||
|
'min_amt',
|
||||||
|
'company_id'
|
||||||
|
];
|
||||||
|
|
||||||
$accessories = Accessory::with('category', 'company', 'manufacturer', 'users', 'location');
|
|
||||||
|
$accessories = Accessory::select('accessories.*')->with('category', 'company', 'manufacturer', 'users', 'location', 'supplier');
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
$accessories = $accessories->TextSearch($request->input('search'));
|
$accessories = $accessories->TextSearch($request->input('search'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('company_id')) {
|
if ($request->filled('company_id')) {
|
||||||
$accessories->where('company_id','=',$request->input('company_id'));
|
$accessories->where('company_id', '=', $request->input('company_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('category_id')) {
|
if ($request->filled('category_id')) {
|
||||||
$accessories->where('category_id','=',$request->input('category_id'));
|
$accessories->where('category_id', '=', $request->input('category_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('manufacturer_id')) {
|
if ($request->filled('manufacturer_id')) {
|
||||||
$accessories->where('manufacturer_id','=',$request->input('manufacturer_id'));
|
$accessories->where('manufacturer_id', '=', $request->input('manufacturer_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('supplier_id')) {
|
if ($request->filled('supplier_id')) {
|
||||||
$accessories->where('supplier_id','=',$request->input('supplier_id'));
|
$accessories->where('supplier_id', '=', $request->input('supplier_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('location_id')) {
|
if ($request->filled('location_id')) {
|
||||||
|
@ -62,26 +77,34 @@ class AccessoriesController extends Controller
|
||||||
// Check to make sure the limit is not higher than the max allowed
|
// Check to make sure the limit is not higher than the max allowed
|
||||||
((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results');
|
((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results');
|
||||||
|
|
||||||
|
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||||
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
|
$sort_override = $request->input('sort');
|
||||||
|
$column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'created_at';
|
||||||
|
|
||||||
switch ($sort) {
|
switch ($sort_override) {
|
||||||
case 'category':
|
case 'category':
|
||||||
$accessories = $accessories->OrderCategory($order);
|
$accessories = $accessories->OrderCategory($order);
|
||||||
break;
|
break;
|
||||||
case 'company':
|
case 'company':
|
||||||
$accessories = $accessories->OrderCompany($order);
|
$accessories = $accessories->OrderCompany($order);
|
||||||
break;
|
break;
|
||||||
|
case 'location':
|
||||||
|
$accessories = $accessories->OrderLocation($order);
|
||||||
|
break;
|
||||||
|
case 'manufacturer':
|
||||||
|
$accessories = $accessories->OrderManufacturer($order);
|
||||||
|
break;
|
||||||
|
case 'supplier':
|
||||||
|
$accessories = $accessories->OrderSupplier($order);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
$accessories = $accessories->orderBy($sort, $order);
|
$accessories = $accessories->orderBy($column_sort, $order);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$accessories->orderBy($sort, $order);
|
|
||||||
|
|
||||||
$total = $accessories->count();
|
$total = $accessories->count();
|
||||||
$accessories = $accessories->skip($offset)->take($limit)->get();
|
$accessories = $accessories->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new AccessoriesTransformer)->transformAccessories($accessories, $total);
|
return (new AccessoriesTransformer)->transformAccessories($accessories, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +127,7 @@ class AccessoriesController extends Controller
|
||||||
if ($accessory->save()) {
|
if ($accessory->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $accessory, trans('admin/accessories/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $accessory, trans('admin/accessories/message.create.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $accessory->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $accessory->getErrors()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -120,6 +144,7 @@ class AccessoriesController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Accessory::class);
|
$this->authorize('view', Accessory::class);
|
||||||
$accessory = Accessory::findOrFail($id);
|
$accessory = Accessory::findOrFail($id);
|
||||||
|
|
||||||
return (new AccessoriesTransformer)->transformAccessory($accessory);
|
return (new AccessoriesTransformer)->transformAccessory($accessory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,6 +161,7 @@ class AccessoriesController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Accessory::class);
|
$this->authorize('view', Accessory::class);
|
||||||
$accessory = Accessory::findOrFail($id);
|
$accessory = Accessory::findOrFail($id);
|
||||||
|
|
||||||
return (new AccessoriesTransformer)->transformAccessory($accessory);
|
return (new AccessoriesTransformer)->transformAccessory($accessory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +179,7 @@ class AccessoriesController extends Controller
|
||||||
$this->authorize('view', Accessory::class);
|
$this->authorize('view', Accessory::class);
|
||||||
|
|
||||||
$accessory = Accessory::with('lastCheckout')->findOrFail($id);
|
$accessory = Accessory::with('lastCheckout')->findOrFail($id);
|
||||||
if (!Company::isCurrentUserHasAccess($accessory)) {
|
if (! Company::isCurrentUserHasAccess($accessory)) {
|
||||||
return ['total' => 0, 'rows' => []];
|
return ['total' => 0, 'rows' => []];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +189,7 @@ class AccessoriesController extends Controller
|
||||||
$accessory_users = $accessory->users;
|
$accessory_users = $accessory->users;
|
||||||
$total = $accessory_users->count();
|
$total = $accessory_users->count();
|
||||||
|
|
||||||
if($total < $offset){
|
if ($total < $offset) {
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,12 +249,12 @@ class AccessoriesController extends Controller
|
||||||
$this->authorize($accessory);
|
$this->authorize($accessory);
|
||||||
|
|
||||||
if ($accessory->hasUsers() > 0) {
|
if ($accessory->hasUsers() > 0) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/accessories/message.assoc_users', array('count'=> $accessory->hasUsers()))));
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/accessories/message.assoc_users', ['count'=> $accessory->hasUsers()])));
|
||||||
}
|
}
|
||||||
|
|
||||||
$accessory->delete();
|
$accessory->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/accessories/message.delete.success')));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/accessories/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -254,7 +280,7 @@ class AccessoriesController extends Controller
|
||||||
|
|
||||||
if ($accessory->numRemaining() > 0) {
|
if ($accessory->numRemaining() > 0) {
|
||||||
|
|
||||||
if (!$user = User::find($request->input('assigned_to'))) {
|
if (! $user = User::find($request->input('assigned_to'))) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/accessories/message.checkout.user_does_not_exist')));
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/accessories/message.checkout.user_does_not_exist')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,12 +292,12 @@ class AccessoriesController extends Controller
|
||||||
'created_at' => Carbon::now(),
|
'created_at' => Carbon::now(),
|
||||||
'user_id' => Auth::id(),
|
'user_id' => Auth::id(),
|
||||||
'assigned_to' => $request->get('assigned_to'),
|
'assigned_to' => $request->get('assigned_to'),
|
||||||
'note' => $request->get('note')
|
'note' => $request->get('note'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$accessory->logCheckout($request->input('note'), $user);
|
$accessory->logCheckout($request->input('note'), $user);
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/accessories/message.checkout.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/accessories/message.checkout.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'No accessories remaining'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'No accessories remaining'));
|
||||||
|
@ -284,7 +310,7 @@ class AccessoriesController extends Controller
|
||||||
* @uses Accessory::checkin_email() to determine if an email can and should be sent
|
* @uses Accessory::checkin_email() to determine if an email can and should be sent
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
* @param integer $accessoryUserId
|
* @param int $accessoryUserId
|
||||||
* @param string $backto
|
* @param string $backto
|
||||||
* @return Redirect
|
* @return Redirect
|
||||||
* @internal param int $accessoryId
|
* @internal param int $accessoryId
|
||||||
|
@ -302,7 +328,7 @@ class AccessoriesController extends Controller
|
||||||
|
|
||||||
// Was the accessory updated?
|
// Was the accessory updated?
|
||||||
if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) {
|
if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) {
|
||||||
if (!is_null($accessory_user->assigned_to)) {
|
if (! is_null($accessory_user->assigned_to)) {
|
||||||
$user = User::find($accessory_user->assigned_to);
|
$user = User::find($accessory_user->assigned_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -317,7 +343,7 @@ class AccessoriesController extends Controller
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/accessories/message.checkin.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/accessories/message.checkin.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/accessories/message.checkin.error')));
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/accessories/message.checkin.error')));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +359,7 @@ class AccessoriesController extends Controller
|
||||||
|
|
||||||
$accessories = Accessory::select([
|
$accessories = Accessory::select([
|
||||||
'accessories.id',
|
'accessories.id',
|
||||||
'accessories.name'
|
'accessories.name',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
|
@ -342,10 +368,7 @@ class AccessoriesController extends Controller
|
||||||
|
|
||||||
$accessories = $accessories->orderBy('name', 'ASC')->paginate(50);
|
$accessories = $accessories->orderBy('name', 'ASC')->paginate(50);
|
||||||
|
|
||||||
|
|
||||||
return (new SelectlistTransformer)->transformSelectlist($accessories);
|
return (new SelectlistTransformer)->transformSelectlist($accessories);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
@ -29,11 +30,11 @@ class AssetMaintenancesController extends Controller
|
||||||
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
||||||
* @version v1.0
|
* @version v1.0
|
||||||
* @since [v1.8]
|
* @since [v1.8]
|
||||||
* @return String JSON
|
* @return string JSON
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$maintenances = AssetMaintenance::with('asset', 'asset.model','asset.location', 'supplier', 'asset.company', 'admin');
|
$maintenances = AssetMaintenance::with('asset', 'asset.model', 'asset.location', 'supplier', 'asset.company', 'admin');
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
$maintenances = $maintenances->TextSearch($request->input('search'));
|
$maintenances = $maintenances->TextSearch($request->input('search'));
|
||||||
|
@ -50,7 +51,6 @@ class AssetMaintenancesController extends Controller
|
||||||
// Check to make sure the limit is not higher than the max allowed
|
// Check to make sure the limit is not higher than the max allowed
|
||||||
((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results');
|
((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results');
|
||||||
|
|
||||||
|
|
||||||
$allowed_columns = [
|
$allowed_columns = [
|
||||||
'id',
|
'id',
|
||||||
'title',
|
'title',
|
||||||
|
@ -62,7 +62,7 @@ class AssetMaintenancesController extends Controller
|
||||||
'notes',
|
'notes',
|
||||||
'asset_tag',
|
'asset_tag',
|
||||||
'asset_name',
|
'asset_name',
|
||||||
'user_id'
|
'user_id',
|
||||||
];
|
];
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||||
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
||||||
|
@ -97,7 +97,7 @@ class AssetMaintenancesController extends Controller
|
||||||
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
* @author Vincent Sposato <vincent.sposato@gmail.com>
|
||||||
* @version v1.0
|
* @version v1.0
|
||||||
* @since [v1.8]
|
* @since [v1.8]
|
||||||
* @return String JSON
|
* @return string JSON
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
|
@ -105,28 +105,28 @@ class AssetMaintenancesController extends Controller
|
||||||
$assetMaintenance = new AssetMaintenance();
|
$assetMaintenance = new AssetMaintenance();
|
||||||
$assetMaintenance->supplier_id = $request->input('supplier_id');
|
$assetMaintenance->supplier_id = $request->input('supplier_id');
|
||||||
$assetMaintenance->is_warranty = $request->input('is_warranty');
|
$assetMaintenance->is_warranty = $request->input('is_warranty');
|
||||||
$assetMaintenance->cost = e($request->input('cost'));
|
$assetMaintenance->cost = Helper::ParseCurrency($request->input('cost'));
|
||||||
$assetMaintenance->notes = e($request->input('notes'));
|
$assetMaintenance->notes = e($request->input('notes'));
|
||||||
$asset = Asset::find(e($request->input('asset_id')));
|
$asset = Asset::find(e($request->input('asset_id')));
|
||||||
|
|
||||||
if (!Company::isCurrentUserHasAccess($asset)) {
|
if (! Company::isCurrentUserHasAccess($asset)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot add a maintenance for that asset'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot add a maintenance for that asset'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the asset maintenance data
|
// Save the asset maintenance data
|
||||||
$assetMaintenance->asset_id = $request->input('asset_id');
|
$assetMaintenance->asset_id = $request->input('asset_id');
|
||||||
$assetMaintenance->asset_maintenance_type = $request->input('asset_maintenance_type');
|
$assetMaintenance->asset_maintenance_type = $request->input('asset_maintenance_type');
|
||||||
$assetMaintenance->title = $request->input('title');
|
$assetMaintenance->title = $request->input('title');
|
||||||
$assetMaintenance->start_date = $request->input('start_date');
|
$assetMaintenance->start_date = $request->input('start_date');
|
||||||
$assetMaintenance->completion_date = $request->input('completion_date');
|
$assetMaintenance->completion_date = $request->input('completion_date');
|
||||||
$assetMaintenance->user_id = Auth::id();
|
$assetMaintenance->user_id = Auth::id();
|
||||||
|
|
||||||
if (( $assetMaintenance->completion_date !== null )
|
if (($assetMaintenance->completion_date !== null)
|
||||||
&& ( $assetMaintenance->start_date !== "" )
|
&& ($assetMaintenance->start_date !== '')
|
||||||
&& ( $assetMaintenance->start_date !== "0000-00-00" )
|
&& ($assetMaintenance->start_date !== '0000-00-00')
|
||||||
) {
|
) {
|
||||||
$startDate = Carbon::parse($assetMaintenance->start_date);
|
$startDate = Carbon::parse($assetMaintenance->start_date);
|
||||||
$completionDate = Carbon::parse($assetMaintenance->completion_date);
|
$completionDate = Carbon::parse($assetMaintenance->completion_date);
|
||||||
$assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
|
$assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +140,6 @@ class AssetMaintenancesController extends Controller
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates and stores an update to an asset maintenance
|
* Validates and stores an update to an asset maintenance
|
||||||
*
|
*
|
||||||
|
@ -149,59 +148,59 @@ class AssetMaintenancesController extends Controller
|
||||||
* @param int $request
|
* @param int $request
|
||||||
* @version v1.0
|
* @version v1.0
|
||||||
* @since [v4.0]
|
* @since [v4.0]
|
||||||
* @return String JSON
|
* @return string JSON
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, $assetMaintenanceId = null)
|
public function update(Request $request, $assetMaintenanceId = null)
|
||||||
{
|
{
|
||||||
// Check if the asset maintenance exists
|
// Check if the asset maintenance exists
|
||||||
$assetMaintenance = AssetMaintenance::findOrFail($assetMaintenanceId);
|
$assetMaintenance = AssetMaintenance::findOrFail($assetMaintenanceId);
|
||||||
|
|
||||||
if (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
if (! Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot edit a maintenance for that asset'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot edit a maintenance for that asset'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$assetMaintenance->supplier_id = e($request->input('supplier_id'));
|
$assetMaintenance->supplier_id = e($request->input('supplier_id'));
|
||||||
$assetMaintenance->is_warranty = e($request->input('is_warranty'));
|
$assetMaintenance->is_warranty = e($request->input('is_warranty'));
|
||||||
$assetMaintenance->cost = Helper::ParseFloat(e($request->input('cost')));
|
$assetMaintenance->cost = Helper::ParseCurrency($request->input('cost'));
|
||||||
$assetMaintenance->notes = e($request->input('notes'));
|
$assetMaintenance->notes = e($request->input('notes'));
|
||||||
|
|
||||||
$asset = Asset::find(request('asset_id'));
|
$asset = Asset::find(request('asset_id'));
|
||||||
|
|
||||||
if (!Company::isCurrentUserHasAccess($asset)) {
|
if (! Company::isCurrentUserHasAccess($asset)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot edit a maintenance for that asset'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot edit a maintenance for that asset'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the asset maintenance data
|
// Save the asset maintenance data
|
||||||
$assetMaintenance->asset_id = $request->input('asset_id');
|
$assetMaintenance->asset_id = $request->input('asset_id');
|
||||||
$assetMaintenance->asset_maintenance_type = $request->input('asset_maintenance_type');
|
$assetMaintenance->asset_maintenance_type = $request->input('asset_maintenance_type');
|
||||||
$assetMaintenance->title = $request->input('title');
|
$assetMaintenance->title = $request->input('title');
|
||||||
$assetMaintenance->start_date = $request->input('start_date');
|
$assetMaintenance->start_date = $request->input('start_date');
|
||||||
$assetMaintenance->completion_date = $request->input('completion_date');
|
$assetMaintenance->completion_date = $request->input('completion_date');
|
||||||
|
|
||||||
if (( $assetMaintenance->completion_date == null )
|
if (($assetMaintenance->completion_date == null)
|
||||||
) {
|
) {
|
||||||
if (( $assetMaintenance->asset_maintenance_time !== 0 )
|
if (($assetMaintenance->asset_maintenance_time !== 0)
|
||||||
|| ( !is_null($assetMaintenance->asset_maintenance_time) )
|
|| (! is_null($assetMaintenance->asset_maintenance_time))
|
||||||
) {
|
) {
|
||||||
$assetMaintenance->asset_maintenance_time = null;
|
$assetMaintenance->asset_maintenance_time = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (( $assetMaintenance->completion_date !== null )
|
if (($assetMaintenance->completion_date !== null)
|
||||||
&& ( $assetMaintenance->start_date !== "" )
|
&& ($assetMaintenance->start_date !== '')
|
||||||
&& ( $assetMaintenance->start_date !== "0000-00-00" )
|
&& ($assetMaintenance->start_date !== '0000-00-00')
|
||||||
) {
|
) {
|
||||||
$startDate = Carbon::parse($assetMaintenance->start_date);
|
$startDate = Carbon::parse($assetMaintenance->start_date);
|
||||||
$completionDate = Carbon::parse($assetMaintenance->completion_date);
|
$completionDate = Carbon::parse($assetMaintenance->completion_date);
|
||||||
$assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
|
$assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Was the asset maintenance created?
|
// Was the asset maintenance created?
|
||||||
if ($assetMaintenance->save()) {
|
if ($assetMaintenance->save()) {
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $assetMaintenance, trans('admin/asset_maintenances/message.edit.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $assetMaintenance, trans('admin/asset_maintenances/message.edit.success')));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $assetMaintenance->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $assetMaintenance->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,14 +211,14 @@ class AssetMaintenancesController extends Controller
|
||||||
* @param int $assetMaintenanceId
|
* @param int $assetMaintenanceId
|
||||||
* @version v1.0
|
* @version v1.0
|
||||||
* @since [v4.0]
|
* @since [v4.0]
|
||||||
* @return String JSON
|
* @return string JSON
|
||||||
*/
|
*/
|
||||||
public function destroy($assetMaintenanceId)
|
public function destroy($assetMaintenanceId)
|
||||||
{
|
{
|
||||||
// Check if the asset maintenance exists
|
// Check if the asset maintenance exists
|
||||||
$assetMaintenance = AssetMaintenance::findOrFail($assetMaintenanceId);
|
$assetMaintenance = AssetMaintenance::findOrFail($assetMaintenanceId);
|
||||||
|
|
||||||
if (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
if (! Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot delete a maintenance for that asset'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot delete a maintenance for that asset'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,14 +236,15 @@ class AssetMaintenancesController extends Controller
|
||||||
* @param int $assetMaintenanceId
|
* @param int $assetMaintenanceId
|
||||||
* @version v1.0
|
* @version v1.0
|
||||||
* @since [v4.0]
|
* @since [v4.0]
|
||||||
* @return String JSON
|
* @return string JSON
|
||||||
*/
|
*/
|
||||||
public function show($assetMaintenanceId)
|
public function show($assetMaintenanceId)
|
||||||
{
|
{
|
||||||
$assetMaintenance = AssetMaintenance::findOrFail($assetMaintenanceId);
|
$assetMaintenance = AssetMaintenance::findOrFail($assetMaintenanceId);
|
||||||
if (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
if (! Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot view a maintenance for that asset'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'You cannot view a maintenance for that asset'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new AssetMaintenancesTransformer())->transformAssetMaintenance($assetMaintenance);
|
return (new AssetMaintenancesTransformer())->transformAssetMaintenance($assetMaintenance);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
@ -43,7 +44,7 @@ class AssetModelsController extends Controller
|
||||||
'manufacturer',
|
'manufacturer',
|
||||||
'requestable',
|
'requestable',
|
||||||
'assets_count',
|
'assets_count',
|
||||||
'category'
|
'category',
|
||||||
];
|
];
|
||||||
|
|
||||||
$assetmodels = AssetModel::select([
|
$assetmodels = AssetModel::select([
|
||||||
|
@ -62,12 +63,10 @@ class AssetModelsController extends Controller
|
||||||
'models.deleted_at',
|
'models.deleted_at',
|
||||||
'models.updated_at',
|
'models.updated_at',
|
||||||
])
|
])
|
||||||
->with('category','depreciation', 'manufacturer','fieldset')
|
->with('category', 'depreciation', 'manufacturer', 'fieldset')
|
||||||
->withCount('assets as assets_count');
|
->withCount('assets as assets_count');
|
||||||
|
|
||||||
|
if ($request->input('status')=='deleted') {
|
||||||
|
|
||||||
if ($request->filled('status')) {
|
|
||||||
$assetmodels->onlyTrashed();
|
$assetmodels->onlyTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,6 +98,7 @@ class AssetModelsController extends Controller
|
||||||
|
|
||||||
$total = $assetmodels->count();
|
$total = $assetmodels->count();
|
||||||
$assetmodels = $assetmodels->skip($offset)->take($limit)->get();
|
$assetmodels = $assetmodels->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new AssetModelsTransformer)->transformAssetModels($assetmodels, $total);
|
return (new AssetModelsTransformer)->transformAssetModels($assetmodels, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +123,7 @@ class AssetModelsController extends Controller
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $assetmodel->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $assetmodel->getErrors()));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,6 +138,7 @@ class AssetModelsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', AssetModel::class);
|
$this->authorize('view', AssetModel::class);
|
||||||
$assetmodel = AssetModel::withCount('assets as assets_count')->findOrFail($id);
|
$assetmodel = AssetModel::withCount('assets as assets_count')->findOrFail($id);
|
||||||
|
|
||||||
return (new AssetModelsTransformer)->transformAssetModel($assetmodel);
|
return (new AssetModelsTransformer)->transformAssetModel($assetmodel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +153,8 @@ class AssetModelsController extends Controller
|
||||||
public function assets($id)
|
public function assets($id)
|
||||||
{
|
{
|
||||||
$this->authorize('view', AssetModel::class);
|
$this->authorize('view', AssetModel::class);
|
||||||
$assets = Asset::where('model_id','=',$id)->get();
|
$assets = Asset::where('model_id', '=', $id)->get();
|
||||||
|
|
||||||
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
|
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +184,7 @@ class AssetModelsController extends Controller
|
||||||
* it, but I'll be damned if I can think of one. - snipe
|
* it, but I'll be damned if I can think of one. - snipe
|
||||||
*/
|
*/
|
||||||
if ($request->filled('custom_fieldset_id')) {
|
if ($request->filled('custom_fieldset_id')) {
|
||||||
$assetmodel->fieldset_id = $request->get("custom_fieldset_id");
|
$assetmodel->fieldset_id = $request->get('custom_fieldset_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -207,11 +210,11 @@ class AssetModelsController extends Controller
|
||||||
$this->authorize('delete', $assetmodel);
|
$this->authorize('delete', $assetmodel);
|
||||||
|
|
||||||
if ($assetmodel->assets()->count() > 0) {
|
if ($assetmodel->assets()->count() > 0) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.assoc_users')));
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/models/message.assoc_users')));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($assetmodel->image) {
|
if ($assetmodel->image) {
|
||||||
try {
|
try {
|
||||||
Storage::disk('public')->delete('assetmodels/'.$assetmodel->image);
|
Storage::disk('public')->delete('assetmodels/'.$assetmodel->image);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::info($e);
|
\Log::info($e);
|
||||||
|
@ -219,8 +222,8 @@ class AssetModelsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$assetmodel->delete();
|
$assetmodel->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/models/message.delete.success')));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/models/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -229,11 +232,9 @@ class AssetModelsController extends Controller
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v4.0.16]
|
* @since [v4.0.16]
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function selectlist(Request $request)
|
public function selectlist(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$assetmodels = AssetModel::select([
|
$assetmodels = AssetModel::select([
|
||||||
'models.id',
|
'models.id',
|
||||||
'models.name',
|
'models.name',
|
||||||
|
@ -241,7 +242,7 @@ class AssetModelsController extends Controller
|
||||||
'models.model_number',
|
'models.model_number',
|
||||||
'models.manufacturer_id',
|
'models.manufacturer_id',
|
||||||
'models.category_id',
|
'models.category_id',
|
||||||
])->with('manufacturer','category');
|
])->with('manufacturer', 'category');
|
||||||
|
|
||||||
$settings = \App\Models\Setting::getSettings();
|
$settings = \App\Models\Setting::getSettings();
|
||||||
|
|
||||||
|
@ -252,7 +253,6 @@ class AssetModelsController extends Controller
|
||||||
$assetmodels = $assetmodels->OrderCategory('ASC')->OrderManufacturer('ASC')->orderby('models.name', 'asc')->orderby('models.model_number', 'asc')->paginate(50);
|
$assetmodels = $assetmodels->OrderCategory('ASC')->OrderManufacturer('ASC')->orderby('models.name', 'asc')->orderby('models.model_number', 'asc')->paginate(50);
|
||||||
|
|
||||||
foreach ($assetmodels as $assetmodel) {
|
foreach ($assetmodels as $assetmodel) {
|
||||||
|
|
||||||
$assetmodel->use_text = '';
|
$assetmodel->use_text = '';
|
||||||
|
|
||||||
if ($settings->modellistCheckedValue('category')) {
|
if ($settings->modellistCheckedValue('category')) {
|
||||||
|
@ -263,10 +263,10 @@ class AssetModelsController extends Controller
|
||||||
$assetmodel->use_text .= (($assetmodel->manufacturer) ? $assetmodel->manufacturer->name.' ' : '');
|
$assetmodel->use_text .= (($assetmodel->manufacturer) ? $assetmodel->manufacturer->name.' ' : '');
|
||||||
}
|
}
|
||||||
|
|
||||||
$assetmodel->use_text .= $assetmodel->name;
|
$assetmodel->use_text .= $assetmodel->name;
|
||||||
|
|
||||||
if (($settings->modellistCheckedValue('model_number')) && ($assetmodel->model_number!='')) {
|
if (($settings->modellistCheckedValue('model_number')) && ($assetmodel->model_number != '')) {
|
||||||
$assetmodel->use_text .= ' (#'.$assetmodel->model_number.')';
|
$assetmodel->use_text .= ' (#'.$assetmodel->model_number.')';
|
||||||
}
|
}
|
||||||
|
|
||||||
$assetmodel->use_image = ($settings->modellistCheckedValue('image') && ($assetmodel->image)) ? Storage::disk('public')->url('models/'.e($assetmodel->image)) : null;
|
$assetmodel->use_image = ($settings->modellistCheckedValue('image') && ($assetmodel->image)) ? Storage::disk('public')->url('models/'.e($assetmodel->image)) : null;
|
||||||
|
@ -274,5 +274,4 @@ class AssetModelsController extends Controller
|
||||||
|
|
||||||
return (new SelectlistTransformer)->transformSelectlist($assetmodels);
|
return (new SelectlistTransformer)->transformSelectlist($assetmodels);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use App\Events\CheckoutableCheckedIn;
|
use App\Events\CheckoutableCheckedIn;
|
||||||
|
@ -7,8 +8,10 @@ use App\Helpers\Helper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\AssetCheckoutRequest;
|
use App\Http\Requests\AssetCheckoutRequest;
|
||||||
use App\Http\Transformers\AssetsTransformer;
|
use App\Http\Transformers\AssetsTransformer;
|
||||||
|
use App\Http\Transformers\DepreciationReportTransformer;
|
||||||
use App\Http\Transformers\LicensesTransformer;
|
use App\Http\Transformers\LicensesTransformer;
|
||||||
use App\Http\Transformers\SelectlistTransformer;
|
use App\Http\Transformers\SelectlistTransformer;
|
||||||
|
use App\Models\Actionlog;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use App\Models\AssetModel;
|
use App\Models\AssetModel;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
|
@ -28,7 +31,7 @@ use Slack;
|
||||||
use Str;
|
use Str;
|
||||||
use TCPDF;
|
use TCPDF;
|
||||||
use Validator;
|
use Validator;
|
||||||
|
use Route;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class controls all actions related to assets for
|
* This class controls all actions related to assets for
|
||||||
|
@ -39,7 +42,6 @@ use Validator;
|
||||||
*/
|
*/
|
||||||
class AssetsController extends Controller
|
class AssetsController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns JSON listing of all assets
|
* Returns JSON listing of all assets
|
||||||
*
|
*
|
||||||
|
@ -48,10 +50,32 @@ class AssetsController extends Controller
|
||||||
* @since [v4.0]
|
* @since [v4.0]
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function index(Request $request, $audit = null)
|
public function index(Request $request, $audit = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->authorize('index', Asset::class);
|
\Log::debug(Route::currentRouteName());
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This looks MAD janky (and it is), but the AssetsController@index does a LOT of heavy lifting throughout the
|
||||||
|
* app. This bit here just makes sure that someone without permission to view assets doesn't
|
||||||
|
* end up with priv escalations because they asked for a different endpoint.
|
||||||
|
*
|
||||||
|
* Since we never gave the specification for which transformer to use before, it should default
|
||||||
|
* gracefully to just use the AssetTransformer by default, which shouldn't break anything.
|
||||||
|
*
|
||||||
|
* It was either this mess, or repeating ALL of the searching and sorting and filtering code,
|
||||||
|
* which would have been far worse of a mess. *sad face* - snipe (Sept 1, 2021)
|
||||||
|
*/
|
||||||
|
if (Route::currentRouteName()=='api.depreciation-report.index') {
|
||||||
|
$transformer = 'App\Http\Transformers\DepreciationReportTransformer';
|
||||||
|
$this->authorize('reports.view');
|
||||||
|
} else {
|
||||||
|
$transformer = 'App\Http\Transformers\AssetsTransformer';
|
||||||
|
$this->authorize('index', Asset::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$settings = Setting::getSettings();
|
$settings = Setting::getSettings();
|
||||||
|
|
||||||
$allowed_columns = [
|
$allowed_columns = [
|
||||||
|
@ -78,7 +102,7 @@ class AssetsController extends Controller
|
||||||
'requests_counter',
|
'requests_counter',
|
||||||
];
|
];
|
||||||
|
|
||||||
$filter = array();
|
$filter = [];
|
||||||
|
|
||||||
if ($request->filled('filter')) {
|
if ($request->filled('filter')) {
|
||||||
$filter = json_decode($request->input('filter'), true);
|
$filter = json_decode($request->input('filter'), true);
|
||||||
|
@ -86,13 +110,12 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
$all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load
|
$all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load
|
||||||
foreach ($all_custom_fields as $field) {
|
foreach ($all_custom_fields as $field) {
|
||||||
$allowed_columns[]=$field->db_column_name();
|
$allowed_columns[] = $field->db_column_name();
|
||||||
}
|
}
|
||||||
|
|
||||||
$assets = Company::scopeCompanyables(Asset::select('assets.*'),"company_id","assets")
|
$assets = Company::scopeCompanyables(Asset::select('assets.*'), 'company_id', 'assets')
|
||||||
->with('location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo',
|
->with('location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo',
|
||||||
'model.category', 'model.manufacturer', 'model.fieldset','supplier');
|
'model.category', 'model.manufacturer', 'model.fieldset', 'supplier');
|
||||||
|
|
||||||
|
|
||||||
// These are used by the API to query against specific ID numbers.
|
// These are used by the API to query against specific ID numbers.
|
||||||
// They are also used by the individual searches on detail pages like
|
// They are also used by the individual searches on detail pages like
|
||||||
|
@ -101,7 +124,7 @@ class AssetsController extends Controller
|
||||||
$assets->where('assets.status_id', '=', $request->input('status_id'));
|
$assets->where('assets.status_id', '=', $request->input('status_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->input('requestable')=='true') {
|
if ($request->input('requestable') == 'true') {
|
||||||
$assets->where('assets.requestable', '=', '1');
|
$assets->where('assets.requestable', '=', '1');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +171,6 @@ class AssetsController extends Controller
|
||||||
// case we override with the actual count, so we should return 0 items.
|
// case we override with the actual count, so we should return 0 items.
|
||||||
$offset = (($assets) && ($request->get('offset') > $assets->count())) ? $assets->count() : $request->get('offset', 0);
|
$offset = (($assets) && ($request->get('offset') > $assets->count())) ? $assets->count() : $request->get('offset', 0);
|
||||||
|
|
||||||
|
|
||||||
// Check to make sure the limit is not higher than the max allowed
|
// Check to make sure the limit is not higher than the max allowed
|
||||||
((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results');
|
((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results');
|
||||||
|
|
||||||
|
@ -156,7 +178,6 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
// This is used by the audit reporting routes
|
// This is used by the audit reporting routes
|
||||||
if (Gate::allows('audit', Asset::class)) {
|
if (Gate::allows('audit', Asset::class)) {
|
||||||
|
|
||||||
switch ($audit) {
|
switch ($audit) {
|
||||||
case 'due':
|
case 'due':
|
||||||
$assets->DueOrOverdueForAudit($settings);
|
$assets->DueOrOverdueForAudit($settings);
|
||||||
|
@ -179,19 +200,19 @@ class AssetsController extends Controller
|
||||||
$assets->onlyTrashed();
|
$assets->onlyTrashed();
|
||||||
break;
|
break;
|
||||||
case 'Pending':
|
case 'Pending':
|
||||||
$assets->join('status_labels AS status_alias',function ($join) {
|
$assets->join('status_labels AS status_alias', function ($join) {
|
||||||
$join->on('status_alias.id', "=", "assets.status_id")
|
$join->on('status_alias.id', '=', 'assets.status_id')
|
||||||
->where('status_alias.deployable','=',0)
|
->where('status_alias.deployable', '=', 0)
|
||||||
->where('status_alias.pending','=',1)
|
->where('status_alias.pending', '=', 1)
|
||||||
->where('status_alias.archived', '=', 0);
|
->where('status_alias.archived', '=', 0);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'RTD':
|
case 'RTD':
|
||||||
$assets->whereNull('assets.assigned_to')
|
$assets->whereNull('assets.assigned_to')
|
||||||
->join('status_labels AS status_alias',function ($join) {
|
->join('status_labels AS status_alias', function ($join) {
|
||||||
$join->on('status_alias.id', "=", "assets.status_id")
|
$join->on('status_alias.id', '=', 'assets.status_id')
|
||||||
->where('status_alias.deployable','=',1)
|
->where('status_alias.deployable', '=', 1)
|
||||||
->where('status_alias.pending','=',0)
|
->where('status_alias.pending', '=', 0)
|
||||||
->where('status_alias.archived', '=', 0);
|
->where('status_alias.archived', '=', 0);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
@ -199,19 +220,19 @@ class AssetsController extends Controller
|
||||||
$assets->Undeployable();
|
$assets->Undeployable();
|
||||||
break;
|
break;
|
||||||
case 'Archived':
|
case 'Archived':
|
||||||
$assets->join('status_labels AS status_alias',function ($join) {
|
$assets->join('status_labels AS status_alias', function ($join) {
|
||||||
$join->on('status_alias.id', "=", "assets.status_id")
|
$join->on('status_alias.id', '=', 'assets.status_id')
|
||||||
->where('status_alias.deployable','=',0)
|
->where('status_alias.deployable', '=', 0)
|
||||||
->where('status_alias.pending','=',0)
|
->where('status_alias.pending', '=', 0)
|
||||||
->where('status_alias.archived', '=', 1);
|
->where('status_alias.archived', '=', 1);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'Requestable':
|
case 'Requestable':
|
||||||
$assets->where('assets.requestable', '=', 1)
|
$assets->where('assets.requestable', '=', 1)
|
||||||
->join('status_labels AS status_alias',function ($join) {
|
->join('status_labels AS status_alias', function ($join) {
|
||||||
$join->on('status_alias.id', "=", "assets.status_id")
|
$join->on('status_alias.id', '=', 'assets.status_id')
|
||||||
->where('status_alias.deployable','=',1)
|
->where('status_alias.deployable', '=', 1)
|
||||||
->where('status_alias.pending','=',0)
|
->where('status_alias.pending', '=', 0)
|
||||||
->where('status_alias.archived', '=', 0);
|
->where('status_alias.archived', '=', 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -222,24 +243,24 @@ class AssetsController extends Controller
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
if ((!$request->filled('status_id')) && ($settings->show_archived_in_list!='1')) {
|
if ((! $request->filled('status_id')) && ($settings->show_archived_in_list != '1')) {
|
||||||
// terrible workaround for complex-query Laravel bug in fulltext
|
// terrible workaround for complex-query Laravel bug in fulltext
|
||||||
$assets->join('status_labels AS status_alias',function ($join) {
|
$assets->join('status_labels AS status_alias', function ($join) {
|
||||||
$join->on('status_alias.id', "=", "assets.status_id")
|
$join->on('status_alias.id', '=', 'assets.status_id')
|
||||||
->where('status_alias.archived', '=', 0);
|
->where('status_alias.archived', '=', 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
// If there is a status ID, don't take show_archived_in_list into consideration
|
// If there is a status ID, don't take show_archived_in_list into consideration
|
||||||
} else {
|
} else {
|
||||||
$assets->join('status_labels AS status_alias',function ($join) {
|
$assets->join('status_labels AS status_alias', function ($join) {
|
||||||
$join->on('status_alias.id', "=", "assets.status_id");
|
$join->on('status_alias.id', '=', 'assets.status_id');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((!is_null($filter)) && (count($filter)) > 0) {
|
if ((! is_null($filter)) && (count($filter)) > 0) {
|
||||||
$assets->ByFilter($filter);
|
$assets->ByFilter($filter);
|
||||||
} elseif ($request->filled('search')) {
|
} elseif ($request->filled('search')) {
|
||||||
$assets->TextSearch($request->input('search'));
|
$assets->TextSearch($request->input('search'));
|
||||||
|
@ -249,7 +270,7 @@ class AssetsController extends Controller
|
||||||
// This is kinda gross, but we need to do this because the Bootstrap Tables
|
// This is kinda gross, but we need to do this because the Bootstrap Tables
|
||||||
// API passes custom field ordering as custom_fields.fieldname, and we have to strip
|
// API passes custom field ordering as custom_fields.fieldname, and we have to strip
|
||||||
// that out to let the default sorter below order them correctly on the assets table.
|
// that out to let the default sorter below order them correctly on the assets table.
|
||||||
$sort_override = str_replace('custom_fields.','', $request->input('sort')) ;
|
$sort_override = str_replace('custom_fields.', '', $request->input('sort'));
|
||||||
|
|
||||||
// This handles all of the pivot sorting (versus the assets.* fields
|
// This handles all of the pivot sorting (versus the assets.* fields
|
||||||
// in the allowed_columns array)
|
// in the allowed_columns array)
|
||||||
|
@ -294,10 +315,26 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
$total = $assets->count();
|
$total = $assets->count();
|
||||||
$assets = $assets->skip($offset)->take($limit)->get();
|
$assets = $assets->skip($offset)->take($limit)->get();
|
||||||
// dd($assets);
|
|
||||||
return (new AssetsTransformer)->transformAssets($assets, $total);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Include additional associated relationships
|
||||||
|
*/
|
||||||
|
if ($request->input('components')) {
|
||||||
|
$assets->loadMissing(['components' => function ($query) {
|
||||||
|
$query->orderBy('created_at', 'desc');
|
||||||
|
}]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Here we're just determining which Transformer (via $transformer) to use based on the
|
||||||
|
* variables we set earlier on in this method - we default to AssetsTransformer.
|
||||||
|
*/
|
||||||
|
return (new $transformer)->transformAssets($assets, $total, $request);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns JSON with information about an asset (by tag) for detail view.
|
* Returns JSON with information about an asset (by tag) for detail view.
|
||||||
|
@ -307,14 +344,16 @@ class AssetsController extends Controller
|
||||||
* @since [v4.2.1]
|
* @since [v4.2.1]
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function showByTag($tag)
|
public function showByTag(Request $request, $tag)
|
||||||
{
|
{
|
||||||
if ($asset = Asset::with('assetstatus')->with('assignedTo')->where('asset_tag',$tag)->first()) {
|
if ($asset = Asset::with('assetstatus')->with('assignedTo')->where('asset_tag', $tag)->first()) {
|
||||||
$this->authorize('view', $asset);
|
$this->authorize('view', $asset);
|
||||||
return (new AssetsTransformer)->transformAsset($asset);
|
|
||||||
|
return (new AssetsTransformer)->transformAsset($asset, $request);
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200);
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -325,15 +364,16 @@ class AssetsController extends Controller
|
||||||
* @since [v4.2.1]
|
* @since [v4.2.1]
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function showBySerial($serial)
|
public function showBySerial(Request $request, $serial)
|
||||||
{
|
{
|
||||||
$this->authorize('index', Asset::class);
|
$this->authorize('index', Asset::class);
|
||||||
if ($assets = Asset::with('assetstatus')->with('assignedTo')
|
if ($assets = Asset::with('assetstatus')->with('assignedTo')
|
||||||
->withTrashed()->where('serial',$serial)->get()) {
|
->withTrashed()->where('serial', $serial)->get()) {
|
||||||
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
|
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200);
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'Asset not found'), 200);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -345,22 +385,25 @@ class AssetsController extends Controller
|
||||||
* @since [v4.0]
|
* @since [v4.0]
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function show($id)
|
public function show(Request $request, $id)
|
||||||
{
|
{
|
||||||
if ($asset = Asset::with('assetstatus')->with('assignedTo')->withTrashed()
|
if ($asset = Asset::with('assetstatus')->with('assignedTo')->withTrashed()
|
||||||
->withCount('checkins as checkins_count', 'checkouts as checkouts_count', 'userRequests as user_requests_count')->findOrFail($id)) {
|
->withCount('checkins as checkins_count', 'checkouts as checkouts_count', 'userRequests as user_requests_count')->findOrFail($id)) {
|
||||||
$this->authorize('view', $asset);
|
$this->authorize('view', $asset);
|
||||||
return (new AssetsTransformer)->transformAsset($asset);
|
|
||||||
|
return (new AssetsTransformer)->transformAsset($asset, $request->input('components') );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public function licenses($id)
|
|
||||||
|
public function licenses(Request $request, $id)
|
||||||
{
|
{
|
||||||
$this->authorize('view', Asset::class);
|
$this->authorize('view', Asset::class);
|
||||||
$this->authorize('view', License::class);
|
$this->authorize('view', License::class);
|
||||||
$asset = Asset::where('id', $id)->withTrashed()->first();
|
$asset = Asset::where('id', $id)->withTrashed()->first();
|
||||||
$licenses = $asset->licenses()->get();
|
$licenses = $asset->licenses()->get();
|
||||||
|
|
||||||
return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count());
|
return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +426,7 @@ class AssetsController extends Controller
|
||||||
'assets.model_id',
|
'assets.model_id',
|
||||||
'assets.assigned_to',
|
'assets.assigned_to',
|
||||||
'assets.assigned_type',
|
'assets.assigned_type',
|
||||||
'assets.status_id'
|
'assets.status_id',
|
||||||
])->with('model', 'assetstatus', 'assignedTo')->NotArchived(), 'company_id', 'assets');
|
])->with('model', 'assetstatus', 'assignedTo')->NotArchived(), 'company_id', 'assets');
|
||||||
|
|
||||||
if ($request->filled('assetStatusType') && $request->input('assetStatusType') === 'RTD') {
|
if ($request->filled('assetStatusType') && $request->input('assetStatusType') === 'RTD') {
|
||||||
|
@ -410,15 +453,14 @@ class AssetsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($asset->assetstatus->getStatuslabelType()=='pending') {
|
if ($asset->assetstatus->getStatuslabelType() == 'pending') {
|
||||||
$asset->use_text .= '('.$asset->assetstatus->getStatuslabelType().')';
|
$asset->use_text .= '('.$asset->assetstatus->getStatuslabelType().')';
|
||||||
}
|
}
|
||||||
|
|
||||||
$asset->use_image = ($asset->getImageUrl()) ? $asset->getImageUrl() : null;
|
$asset->use_image = ($asset->getImageUrl()) ? $asset->getImageUrl() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new SelectlistTransformer)->transformSelectlist($assets);
|
return (new SelectlistTransformer)->transformSelectlist($assets);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -432,7 +474,6 @@ class AssetsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function store(ImageUploadRequest $request)
|
public function store(ImageUploadRequest $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->authorize('create', Asset::class);
|
$this->authorize('create', Asset::class);
|
||||||
|
|
||||||
$asset = new Asset();
|
$asset = new Asset();
|
||||||
|
@ -451,7 +492,7 @@ class AssetsController extends Controller
|
||||||
$asset->depreciate = '0';
|
$asset->depreciate = '0';
|
||||||
$asset->status_id = $request->get('status_id', 0);
|
$asset->status_id = $request->get('status_id', 0);
|
||||||
$asset->warranty_months = $request->get('warranty_months', null);
|
$asset->warranty_months = $request->get('warranty_months', null);
|
||||||
$asset->purchase_cost = Helper::ParseFloat($request->get('purchase_cost'));
|
$asset->purchase_cost = Helper::ParseCurrency($request->get('purchase_cost')); // this is the API's store method, so I don't know that I want to do this? Confusing. FIXME (or not?!)
|
||||||
$asset->purchase_date = $request->get('purchase_date', null);
|
$asset->purchase_date = $request->get('purchase_date', null);
|
||||||
$asset->assigned_to = $request->get('assigned_to', null);
|
$asset->assigned_to = $request->get('assigned_to', null);
|
||||||
$asset->supplier_id = $request->get('supplier_id', 0);
|
$asset->supplier_id = $request->get('supplier_id', 0);
|
||||||
|
@ -487,13 +528,12 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
// if the field is set to encrypted, make sure we encrypt the value
|
// if the field is set to encrypted, make sure we encrypt the value
|
||||||
if ($field->field_encrypted == '1') {
|
if ($field->field_encrypted == '1') {
|
||||||
|
|
||||||
\Log::debug('This model field is encrypted in this fieldset.');
|
\Log::debug('This model field is encrypted in this fieldset.');
|
||||||
|
|
||||||
if (Gate::allows('admin')) {
|
if (Gate::allows('admin')) {
|
||||||
|
|
||||||
// If input value is null, use custom field's default value
|
// If input value is null, use custom field's default value
|
||||||
if (($field_val == null) && ($request->has('model_id')!='')){
|
if (($field_val == null) && ($request->has('model_id') != '')) {
|
||||||
$field_val = \Crypt::encrypt($field->defaultValue($request->get('model_id')));
|
$field_val = \Crypt::encrypt($field->defaultValue($request->get('model_id')));
|
||||||
} else {
|
} else {
|
||||||
$field_val = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));
|
$field_val = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));
|
||||||
|
@ -503,12 +543,10 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
|
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = $field_val;
|
$asset->{$field->convertUnicodeDbSlug()} = $field_val;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($asset->save()) {
|
if ($asset->save()) {
|
||||||
|
|
||||||
if ($request->get('assigned_user')) {
|
if ($request->get('assigned_user')) {
|
||||||
$target = User::find(request('assigned_user'));
|
$target = User::find(request('assigned_user'));
|
||||||
} elseif ($request->get('assigned_asset')) {
|
} elseif ($request->get('assigned_asset')) {
|
||||||
|
@ -570,7 +608,7 @@ class AssetsController extends Controller
|
||||||
if (($model = AssetModel::find($asset->model_id)) && (isset($model->fieldset))) {
|
if (($model = AssetModel::find($asset->model_id)) && (isset($model->fieldset))) {
|
||||||
foreach ($model->fieldset->fields as $field) {
|
foreach ($model->fieldset->fields as $field) {
|
||||||
if ($request->has($field->convertUnicodeDbSlug())) {
|
if ($request->has($field->convertUnicodeDbSlug())) {
|
||||||
if ($field->field_encrypted=='1') {
|
if ($field->field_encrypted == '1') {
|
||||||
if (Gate::allows('admin')) {
|
if (Gate::allows('admin')) {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));
|
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));
|
||||||
}
|
}
|
||||||
|
@ -583,15 +621,13 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
|
|
||||||
if ($asset->save()) {
|
if ($asset->save()) {
|
||||||
|
|
||||||
if (($request->filled('assigned_user')) && ($target = User::find($request->get('assigned_user')))) {
|
if (($request->filled('assigned_user')) && ($target = User::find($request->get('assigned_user')))) {
|
||||||
$location = $target->location_id;
|
$location = $target->location_id;
|
||||||
} elseif (($request->filled('assigned_asset')) && ($target = Asset::find($request->get('assigned_asset')))) {
|
} elseif (($request->filled('assigned_asset')) && ($target = Asset::find($request->get('assigned_asset')))) {
|
||||||
$location = $target->location_id;
|
$location = $target->location_id;
|
||||||
|
|
||||||
Asset::where('assigned_type', '\\App\\Models\\Asset')->where('assigned_to', $id)
|
Asset::where('assigned_type', \App\Models\Asset::class)->where('assigned_to', $id)
|
||||||
->update(['location_id' => $target->location_id]);
|
->update(['location_id' => $target->location_id]);
|
||||||
|
|
||||||
} elseif (($request->filled('assigned_location')) && ($target = Location::find($request->get('assigned_location')))) {
|
} elseif (($request->filled('assigned_location')) && ($target = Location::find($request->get('assigned_location')))) {
|
||||||
$location = $target->id;
|
$location = $target->id;
|
||||||
}
|
}
|
||||||
|
@ -606,8 +642,10 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $asset, trans('admin/hardware/message.update.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $asset->getErrors()), 200);
|
return response()->json(Helper::formatStandardApiResponse('error', null, $asset->getErrors()), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -625,12 +663,11 @@ class AssetsController extends Controller
|
||||||
$this->authorize('delete', Asset::class);
|
$this->authorize('delete', Asset::class);
|
||||||
|
|
||||||
if ($asset = Asset::find($id)) {
|
if ($asset = Asset::find($id)) {
|
||||||
|
|
||||||
$this->authorize('delete', $asset);
|
$this->authorize('delete', $asset);
|
||||||
|
|
||||||
DB::table('assets')
|
DB::table('assets')
|
||||||
->where('id', $asset->id)
|
->where('id', $asset->id)
|
||||||
->update(array('assigned_to' => null));
|
->update(['assigned_to' => null]);
|
||||||
|
|
||||||
$asset->delete();
|
$asset->delete();
|
||||||
|
|
||||||
|
@ -640,6 +677,37 @@ class AssetsController extends Controller
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore a soft-deleted asset.
|
||||||
|
*
|
||||||
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
* @param int $assetId
|
||||||
|
* @since [v5.1.18]
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function restore($assetId = null)
|
||||||
|
{
|
||||||
|
// Get asset information
|
||||||
|
$asset = Asset::withTrashed()->find($assetId);
|
||||||
|
$this->authorize('delete', $asset);
|
||||||
|
if (isset($asset->id)) {
|
||||||
|
// Restore the asset
|
||||||
|
Asset::withTrashed()->where('id', $assetId)->restore();
|
||||||
|
|
||||||
|
$logaction = new Actionlog();
|
||||||
|
$logaction->item_type = Asset::class;
|
||||||
|
$logaction->item_id = $asset->id;
|
||||||
|
$logaction->created_at = date("Y-m-d H:i:s");
|
||||||
|
$logaction->user_id = Auth::user()->id;
|
||||||
|
$logaction->logaction('restored');
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.restore.success')));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')), 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -655,7 +723,7 @@ class AssetsController extends Controller
|
||||||
$this->authorize('checkout', Asset::class);
|
$this->authorize('checkout', Asset::class);
|
||||||
$asset = Asset::findOrFail($asset_id);
|
$asset = Asset::findOrFail($asset_id);
|
||||||
|
|
||||||
if (!$asset->availableForCheckout()) {
|
if (! $asset->availableForCheckout()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkout.not_available')));
|
return response()->json(Helper::formatStandardApiResponse('error', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkout.not_available')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,21 +737,21 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
|
|
||||||
// This item is checked out to a location
|
// This item is checked out to a location
|
||||||
if (request('checkout_to_type')=='location') {
|
if (request('checkout_to_type') == 'location') {
|
||||||
$target = Location::find(request('assigned_location'));
|
$target = Location::find(request('assigned_location'));
|
||||||
$asset->location_id = ($target) ? $target->id : '';
|
$asset->location_id = ($target) ? $target->id : '';
|
||||||
$error_payload['target_id'] = $request->input('assigned_location');
|
$error_payload['target_id'] = $request->input('assigned_location');
|
||||||
$error_payload['target_type'] = 'location';
|
$error_payload['target_type'] = 'location';
|
||||||
|
|
||||||
} elseif (request('checkout_to_type')=='asset') {
|
} elseif (request('checkout_to_type') == 'asset') {
|
||||||
$target = Asset::where('id','!=',$asset_id)->find(request('assigned_asset'));
|
$target = Asset::where('id', '!=', $asset_id)->find(request('assigned_asset'));
|
||||||
$asset->location_id = $target->rtd_location_id;
|
$asset->location_id = $target->rtd_location_id;
|
||||||
// Override with the asset's location_id if it has one
|
// Override with the asset's location_id if it has one
|
||||||
$asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : '';
|
$asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : '';
|
||||||
$error_payload['target_id'] = $request->input('assigned_asset');
|
$error_payload['target_id'] = $request->input('assigned_asset');
|
||||||
$error_payload['target_type'] = 'asset';
|
$error_payload['target_type'] = 'asset';
|
||||||
|
|
||||||
} elseif (request('checkout_to_type')=='user') {
|
} elseif (request('checkout_to_type') == 'user') {
|
||||||
// Fetch the target and set the asset's new location_id
|
// Fetch the target and set the asset's new location_id
|
||||||
$target = User::find(request('assigned_user'));
|
$target = User::find(request('assigned_user'));
|
||||||
$asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : '';
|
$asset->location_id = (($target) && (isset($target->location_id))) ? $target->location_id : '';
|
||||||
|
@ -693,13 +761,13 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!isset($target)) {
|
if (! isset($target)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', $error_payload, 'Checkout target for asset '.e($asset->asset_tag).' is invalid - '.$error_payload['target_type'].' does not exist.'));
|
return response()->json(Helper::formatStandardApiResponse('error', $error_payload, 'Checkout target for asset '.e($asset->asset_tag).' is invalid - '.$error_payload['target_type'].' does not exist.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$checkout_at = request('checkout_at', date("Y-m-d H:i:s"));
|
$checkout_at = request('checkout_at', date('Y-m-d H:i:s'));
|
||||||
$expected_checkin = request('expected_checkin', null);
|
$expected_checkin = request('expected_checkin', null);
|
||||||
$note = request('note', null);
|
$note = request('note', null);
|
||||||
$asset_name = request('name', null);
|
$asset_name = request('name', null);
|
||||||
|
@ -753,18 +821,17 @@ class AssetsController extends Controller
|
||||||
$asset->name = $request->input('name');
|
$asset->name = $request->input('name');
|
||||||
}
|
}
|
||||||
|
|
||||||
$asset->location_id = $asset->rtd_location_id;
|
$asset->location_id = $asset->rtd_location_id;
|
||||||
|
|
||||||
if ($request->filled('location_id')) {
|
if ($request->filled('location_id')) {
|
||||||
$asset->location_id = $request->input('location_id');
|
$asset->location_id = $request->input('location_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->has('status_id')) {
|
if ($request->has('status_id')) {
|
||||||
$asset->status_id = $request->input('status_id');
|
$asset->status_id = $request->input('status_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($asset->save()) {
|
if ($asset->save()) {
|
||||||
$asset->logCheckin($target, e($request->input('note')));
|
|
||||||
event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note')));
|
event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note')));
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkin.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', ['asset'=> e($asset->asset_tag)], trans('admin/hardware/message.checkin.success')));
|
||||||
|
@ -782,15 +849,16 @@ class AssetsController extends Controller
|
||||||
* @since [v4.0]
|
* @since [v4.0]
|
||||||
* @return JsonResponse
|
* @return JsonResponse
|
||||||
*/
|
*/
|
||||||
public function audit(Request $request) {
|
public function audit(Request $request)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
$this->authorize('audit', Asset::class);
|
$this->authorize('audit', Asset::class);
|
||||||
$rules = array(
|
$rules = [
|
||||||
'asset_tag' => 'required',
|
'asset_tag' => 'required',
|
||||||
'location_id' => 'exists:locations,id|nullable|numeric',
|
'location_id' => 'exists:locations,id|nullable|numeric',
|
||||||
'next_audit_date' => 'date|nullable'
|
'next_audit_date' => 'date|nullable',
|
||||||
);
|
];
|
||||||
|
|
||||||
$validator = Validator::make($request->all(), $rules);
|
$validator = Validator::make($request->all(), $rules);
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
|
@ -800,7 +868,7 @@ class AssetsController extends Controller
|
||||||
$settings = Setting::getSettings();
|
$settings = Setting::getSettings();
|
||||||
$dt = Carbon::now()->addMonths($settings->audit_interval)->toDateString();
|
$dt = Carbon::now()->addMonths($settings->audit_interval)->toDateString();
|
||||||
|
|
||||||
$asset = Asset::where('asset_tag','=', $request->input('asset_tag'))->first();
|
$asset = Asset::where('asset_tag', '=', $request->input('asset_tag'))->first();
|
||||||
|
|
||||||
|
|
||||||
if ($asset) {
|
if ($asset) {
|
||||||
|
@ -814,18 +882,19 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
// Check to see if they checked the box to update the physical location,
|
// Check to see if they checked the box to update the physical location,
|
||||||
// not just note it in the audit notes
|
// not just note it in the audit notes
|
||||||
if ($request->input('update_location')=='1') {
|
if ($request->input('update_location') == '1') {
|
||||||
$asset->location_id = $request->input('location_id');
|
$asset->location_id = $request->input('location_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
$asset->last_audit_date = date('Y-m-d H:i:s');
|
$asset->last_audit_date = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
if ($asset->save()) {
|
if ($asset->save()) {
|
||||||
$log = $asset->logAudit(request('note'),request('location_id'));
|
$log = $asset->logAudit(request('note'), request('location_id'));
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', [
|
return response()->json(Helper::formatStandardApiResponse('success', [
|
||||||
'asset_tag'=> e($asset->asset_tag),
|
'asset_tag'=> e($asset->asset_tag),
|
||||||
'note'=> e($request->input('note')),
|
'note'=> e($request->input('note')),
|
||||||
'next_audit_date' => Helper::getFormattedDateObject($asset->next_audit_date)
|
'next_audit_date' => Helper::getFormattedDateObject($asset->next_audit_date),
|
||||||
], trans('admin/hardware/message.audit.success')));
|
], trans('admin/hardware/message.audit.success')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -851,9 +920,9 @@ class AssetsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('viewRequestable', Asset::class);
|
$this->authorize('viewRequestable', Asset::class);
|
||||||
|
|
||||||
$assets = Company::scopeCompanyables(Asset::select('assets.*'),"company_id","assets")
|
$assets = Company::scopeCompanyables(Asset::select('assets.*'), 'company_id', 'assets')
|
||||||
->with('location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo',
|
->with('location', 'assetstatus', 'assetlog', 'company', 'defaultLoc','assignedTo',
|
||||||
'model.category', 'model.manufacturer', 'model.fieldset','supplier')->where('assets.requestable', '=', '1');
|
'model.category', 'model.manufacturer', 'model.fieldset', 'supplier')->where('assets.requestable', '=', '1');
|
||||||
|
|
||||||
$offset = request('offset', 0);
|
$offset = request('offset', 0);
|
||||||
$limit = $request->input('limit', 50);
|
$limit = $request->input('limit', 50);
|
||||||
|
@ -878,9 +947,9 @@ class AssetsController extends Controller
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$total = $assets->count();
|
$total = $assets->count();
|
||||||
$assets = $assets->skip($offset)->take($limit)->get();
|
$assets = $assets->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new AssetsTransformer)->transformRequestedAssets($assets, $total);
|
return (new AssetsTransformer)->transformRequestedAssets($assets, $total);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,10 @@ class CategoriesController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('view', Category::class);
|
$this->authorize('view', Category::class);
|
||||||
$allowed_columns = ['id', 'name','category_type', 'category_type','use_default_eula','eula_text', 'require_acceptance','checkin_email', 'assets_count', 'accessories_count', 'consumables_count', 'components_count','licenses_count', 'image'];
|
$allowed_columns = ['id', 'name', 'category_type', 'category_type', 'use_default_eula', 'eula_text', 'require_acceptance', 'checkin_email', 'assets_count', 'accessories_count', 'consumables_count', 'components_count', 'licenses_count', 'image'];
|
||||||
|
|
||||||
$categories = Category::select(['id', 'created_at', 'updated_at', 'name','category_type','use_default_eula','eula_text', 'require_acceptance','checkin_email','image'])
|
$categories = Category::select(['id', 'created_at', 'updated_at', 'name', 'category_type', 'use_default_eula', 'eula_text', 'require_acceptance', 'checkin_email', 'image'])
|
||||||
->withCount('assets as assets_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count','licenses as licenses_count');
|
->withCount('assets as assets_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'licenses as licenses_count');
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
$categories = $categories->TextSearch($request->input('search'));
|
$categories = $categories->TextSearch($request->input('search'));
|
||||||
|
@ -45,11 +45,11 @@ class CategoriesController extends Controller
|
||||||
|
|
||||||
$total = $categories->count();
|
$total = $categories->count();
|
||||||
$categories = $categories->skip($offset)->take($limit)->get();
|
$categories = $categories->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new CategoriesTransformer)->transformCategories($categories, $total);
|
return (new CategoriesTransformer)->transformCategories($categories, $total);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -63,13 +63,14 @@ class CategoriesController extends Controller
|
||||||
$this->authorize('create', Category::class);
|
$this->authorize('create', Category::class);
|
||||||
$category = new Category;
|
$category = new Category;
|
||||||
$category->fill($request->all());
|
$category->fill($request->all());
|
||||||
|
$category->category_type = strtolower($request->input('category_type'));
|
||||||
$category = $request->handleImages($category);
|
$category = $request->handleImages($category);
|
||||||
|
|
||||||
if ($category->save()) {
|
if ($category->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $category, trans('admin/categories/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $category, trans('admin/categories/message.create.success')));
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $category->getErrors()));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, $category->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -84,11 +85,10 @@ class CategoriesController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Category::class);
|
$this->authorize('view', Category::class);
|
||||||
$category = Category::findOrFail($id);
|
$category = Category::findOrFail($id);
|
||||||
|
|
||||||
return (new CategoriesTransformer)->transformCategory($category);
|
return (new CategoriesTransformer)->transformCategory($category);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -103,6 +103,7 @@ class CategoriesController extends Controller
|
||||||
$this->authorize('update', Category::class);
|
$this->authorize('update', Category::class);
|
||||||
$category = Category::findOrFail($id);
|
$category = Category::findOrFail($id);
|
||||||
$category->fill($request->all());
|
$category->fill($request->all());
|
||||||
|
$category->category_type = strtolower($request->input('category_type'));
|
||||||
$category = $request->handleImages($category);
|
$category = $request->handleImages($category);
|
||||||
|
|
||||||
if ($category->save()) {
|
if ($category->save()) {
|
||||||
|
@ -125,28 +126,25 @@ class CategoriesController extends Controller
|
||||||
$this->authorize('delete', Category::class);
|
$this->authorize('delete', Category::class);
|
||||||
$category = Category::findOrFail($id);
|
$category = Category::findOrFail($id);
|
||||||
|
|
||||||
if (!$category->isDeletable()) {
|
if (! $category->isDeletable()) {
|
||||||
return response()->json(
|
return response()->json(
|
||||||
Helper::formatStandardApiResponse('error', null, trans('admin/categories/message.assoc_items', ['asset_type'=>$category->category_type]))
|
Helper::formatStandardApiResponse('error', null, trans('admin/categories/message.assoc_items', ['asset_type'=>$category->category_type]))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$category->delete();
|
$category->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/categories/message.delete.success')));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/categories/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a paginated collection for the select2 menus
|
* Gets a paginated collection for the select2 menus
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v4.0.16]
|
* @since [v4.0.16]
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function selectlist(Request $request, $category_type = 'asset')
|
public function selectlist(Request $request, $category_type = 'asset')
|
||||||
{
|
{
|
||||||
|
|
||||||
$categories = Category::select([
|
$categories = Category::select([
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
|
@ -167,7 +165,5 @@ class CategoriesController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new SelectlistTransformer)->transformSelectlist($categories);
|
return (new SelectlistTransformer)->transformSelectlist($categories);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ class CompaniesController extends Controller
|
||||||
'components_count',
|
'components_count',
|
||||||
];
|
];
|
||||||
|
|
||||||
$companies = Company::withCount('assets as assets_count','licenses as licenses_count','accessories as accessories_count','consumables as consumables_count','components as components_count','users as users_count');
|
$companies = Company::withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count', 'components as components_count', 'users as users_count');
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
$companies->TextSearch($request->input('search'));
|
$companies->TextSearch($request->input('search'));
|
||||||
|
@ -56,11 +56,10 @@ class CompaniesController extends Controller
|
||||||
|
|
||||||
$total = $companies->count();
|
$total = $companies->count();
|
||||||
$companies = $companies->skip($offset)->take($limit)->get();
|
$companies = $companies->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new CompaniesTransformer)->transformCompanies($companies, $total);
|
return (new CompaniesTransformer)->transformCompanies($companies, $total);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -79,9 +78,9 @@ class CompaniesController extends Controller
|
||||||
if ($company->save()) {
|
if ($company->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', (new CompaniesTransformer)->transformCompany($company), trans('admin/companies/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', (new CompaniesTransformer)->transformCompany($company), trans('admin/companies/message.create.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()
|
return response()
|
||||||
->json(Helper::formatStandardApiResponse('error', null, $company->getErrors()));
|
->json(Helper::formatStandardApiResponse('error', null, $company->getErrors()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,11 +95,10 @@ class CompaniesController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Company::class);
|
$this->authorize('view', Company::class);
|
||||||
$company = Company::findOrFail($id);
|
$company = Company::findOrFail($id);
|
||||||
|
|
||||||
return (new CompaniesTransformer)->transformCompany($company);
|
return (new CompaniesTransformer)->transformCompany($company);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -140,13 +138,14 @@ class CompaniesController extends Controller
|
||||||
$company = Company::findOrFail($id);
|
$company = Company::findOrFail($id);
|
||||||
$this->authorize('delete', $company);
|
$this->authorize('delete', $company);
|
||||||
|
|
||||||
if ( !$company->isDeletable() ) {
|
if (! $company->isDeletable()) {
|
||||||
return response()
|
return response()
|
||||||
->json(Helper::formatStandardApiResponse('error', null, trans('admin/companies/message.assoc_users')));
|
->json(Helper::formatStandardApiResponse('error', null, trans('admin/companies/message.assoc_users')));
|
||||||
}
|
}
|
||||||
$company->delete();
|
$company->delete();
|
||||||
|
|
||||||
return response()
|
return response()
|
||||||
->json(Helper::formatStandardApiResponse('success', null, trans('admin/companies/message.delete.success')));
|
->json(Helper::formatStandardApiResponse('success', null, trans('admin/companies/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,11 +154,9 @@ class CompaniesController extends Controller
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v4.0.16]
|
* @since [v4.0.16]
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function selectlist(Request $request)
|
public function selectlist(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$companies = Company::select([
|
$companies = Company::select([
|
||||||
'companies.id',
|
'companies.id',
|
||||||
'companies.name',
|
'companies.name',
|
||||||
|
|
|
@ -26,23 +26,40 @@ class ComponentsController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('view', Component::class);
|
$this->authorize('view', Component::class);
|
||||||
|
|
||||||
|
// This array is what determines which fields should be allowed to be sorted on ON the table itself, no relations
|
||||||
|
// Relations will be handled in query scopes a little further down.
|
||||||
|
$allowed_columns =
|
||||||
|
[
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'min_amt',
|
||||||
|
'order_number',
|
||||||
|
'serial',
|
||||||
|
'purchase_date',
|
||||||
|
'purchase_cost',
|
||||||
|
'qty',
|
||||||
|
'image',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
$components = Company::scopeCompanyables(Component::select('components.*')
|
$components = Company::scopeCompanyables(Component::select('components.*')
|
||||||
->with('company', 'location', 'category'));
|
->with('company', 'location', 'category', 'assets'));
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
$components = $components->TextSearch($request->input('search'));
|
$components = $components->TextSearch($request->input('search'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('company_id')) {
|
if ($request->filled('company_id')) {
|
||||||
$components->where('company_id','=',$request->input('company_id'));
|
$components->where('company_id', '=', $request->input('company_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('category_id')) {
|
if ($request->filled('category_id')) {
|
||||||
$components->where('category_id','=',$request->input('category_id'));
|
$components->where('category_id', '=', $request->input('category_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('location_id')) {
|
if ($request->filled('location_id')) {
|
||||||
$components->where('location_id','=',$request->input('location_id'));
|
$components->where('location_id', '=', $request->input('location_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which
|
// Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which
|
||||||
|
@ -52,11 +69,12 @@ class ComponentsController extends Controller
|
||||||
// Check to make sure the limit is not higher than the max allowed
|
// Check to make sure the limit is not higher than the max allowed
|
||||||
((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results');
|
((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results');
|
||||||
|
|
||||||
$allowed_columns = ['id','name','min_amt','order_number','serial','purchase_date','purchase_cost','company','category','qty','location','image'];
|
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||||
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
|
$sort_override = $request->input('sort');
|
||||||
|
$column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'created_at';
|
||||||
|
|
||||||
switch ($sort) {
|
switch ($sort_override) {
|
||||||
case 'category':
|
case 'category':
|
||||||
$components = $components->OrderCategory($order);
|
$components = $components->OrderCategory($order);
|
||||||
break;
|
break;
|
||||||
|
@ -67,12 +85,13 @@ class ComponentsController extends Controller
|
||||||
$components = $components->OrderCompany($order);
|
$components = $components->OrderCompany($order);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$components = $components->orderBy($sort, $order);
|
$components = $components->orderBy($column_sort, $order);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$total = $components->count();
|
$total = $components->count();
|
||||||
$components = $components->skip($offset)->take($limit)->get();
|
$components = $components->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new ComponentsTransformer)->transformComponents($components, $total);
|
return (new ComponentsTransformer)->transformComponents($components, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +114,7 @@ class ComponentsController extends Controller
|
||||||
if ($component->save()) {
|
if ($component->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $component, trans('admin/components/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $component, trans('admin/components/message.create.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $component->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $component->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +135,6 @@ class ComponentsController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -154,6 +173,7 @@ class ComponentsController extends Controller
|
||||||
$component = Component::findOrFail($id);
|
$component = Component::findOrFail($id);
|
||||||
$this->authorize('delete', $component);
|
$this->authorize('delete', $component);
|
||||||
$component->delete();
|
$component->delete();
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/components/message.delete.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/components/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +197,7 @@ class ComponentsController extends Controller
|
||||||
$limit = $request->input('limit', 50);
|
$limit = $request->input('limit', 50);
|
||||||
$total = $assets->count();
|
$total = $assets->count();
|
||||||
$assets = $assets->skip($offset)->take($limit)->get();
|
$assets = $assets->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new ComponentsTransformer)->transformCheckedoutComponents($assets, $total);
|
return (new ComponentsTransformer)->transformCheckedoutComponents($assets, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +223,7 @@ class ComponentsController extends Controller
|
||||||
$this->authorize('checkout', $component);
|
$this->authorize('checkout', $component);
|
||||||
|
|
||||||
|
|
||||||
if ($component->numRemaining() > $request->get('assigned_qty')) {
|
if ($component->numRemaining() >= $request->get('assigned_qty')) {
|
||||||
|
|
||||||
if (!$asset = Asset::find($request->input('assigned_to'))) {
|
if (!$asset = Asset::find($request->input('assigned_to'))) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')));
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/hardware/message.does_not_exist')));
|
||||||
|
|
|
@ -25,6 +25,26 @@ class ConsumablesController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('index', Consumable::class);
|
$this->authorize('index', Consumable::class);
|
||||||
|
|
||||||
|
// This array is what determines which fields should be allowed to be sorted on ON the table itself, no relations
|
||||||
|
// Relations will be handled in query scopes a little further down.
|
||||||
|
$allowed_columns =
|
||||||
|
[
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'order_number',
|
||||||
|
'min_amt',
|
||||||
|
'purchase_date',
|
||||||
|
'purchase_cost',
|
||||||
|
'company',
|
||||||
|
'category',
|
||||||
|
'model_number',
|
||||||
|
'item_no',
|
||||||
|
'qty',
|
||||||
|
'image',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
$consumables = Company::scopeCompanyables(
|
$consumables = Company::scopeCompanyables(
|
||||||
Consumable::select('consumables.*')
|
Consumable::select('consumables.*')
|
||||||
->with('company', 'location', 'category', 'users', 'manufacturer')
|
->with('company', 'location', 'category', 'users', 'manufacturer')
|
||||||
|
@ -35,15 +55,19 @@ class ConsumablesController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('company_id')) {
|
if ($request->filled('company_id')) {
|
||||||
$consumables->where('company_id','=',$request->input('company_id'));
|
$consumables->where('company_id', '=', $request->input('company_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('category_id')) {
|
if ($request->filled('category_id')) {
|
||||||
$consumables->where('category_id','=',$request->input('category_id'));
|
$consumables->where('category_id', '=', $request->input('category_id'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->filled('model_number')) {
|
||||||
|
$consumables->where('model_number','=',$request->input('model_number'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('manufacturer_id')) {
|
if ($request->filled('manufacturer_id')) {
|
||||||
$consumables->where('manufacturer_id','=',$request->input('manufacturer_id'));
|
$consumables->where('manufacturer_id', '=', $request->input('manufacturer_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('location_id')) {
|
if ($request->filled('location_id')) {
|
||||||
|
@ -58,12 +82,14 @@ class ConsumablesController extends Controller
|
||||||
// Check to make sure the limit is not higher than the max allowed
|
// Check to make sure the limit is not higher than the max allowed
|
||||||
((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results');
|
((config('app.max_results') >= $request->input('limit')) && ($request->filled('limit'))) ? $limit = $request->input('limit') : $limit = config('app.max_results');
|
||||||
|
|
||||||
$allowed_columns = ['id','name','order_number','min_amt','purchase_date','purchase_cost','company','category','model_number', 'item_no', 'manufacturer','location','qty','image'];
|
$allowed_columns = ['id', 'name', 'order_number', 'min_amt', 'purchase_date', 'purchase_cost', 'company', 'category', 'model_number', 'item_no', 'manufacturer', 'location', 'qty', 'image'];
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||||
$sort = in_array($request->input('sort'), $allowed_columns) ? $request->input('sort') : 'created_at';
|
|
||||||
|
$sort_override = $request->input('sort');
|
||||||
|
$column_sort = in_array($sort_override, $allowed_columns) ? $sort_override : 'created_at';
|
||||||
|
|
||||||
|
|
||||||
switch ($sort) {
|
switch ($sort_override) {
|
||||||
case 'category':
|
case 'category':
|
||||||
$consumables = $consumables->OrderCategory($order);
|
$consumables = $consumables->OrderCategory($order);
|
||||||
break;
|
break;
|
||||||
|
@ -77,19 +103,16 @@ class ConsumablesController extends Controller
|
||||||
$consumables = $consumables->OrderCompany($order);
|
$consumables = $consumables->OrderCompany($order);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
$consumables = $consumables->orderBy($sort, $order);
|
$consumables = $consumables->orderBy($column_sort, $order);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$total = $consumables->count();
|
$total = $consumables->count();
|
||||||
$consumables = $consumables->skip($offset)->take($limit)->get();
|
$consumables = $consumables->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new ConsumablesTransformer)->transformConsumables($consumables, $total);
|
return (new ConsumablesTransformer)->transformConsumables($consumables, $total);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -108,6 +131,7 @@ class ConsumablesController extends Controller
|
||||||
if ($consumable->save()) {
|
if ($consumable->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $consumable, trans('admin/consumables/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $consumable, trans('admin/consumables/message.create.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $consumable->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $consumable->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,10 +146,10 @@ class ConsumablesController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Consumable::class);
|
$this->authorize('view', Consumable::class);
|
||||||
$consumable = Consumable::findOrFail($id);
|
$consumable = Consumable::findOrFail($id);
|
||||||
|
|
||||||
return (new ConsumablesTransformer)->transformConsumable($consumable);
|
return (new ConsumablesTransformer)->transformConsumable($consumable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -163,7 +187,8 @@ class ConsumablesController extends Controller
|
||||||
$consumable = Consumable::findOrFail($id);
|
$consumable = Consumable::findOrFail($id);
|
||||||
$this->authorize('delete', $consumable);
|
$this->authorize('delete', $consumable);
|
||||||
$consumable->delete();
|
$consumable->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/consumables/message.delete.success')));
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/consumables/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,21 +202,20 @@ class ConsumablesController extends Controller
|
||||||
*/
|
*/
|
||||||
public function getDataView($consumableId)
|
public function getDataView($consumableId)
|
||||||
{
|
{
|
||||||
$consumable = Consumable::with(array('consumableAssignments'=>
|
$consumable = Consumable::with(['consumableAssignments'=> function ($query) {
|
||||||
function ($query) {
|
|
||||||
$query->orderBy($query->getModel()->getTable().'.created_at', 'DESC');
|
$query->orderBy($query->getModel()->getTable().'.created_at', 'DESC');
|
||||||
},
|
},
|
||||||
'consumableAssignments.admin'=> function ($query) {
|
'consumableAssignments.admin'=> function ($query) {
|
||||||
},
|
},
|
||||||
'consumableAssignments.user'=> function ($query) {
|
'consumableAssignments.user'=> function ($query) {
|
||||||
},
|
},
|
||||||
))->find($consumableId);
|
])->find($consumableId);
|
||||||
|
|
||||||
if (!Company::isCurrentUserHasAccess($consumable)) {
|
if (! Company::isCurrentUserHasAccess($consumable)) {
|
||||||
return ['total' => 0, 'rows' => []];
|
return ['total' => 0, 'rows' => []];
|
||||||
}
|
}
|
||||||
$this->authorize('view', Consumable::class);
|
$this->authorize('view', Consumable::class);
|
||||||
$rows = array();
|
$rows = [];
|
||||||
|
|
||||||
foreach ($consumable->consumableAssignments as $consumable_assignment) {
|
foreach ($consumable->consumableAssignments as $consumable_assignment) {
|
||||||
$rows[] = [
|
$rows[] = [
|
||||||
|
@ -202,7 +226,8 @@ class ConsumablesController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$consumableCount = $consumable->users->count();
|
$consumableCount = $consumable->users->count();
|
||||||
$data = array('total' => $consumableCount, 'rows' => $rows);
|
$data = ['total' => $consumableCount, 'rows' => $rows];
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +263,7 @@ class ConsumablesController extends Controller
|
||||||
$consumable->users()->attach($consumable->id, [
|
$consumable->users()->attach($consumable->id, [
|
||||||
'consumable_id' => $consumable->id,
|
'consumable_id' => $consumable->id,
|
||||||
'user_id' => $user->id,
|
'user_id' => $user->id,
|
||||||
'assigned_to' => $assigned_to
|
'assigned_to' => $assigned_to,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Log checkout event
|
// Log checkout event
|
||||||
|
@ -251,7 +276,7 @@ class ConsumablesController extends Controller
|
||||||
$data['note'] = $logaction->note;
|
$data['note'] = $logaction->note;
|
||||||
$data['require_acceptance'] = $consumable->requireAcceptance();
|
$data['require_acceptance'] = $consumable->requireAcceptance();
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/consumables/message.checkout.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/consumables/message.checkout.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'No consumables remaining'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'No consumables remaining'));
|
||||||
|
@ -261,14 +286,12 @@ class ConsumablesController extends Controller
|
||||||
* Gets a paginated collection for the select2 menus
|
* Gets a paginated collection for the select2 menus
|
||||||
*
|
*
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function selectlist(Request $request)
|
public function selectlist(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$consumables = Consumable::select([
|
$consumables = Consumable::select([
|
||||||
'consumables.id',
|
'consumables.id',
|
||||||
'consumables.name'
|
'consumables.name',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
|
@ -277,7 +300,6 @@ class ConsumablesController extends Controller
|
||||||
|
|
||||||
$consumables = $consumables->orderBy('name', 'ASC')->paginate(50);
|
$consumables = $consumables->orderBy('name', 'ASC')->paginate(50);
|
||||||
|
|
||||||
|
|
||||||
return (new SelectlistTransformer)->transformSelectlist($consumables);
|
return (new SelectlistTransformer)->transformSelectlist($consumables);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,26 +18,26 @@ class CustomFieldsController extends Controller
|
||||||
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @since [v3.0]
|
* @since [v3.0]
|
||||||
* @return Array
|
* @return array
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$this->authorize('index', CustomField::class);
|
$this->authorize('index', CustomField::class);
|
||||||
$fields = CustomField::get();
|
$fields = CustomField::get();
|
||||||
|
|
||||||
return (new CustomFieldsTransformer)->transformCustomFields($fields, $fields->count());
|
return (new CustomFieldsTransformer)->transformCustomFields($fields, $fields->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the given field
|
* Shows the given field
|
||||||
* @author [V. Cordes] [<volker@fdatek.de>]
|
* @author [V. Cordes] [<volker@fdatek.de>]
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @since [v4.1.10]
|
* @since [v4.1.10]
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$this->authorize('view', CustomField::class);
|
$this->authorize('view', CustomField::class);
|
||||||
if ($field = CustomField::find($id)) {
|
if ($field = CustomField::find($id)) {
|
||||||
return (new CustomFieldsTransformer)->transformCustomField($field);
|
return (new CustomFieldsTransformer)->transformCustomField($field);
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ class CustomFieldsController extends Controller
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/custom_fields/message.field.invalid')), 200);
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/custom_fields/message.field.invalid')), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified field
|
* Update the specified field
|
||||||
*
|
*
|
||||||
* @author [V. Cordes] [<volker@fdatek.de>]
|
* @author [V. Cordes] [<volker@fdatek.de>]
|
||||||
|
@ -80,7 +80,6 @@ class CustomFieldsController extends Controller
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $field->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $field->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created field.
|
* Store a newly created field.
|
||||||
*
|
*
|
||||||
|
@ -96,9 +95,9 @@ class CustomFieldsController extends Controller
|
||||||
|
|
||||||
$data = $request->all();
|
$data = $request->all();
|
||||||
$regex_format = null;
|
$regex_format = null;
|
||||||
|
|
||||||
if (str_contains($data["format"], "regex:")){
|
if (str_contains($data['format'], 'regex:')) {
|
||||||
$regex_format = $data["format"];
|
$regex_format = $data['format'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$validator = Validator::make($data, $field->validationRules($regex_format));
|
$validator = Validator::make($data, $field->validationRules($regex_format));
|
||||||
|
@ -111,8 +110,8 @@ class CustomFieldsController extends Controller
|
||||||
if ($field->save()) {
|
if ($field->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $field, trans('admin/custom_fields/message.field.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $field, trans('admin/custom_fields/message.field.create.success')));
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $field->getErrors()));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, $field->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function postReorder(Request $request, $id)
|
public function postReorder(Request $request, $id)
|
||||||
|
@ -121,8 +120,8 @@ class CustomFieldsController extends Controller
|
||||||
|
|
||||||
$this->authorize('update', $fieldset);
|
$this->authorize('update', $fieldset);
|
||||||
|
|
||||||
$fields = array();
|
$fields = [];
|
||||||
$order_array = array();
|
$order_array = [];
|
||||||
|
|
||||||
$items = $request->input('item');
|
$items = $request->input('item');
|
||||||
|
|
||||||
|
@ -135,7 +134,6 @@ class CustomFieldsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return $fieldset->fields()->sync($fields);
|
return $fieldset->fields()->sync($fields);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function associate(Request $request, $field_id)
|
public function associate(Request $request, $field_id)
|
||||||
|
@ -152,7 +150,8 @@ class CustomFieldsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$fieldset = CustomFieldset::findOrFail($fieldset_id);
|
$fieldset = CustomFieldset::findOrFail($fieldset_id);
|
||||||
$fieldset->fields()->attach($field->id, ["required" => ($request->input('required') == "on"), "order" => $request->input('order', $fieldset->fields->count())]);
|
$fieldset->fields()->attach($field->id, ['required' => ($request->input('required') == 'on'), 'order' => $request->input('order', $fieldset->fields->count())]);
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $fieldset, trans('admin/custom_fields/message.fieldset.update.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $fieldset, trans('admin/custom_fields/message.fieldset.update.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,10 +165,12 @@ class CustomFieldsController extends Controller
|
||||||
foreach ($field->fieldset as $fieldset) {
|
foreach ($field->fieldset as $fieldset) {
|
||||||
if ($fieldset->id == $fieldset_id) {
|
if ($fieldset->id == $fieldset_id) {
|
||||||
$fieldset->fields()->detach($field->id);
|
$fieldset->fields()->detach($field->id);
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $fieldset, trans('admin/custom_fields/message.fieldset.update.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $fieldset, trans('admin/custom_fields/message.fieldset.update.success')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$fieldset = CustomFieldset::findOrFail($fieldset_id);
|
$fieldset = CustomFieldset::findOrFail($fieldset_id);
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $fieldset, trans('admin/custom_fields/message.fieldset.update.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $fieldset, trans('admin/custom_fields/message.fieldset.update.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,13 +187,12 @@ class CustomFieldsController extends Controller
|
||||||
|
|
||||||
$this->authorize('delete', $field);
|
$this->authorize('delete', $field);
|
||||||
|
|
||||||
if ($field->fieldset->count() >0) {
|
if ($field->fieldset->count() > 0) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'Field is in use.'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'Field is in use.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$field->delete();
|
$field->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/custom_fields/message.field.delete.success')));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/custom_fields/message.field.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
@ -20,47 +21,43 @@ use View;
|
||||||
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
* @author [Brady Wetherington] [<uberbrady@gmail.com>]
|
||||||
* @author [Josh Gibson]
|
* @author [Josh Gibson]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class CustomFieldsetsController extends Controller
|
class CustomFieldsetsController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the given fieldset and its fields
|
* Shows the given fieldset and its fields
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @author [Josh Gibson]
|
* @author [Josh Gibson]
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @since [v1.8]
|
* @since [v1.8]
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$this->authorize('index', CustomFieldset::class);
|
$this->authorize('index', CustomFieldset::class);
|
||||||
$fieldsets = CustomFieldset::withCount('fields as fields_count', 'models as models_count')->get();
|
$fieldsets = CustomFieldset::withCount('fields as fields_count', 'models as models_count')->get();
|
||||||
return (new CustomFieldsetsTransformer)->transformCustomFieldsets($fieldsets, $fieldsets->count());
|
|
||||||
|
|
||||||
|
return (new CustomFieldsetsTransformer)->transformCustomFieldsets($fieldsets, $fieldsets->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shows the given fieldset and its fields
|
* Shows the given fieldset and its fields
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @author [Josh Gibson]
|
* @author [Josh Gibson]
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @since [v1.8]
|
* @since [v1.8]
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$this->authorize('view', CustomFieldset::class);
|
$this->authorize('view', CustomFieldset::class);
|
||||||
if ($fieldset = CustomFieldset::find($id)) {
|
if ($fieldset = CustomFieldset::find($id)) {
|
||||||
return (new CustomFieldsetsTransformer)->transformCustomFieldset($fieldset);
|
return (new CustomFieldsetsTransformer)->transformCustomFieldset($fieldset);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/custom_fields/message.fieldset.does_not_exist')), 200);
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/custom_fields/message.fieldset.does_not_exist')), 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
@ -82,7 +79,6 @@ class CustomFieldsetsController extends Controller
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $fieldset->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $fieldset->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -100,11 +96,10 @@ class CustomFieldsetsController extends Controller
|
||||||
if ($fieldset->save()) {
|
if ($fieldset->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $fieldset, trans('admin/custom_fields/message.fieldset.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $fieldset, trans('admin/custom_fields/message.fieldset.create.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $fieldset->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $fieldset->getErrors()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a custom fieldset.
|
* Delete a custom fieldset.
|
||||||
*
|
*
|
||||||
|
@ -120,18 +115,15 @@ class CustomFieldsetsController extends Controller
|
||||||
$modelsCount = $fieldset->models->count();
|
$modelsCount = $fieldset->models->count();
|
||||||
$fieldsCount = $fieldset->fields->count();
|
$fieldsCount = $fieldset->fields->count();
|
||||||
|
|
||||||
if (($modelsCount > 0) || ($fieldsCount > 0) ){
|
if (($modelsCount > 0) || ($fieldsCount > 0)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'Fieldset is in use.'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'Fieldset is in use.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($fieldset->delete()) {
|
if ($fieldset->delete()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/custom_fields/message.fieldset.delete.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/custom_fields/message.fieldset.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'Unspecified error'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'Unspecified error'));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,6 +139,7 @@ class CustomFieldsetsController extends Controller
|
||||||
$this->authorize('view', CustomFieldset::class);
|
$this->authorize('view', CustomFieldset::class);
|
||||||
$set = CustomFieldset::findOrFail($id);
|
$set = CustomFieldset::findOrFail($id);
|
||||||
$fields = $set->fields;
|
$fields = $set->fields;
|
||||||
|
|
||||||
return (new CustomFieldsTransformer)->transformCustomFields($fields, $fields->count());
|
return (new CustomFieldsTransformer)->transformCustomFields($fields, $fields->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ class DepartmentsController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('view', Department::class);
|
$this->authorize('view', Department::class);
|
||||||
$allowed_columns = ['id','name','image','users_count'];
|
$allowed_columns = ['id', 'name', 'image', 'users_count'];
|
||||||
|
|
||||||
$departments = Department::select([
|
$departments = Department::select([
|
||||||
'departments.id',
|
'departments.id',
|
||||||
|
@ -34,7 +34,7 @@ class DepartmentsController extends Controller
|
||||||
'departments.manager_id',
|
'departments.manager_id',
|
||||||
'departments.created_at',
|
'departments.created_at',
|
||||||
'departments.updated_at',
|
'departments.updated_at',
|
||||||
'departments.image'
|
'departments.image',
|
||||||
])->with('users')->with('location')->with('manager')->with('company')->withCount('users as users_count');
|
])->with('users')->with('location')->with('manager')->with('company')->withCount('users as users_count');
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
|
@ -65,8 +65,8 @@ class DepartmentsController extends Controller
|
||||||
|
|
||||||
$total = $departments->count();
|
$total = $departments->count();
|
||||||
$departments = $departments->skip($offset)->take($limit)->get();
|
$departments = $departments->skip($offset)->take($limit)->get();
|
||||||
return (new DepartmentsTransformer)->transformDepartments($departments, $total);
|
|
||||||
|
|
||||||
|
return (new DepartmentsTransformer)->transformDepartments($departments, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,13 +85,13 @@ class DepartmentsController extends Controller
|
||||||
$department = $request->handleImages($department);
|
$department = $request->handleImages($department);
|
||||||
|
|
||||||
$department->user_id = Auth::user()->id;
|
$department->user_id = Auth::user()->id;
|
||||||
$department->manager_id = ($request->filled('manager_id' ) ? $request->input('manager_id') : null);
|
$department->manager_id = ($request->filled('manager_id') ? $request->input('manager_id') : null);
|
||||||
|
|
||||||
if ($department->save()) {
|
if ($department->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $department, trans('admin/departments/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $department, trans('admin/departments/message.create.success')));
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $department->getErrors()));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, $department->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,6 +106,7 @@ class DepartmentsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Department::class);
|
$this->authorize('view', Department::class);
|
||||||
$department = Department::findOrFail($id);
|
$department = Department::findOrFail($id);
|
||||||
|
|
||||||
return (new DepartmentsTransformer)->transformDepartment($department);
|
return (new DepartmentsTransformer)->transformDepartment($department);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,8 +133,6 @@ class DepartmentsController extends Controller
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $department->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $department->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates and deletes selected department.
|
* Validates and deletes selected department.
|
||||||
*
|
*
|
||||||
|
@ -153,8 +152,8 @@ class DepartmentsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$department->delete();
|
$department->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/departments/message.delete.success')));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/departments/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,11 +162,9 @@ class DepartmentsController extends Controller
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v4.0.16]
|
* @since [v4.0.16]
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function selectlist(Request $request)
|
public function selectlist(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$departments = Department::select([
|
$departments = Department::select([
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
|
@ -188,7 +185,5 @@ class DepartmentsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new SelectlistTransformer)->transformSelectlist($departments);
|
return (new SelectlistTransformer)->transformSelectlist($departments);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@ class DepreciationsController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('view', Depreciation::class);
|
$this->authorize('view', Depreciation::class);
|
||||||
$allowed_columns = ['id','name','months','created_at'];
|
$allowed_columns = ['id','name','months','depreciation_min','created_at'];
|
||||||
|
|
||||||
$depreciations = Depreciation::select('id','name','months','user_id','created_at','updated_at');
|
$depreciations = Depreciation::select('id','name','months','depreciation_min','user_id','created_at','updated_at');
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
$depreciations = $depreciations->TextSearch($request->input('search'));
|
$depreciations = $depreciations->TextSearch($request->input('search'));
|
||||||
|
@ -41,10 +41,10 @@ class DepreciationsController extends Controller
|
||||||
|
|
||||||
$total = $depreciations->count();
|
$total = $depreciations->count();
|
||||||
$depreciations = $depreciations->skip($offset)->take($limit)->get();
|
$depreciations = $depreciations->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new DepreciationsTransformer)->transformDepreciations($depreciations, $total);
|
return (new DepreciationsTransformer)->transformDepreciations($depreciations, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -62,8 +62,8 @@ class DepreciationsController extends Controller
|
||||||
if ($depreciation->save()) {
|
if ($depreciation->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $depreciation, trans('admin/depreciations/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $depreciation, trans('admin/depreciations/message.create.success')));
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $depreciation->getErrors()));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, $depreciation->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,10 +78,10 @@ class DepreciationsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Depreciation::class);
|
$this->authorize('view', Depreciation::class);
|
||||||
$depreciation = Depreciation::findOrFail($id);
|
$depreciation = Depreciation::findOrFail($id);
|
||||||
|
|
||||||
return (new DepreciationsTransformer)->transformDepreciation($depreciation);
|
return (new DepreciationsTransformer)->transformDepreciation($depreciation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -123,10 +123,7 @@ class DepreciationsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$depreciation->delete();
|
$depreciation->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/depreciations/message.delete.success')));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/depreciations/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,9 @@ class GroupsController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('view', Group::class);
|
$this->authorize('view', Group::class);
|
||||||
$allowed_columns = ['id','name','created_at', 'users_count'];
|
$allowed_columns = ['id', 'name', 'created_at', 'users_count'];
|
||||||
|
|
||||||
$groups = Group::select('id','name','permissions','created_at','updated_at')->withCount('users as users_count');
|
$groups = Group::select('id', 'name', 'permissions', 'created_at', 'updated_at')->withCount('users as users_count');
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
$groups = $groups->TextSearch($request->input('search'));
|
$groups = $groups->TextSearch($request->input('search'));
|
||||||
|
@ -41,10 +41,10 @@ class GroupsController extends Controller
|
||||||
|
|
||||||
$total = $groups->count();
|
$total = $groups->count();
|
||||||
$groups = $groups->skip($offset)->take($limit)->get();
|
$groups = $groups->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new GroupsTransformer)->transformGroups($groups, $total);
|
return (new GroupsTransformer)->transformGroups($groups, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -62,8 +62,8 @@ class GroupsController extends Controller
|
||||||
if ($group->save()) {
|
if ($group->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $group, trans('admin/groups/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $group, trans('admin/groups/message.create.success')));
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $group->getErrors()));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, $group->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,10 +78,10 @@ class GroupsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Group::class);
|
$this->authorize('view', Group::class);
|
||||||
$group = Group::findOrFail($id);
|
$group = Group::findOrFail($id);
|
||||||
|
|
||||||
return (new GroupsTransformer)->transformGroup($group);
|
return (new GroupsTransformer)->transformGroup($group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -118,9 +118,7 @@ class GroupsController extends Controller
|
||||||
$group = Group::findOrFail($id);
|
$group = Group::findOrFail($id);
|
||||||
$this->authorize('delete', $group);
|
$this->authorize('delete', $group);
|
||||||
$group->delete();
|
$group->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/groups/message.delete.success')));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/groups/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,8 @@ class ImportController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('import');
|
$this->authorize('import');
|
||||||
$imports = Import::latest()->get();
|
$imports = Import::latest()->get();
|
||||||
return (new ImportsTransformer)->transformImports($imports);
|
|
||||||
|
|
||||||
|
return (new ImportsTransformer)->transformImports($imports);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,27 +40,28 @@ class ImportController extends Controller
|
||||||
public function store()
|
public function store()
|
||||||
{
|
{
|
||||||
$this->authorize('import');
|
$this->authorize('import');
|
||||||
if (!config('app.lock_passwords')) {
|
if (! config('app.lock_passwords')) {
|
||||||
$files = Request::file('files');
|
$files = Request::file('files');
|
||||||
$path = config('app.private_uploads').'/imports';
|
$path = config('app.private_uploads').'/imports';
|
||||||
$results = [];
|
$results = [];
|
||||||
$import = new Import;
|
$import = new Import;
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
if (!in_array($file->getMimeType(), array(
|
if (! in_array($file->getMimeType(), [
|
||||||
'application/vnd.ms-excel',
|
'application/vnd.ms-excel',
|
||||||
'text/csv',
|
'text/csv',
|
||||||
'application/csv',
|
'application/csv',
|
||||||
'text/x-Algol68', // because wtf CSV files?
|
'text/x-Algol68', // because wtf CSV files?
|
||||||
'text/plain',
|
'text/plain',
|
||||||
'text/comma-separated-values',
|
'text/comma-separated-values',
|
||||||
'text/tsv'))) {
|
'text/tsv', ])) {
|
||||||
$results['error']='File type must be CSV. Uploaded file is '.$file->getMimeType();
|
$results['error'] = 'File type must be CSV. Uploaded file is '.$file->getMimeType();
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $results['error']), 500);
|
return response()->json(Helper::formatStandardApiResponse('error', null, $results['error']), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: is there a lighter way to do this?
|
//TODO: is there a lighter way to do this?
|
||||||
if (! ini_get("auto_detect_line_endings")) {
|
if (! ini_get('auto_detect_line_endings')) {
|
||||||
ini_set("auto_detect_line_endings", '1');
|
ini_set('auto_detect_line_endings', '1');
|
||||||
}
|
}
|
||||||
$reader = Reader::createFromFileObject($file->openFile('r')); //file pointer leak?
|
$reader = Reader::createFromFileObject($file->openFile('r')); //file pointer leak?
|
||||||
$import->header_row = $reader->fetchOne(0);
|
$import->header_row = $reader->fetchOne(0);
|
||||||
|
@ -68,20 +69,20 @@ class ImportController extends Controller
|
||||||
//duplicate headers check
|
//duplicate headers check
|
||||||
$duplicate_headers = [];
|
$duplicate_headers = [];
|
||||||
|
|
||||||
for($i = 0; $i<count($import->header_row); $i++) {
|
for ($i = 0; $i < count($import->header_row); $i++) {
|
||||||
$header = $import->header_row[$i];
|
$header = $import->header_row[$i];
|
||||||
if(in_array($header, $import->header_row)) {
|
if (in_array($header, $import->header_row)) {
|
||||||
$found_at = array_search($header, $import->header_row);
|
$found_at = array_search($header, $import->header_row);
|
||||||
if($i > $found_at) {
|
if ($i > $found_at) {
|
||||||
//avoid reporting duplicates twice, e.g. "1 is same as 17! 17 is same as 1!!!"
|
//avoid reporting duplicates twice, e.g. "1 is same as 17! 17 is same as 1!!!"
|
||||||
//as well as "1 is same as 1!!!" (which is always true)
|
//as well as "1 is same as 1!!!" (which is always true)
|
||||||
//has to be > because otherwise the first result of array_search will always be $i itself(!)
|
//has to be > because otherwise the first result of array_search will always be $i itself(!)
|
||||||
array_push($duplicate_headers,"Duplicate header '$header' detected, first at column: ".($found_at+1).", repeats at column: ".($i+1));
|
array_push($duplicate_headers, "Duplicate header '$header' detected, first at column: ".($found_at + 1).', repeats at column: '.($i + 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(count($duplicate_headers) > 0) {
|
if (count($duplicate_headers) > 0) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error',null, implode("; ",$duplicate_headers)), 500); //should this be '4xx'?
|
return response()->json(Helper::formatStandardApiResponse('error', null, implode('; ', $duplicate_headers)), 500); //should this be '4xx'?
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grab the first row to display via ajax as the user picks fields
|
// Grab the first row to display via ajax as the user picks fields
|
||||||
|
@ -92,10 +93,11 @@ class ImportController extends Controller
|
||||||
try {
|
try {
|
||||||
$file->move($path, $date.'-'.$fixed_filename);
|
$file->move($path, $date.'-'.$fixed_filename);
|
||||||
} catch (FileException $exception) {
|
} catch (FileException $exception) {
|
||||||
$results['error']=trans('admin/hardware/message.upload.error');
|
$results['error'] = trans('admin/hardware/message.upload.error');
|
||||||
if (config('app.debug')) {
|
if (config('app.debug')) {
|
||||||
$results['error'].= ' ' . $exception->getMessage();
|
$results['error'] .= ' '.$exception->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $results['error']), 500);
|
return response()->json(Helper::formatStandardApiResponse('error', null, $results['error']), 500);
|
||||||
}
|
}
|
||||||
$file_name = date('Y-m-d-his').'-'.$fixed_filename;
|
$file_name = date('Y-m-d-his').'-'.$fixed_filename;
|
||||||
|
@ -105,12 +107,15 @@ class ImportController extends Controller
|
||||||
$results[] = $import;
|
$results[] = $import;
|
||||||
}
|
}
|
||||||
$results = (new ImportsTransformer)->transformImports($results);
|
$results = (new ImportsTransformer)->transformImports($results);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'files' => $results,
|
'files' => $results,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.feature_disabled')), 500);
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('general.feature_disabled')), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the specified Import.
|
* Processes the specified Import.
|
||||||
*
|
*
|
||||||
|
@ -130,25 +135,25 @@ class ImportController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$errors = $request->import(Import::find($import_id));
|
$errors = $request->import(Import::find($import_id));
|
||||||
$redirectTo = "hardware.index";
|
$redirectTo = 'hardware.index';
|
||||||
switch ($request->get('import-type')) {
|
switch ($request->get('import-type')) {
|
||||||
case "asset":
|
case 'asset':
|
||||||
$redirectTo = "hardware.index";
|
$redirectTo = 'hardware.index';
|
||||||
break;
|
break;
|
||||||
case "accessory":
|
case 'accessory':
|
||||||
$redirectTo = "accessories.index";
|
$redirectTo = 'accessories.index';
|
||||||
break;
|
break;
|
||||||
case "consumable":
|
case 'consumable':
|
||||||
$redirectTo = "consumables.index";
|
$redirectTo = 'consumables.index';
|
||||||
break;
|
break;
|
||||||
case "component":
|
case 'component':
|
||||||
$redirectTo = "components.index";
|
$redirectTo = 'components.index';
|
||||||
break;
|
break;
|
||||||
case "license":
|
case 'license':
|
||||||
$redirectTo = "licenses.index";
|
$redirectTo = 'licenses.index';
|
||||||
break;
|
break;
|
||||||
case "user":
|
case 'user':
|
||||||
$redirectTo = "users.index";
|
$redirectTo = 'users.index';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,8 +162,8 @@ class ImportController extends Controller
|
||||||
}
|
}
|
||||||
//Flash message before the redirect
|
//Flash message before the redirect
|
||||||
Session::flash('success', trans('admin/hardware/message.import.success'));
|
Session::flash('success', trans('admin/hardware/message.import.success'));
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, ['redirect_url' => route($redirectTo)]));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, ['redirect_url' => route($redirectTo)]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -170,20 +175,20 @@ class ImportController extends Controller
|
||||||
public function destroy($import_id)
|
public function destroy($import_id)
|
||||||
{
|
{
|
||||||
$this->authorize('create', Asset::class);
|
$this->authorize('create', Asset::class);
|
||||||
|
|
||||||
if ($import = Import::find($import_id)) {
|
if ($import = Import::find($import_id)) {
|
||||||
try {
|
try {
|
||||||
// Try to delete the file
|
// Try to delete the file
|
||||||
Storage::delete('imports/'.$import->file_path);
|
Storage::delete('imports/'.$import->file_path);
|
||||||
$import->delete();
|
$import->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.import.file_delete_success')));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/hardware/message.import.file_delete_success')));
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// If the file delete didn't work, remove it from the database anyway and return a warning
|
// If the file delete didn't work, remove it from the database anyway and return a warning
|
||||||
$import->delete();
|
$import->delete();
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('warning', null, trans('admin/hardware/message.import.file_not_deleted_warning')));
|
return response()->json(Helper::formatStandardApiResponse('warning', null, trans('admin/hardware/message.import.file_not_deleted_warning')));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ class LicenseSeatsController extends Controller
|
||||||
|
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||||
|
|
||||||
if ($request->input('sort')=='department') {
|
if ($request->input('sort') == 'department') {
|
||||||
$seats->OrderDepartments($order);
|
$seats->OrderDepartments($order);
|
||||||
} else {
|
} else {
|
||||||
$seats->orderBy('id', $order);
|
$seats->orderBy('id', $order);
|
||||||
|
@ -41,7 +41,7 @@ class LicenseSeatsController extends Controller
|
||||||
$total = $seats->count();
|
$total = $seats->count();
|
||||||
$offset = (($seats) && (request('offset') > $total)) ? 0 : request('offset', 0);
|
$offset = (($seats) && (request('offset') > $total)) ? 0 : request('offset', 0);
|
||||||
$limit = request('limit', 50);
|
$limit = request('limit', 50);
|
||||||
|
|
||||||
$seats = $seats->skip($offset)->take($limit)->get();
|
$seats = $seats->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
if ($seats) {
|
if ($seats) {
|
||||||
|
@ -65,13 +65,14 @@ class LicenseSeatsController extends Controller
|
||||||
$this->authorize('view', License::class);
|
$this->authorize('view', License::class);
|
||||||
// sanity checks:
|
// sanity checks:
|
||||||
// 1. does the license seat exist?
|
// 1. does the license seat exist?
|
||||||
if (!$licenseSeat = LicenseSeat::find($seatId)) {
|
if (! $licenseSeat = LicenseSeat::find($seatId)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat not found'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat not found'));
|
||||||
}
|
}
|
||||||
// 2. does the seat belong to the specified license?
|
// 2. does the seat belong to the specified license?
|
||||||
if (!$license = $licenseSeat->license()->first() || $license->id != intval($licenseId)) {
|
if (! $license = $licenseSeat->license()->first() || $license->id != intval($licenseId)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat does not belong to the specified license'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat does not belong to the specified license'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new LicenseSeatsTransformer)->transformLicenseSeat($licenseSeat);
|
return (new LicenseSeatsTransformer)->transformLicenseSeat($licenseSeat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,11 +90,11 @@ class LicenseSeatsController extends Controller
|
||||||
|
|
||||||
// sanity checks:
|
// sanity checks:
|
||||||
// 1. does the license seat exist?
|
// 1. does the license seat exist?
|
||||||
if (!$licenseSeat = LicenseSeat::find($seatId)) {
|
if (! $licenseSeat = LicenseSeat::find($seatId)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat not found'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat not found'));
|
||||||
}
|
}
|
||||||
// 2. does the seat belong to the specified license?
|
// 2. does the seat belong to the specified license?
|
||||||
if (!$license = $licenseSeat->license()->first() || $license->id != intval($licenseId)) {
|
if (! $license = $licenseSeat->license()->first() || $license->id != intval($licenseId)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat does not belong to the specified license'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'Seat does not belong to the specified license'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,14 +104,14 @@ class LicenseSeatsController extends Controller
|
||||||
// attempt to update the license seat
|
// attempt to update the license seat
|
||||||
$licenseSeat->fill($request->all());
|
$licenseSeat->fill($request->all());
|
||||||
$licenseSeat->user_id = Auth::user()->id;
|
$licenseSeat->user_id = Auth::user()->id;
|
||||||
|
|
||||||
// check if this update is a checkin operation
|
// check if this update is a checkin operation
|
||||||
// 1. are relevant fields touched at all?
|
// 1. are relevant fields touched at all?
|
||||||
$touched = $licenseSeat->isDirty('assigned_to') || $licenseSeat->isDirty('asset_id');
|
$touched = $licenseSeat->isDirty('assigned_to') || $licenseSeat->isDirty('asset_id');
|
||||||
// 2. are they cleared? if yes then this is a checkin operation
|
// 2. are they cleared? if yes then this is a checkin operation
|
||||||
$is_checkin = ($touched && $licenseSeat->assigned_to === null && $licenseSeat->asset_id === null);
|
$is_checkin = ($touched && $licenseSeat->assigned_to === null && $licenseSeat->asset_id === null);
|
||||||
|
|
||||||
if (!$touched) {
|
if (! $touched) {
|
||||||
// nothing to update
|
// nothing to update
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
|
||||||
}
|
}
|
||||||
|
@ -128,11 +129,13 @@ class LicenseSeatsController extends Controller
|
||||||
|
|
||||||
if ($is_checkin) {
|
if ($is_checkin) {
|
||||||
$licenseSeat->logCheckin($target, $request->input('note'));
|
$licenseSeat->logCheckin($target, $request->input('note'));
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
// in this case, relevant fields are touched but it's not a checkin operation. so it must be a checkout operation.
|
// in this case, relevant fields are touched but it's not a checkin operation. so it must be a checkout operation.
|
||||||
$licenseSeat->logCheckout($request->input('note'), $target);
|
$licenseSeat->logCheckout($request->input('note'), $target);
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $licenseSeat, trans('admin/licenses/message.update.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,63 +26,60 @@ class LicensesController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('view', License::class);
|
$this->authorize('view', License::class);
|
||||||
$licenses = Company::scopeCompanyables(License::with('company', 'manufacturer', 'freeSeats', 'supplier','category')->withCount('freeSeats as free_seats_count'));
|
$licenses = Company::scopeCompanyables(License::with('company', 'manufacturer', 'freeSeats', 'supplier', 'category')->withCount('freeSeats as free_seats_count'));
|
||||||
|
|
||||||
|
|
||||||
if ($request->filled('company_id')) {
|
if ($request->filled('company_id')) {
|
||||||
$licenses->where('company_id','=',$request->input('company_id'));
|
$licenses->where('company_id', '=', $request->input('company_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('name')) {
|
if ($request->filled('name')) {
|
||||||
$licenses->where('licenses.name','=',$request->input('name'));
|
$licenses->where('licenses.name', '=', $request->input('name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('product_key')) {
|
if ($request->filled('product_key')) {
|
||||||
$licenses->where('licenses.serial','=',$request->input('product_key'));
|
$licenses->where('licenses.serial', '=', $request->input('product_key'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('order_number')) {
|
if ($request->filled('order_number')) {
|
||||||
$licenses->where('order_number','=',$request->input('order_number'));
|
$licenses->where('order_number', '=', $request->input('order_number'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('purchase_order')) {
|
if ($request->filled('purchase_order')) {
|
||||||
$licenses->where('purchase_order','=',$request->input('purchase_order'));
|
$licenses->where('purchase_order', '=', $request->input('purchase_order'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('license_name')) {
|
if ($request->filled('license_name')) {
|
||||||
$licenses->where('license_name','=',$request->input('license_name'));
|
$licenses->where('license_name', '=', $request->input('license_name'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('license_email')) {
|
if ($request->filled('license_email')) {
|
||||||
$licenses->where('license_email','=',$request->input('license_email'));
|
$licenses->where('license_email', '=', $request->input('license_email'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('manufacturer_id')) {
|
if ($request->filled('manufacturer_id')) {
|
||||||
$licenses->where('manufacturer_id','=',$request->input('manufacturer_id'));
|
$licenses->where('manufacturer_id', '=', $request->input('manufacturer_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('supplier_id')) {
|
if ($request->filled('supplier_id')) {
|
||||||
$licenses->where('supplier_id','=',$request->input('supplier_id'));
|
$licenses->where('supplier_id', '=', $request->input('supplier_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('category_id')) {
|
if ($request->filled('category_id')) {
|
||||||
$licenses->where('category_id','=',$request->input('category_id'));
|
$licenses->where('category_id', '=', $request->input('category_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('depreciation_id')) {
|
if ($request->filled('depreciation_id')) {
|
||||||
$licenses->where('depreciation_id','=',$request->input('depreciation_id'));
|
$licenses->where('depreciation_id', '=', $request->input('depreciation_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('supplier_id')) {
|
if ($request->filled('supplier_id')) {
|
||||||
$licenses->where('supplier_id','=',$request->input('supplier_id'));
|
$licenses->where('supplier_id', '=', $request->input('supplier_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
$licenses = $licenses->TextSearch($request->input('search'));
|
$licenses = $licenses->TextSearch($request->input('search'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which
|
// Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which
|
||||||
// case we override with the actual count, so we should return 0 items.
|
// case we override with the actual count, so we should return 0 items.
|
||||||
$offset = (($licenses) && ($request->get('offset') > $licenses->count())) ? $licenses->count() : $request->get('offset', 0);
|
$offset = (($licenses) && ($request->get('offset') > $licenses->count())) ? $licenses->count() : $request->get('offset', 0);
|
||||||
|
@ -92,7 +89,6 @@ class LicensesController extends Controller
|
||||||
|
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||||
|
|
||||||
|
|
||||||
switch ($request->input('sort')) {
|
switch ($request->input('sort')) {
|
||||||
case 'manufacturer':
|
case 'manufacturer':
|
||||||
$licenses = $licenses->leftJoin('manufacturers', 'licenses.manufacturer_id', '=', 'manufacturers.id')->orderBy('manufacturers.name', $order);
|
$licenses = $licenses->leftJoin('manufacturers', 'licenses.manufacturer_id', '=', 'manufacturers.id')->orderBy('manufacturers.name', $order);
|
||||||
|
@ -128,25 +124,20 @@ class LicensesController extends Controller
|
||||||
'free_seats_count',
|
'free_seats_count',
|
||||||
'seats',
|
'seats',
|
||||||
'termination_date',
|
'termination_date',
|
||||||
'depreciation_id'
|
'depreciation_id',
|
||||||
];
|
];
|
||||||
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
||||||
$licenses = $licenses->orderBy($sort, $order);
|
$licenses = $licenses->orderBy($sort, $order);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$total = $licenses->count();
|
$total = $licenses->count();
|
||||||
|
|
||||||
$licenses = $licenses->skip($offset)->take($limit)->get();
|
$licenses = $licenses->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new LicensesTransformer)->transformLicenses($licenses, $total);
|
return (new LicensesTransformer)->transformLicenses($licenses, $total);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -162,9 +153,10 @@ class LicensesController extends Controller
|
||||||
$license = new License;
|
$license = new License;
|
||||||
$license->fill($request->all());
|
$license->fill($request->all());
|
||||||
|
|
||||||
if($license->save()) {
|
if ($license->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $license, trans('admin/licenses/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $license, trans('admin/licenses/message.create.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $license->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $license->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,10 +172,10 @@ class LicensesController extends Controller
|
||||||
$this->authorize('view', License::class);
|
$this->authorize('view', License::class);
|
||||||
$license = License::withCount('freeSeats')->findOrFail($id);
|
$license = License::withCount('freeSeats')->findOrFail($id);
|
||||||
$license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset');
|
$license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset');
|
||||||
|
|
||||||
return (new LicensesTransformer)->transformLicense($license);
|
return (new LicensesTransformer)->transformLicense($license);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -222,22 +214,23 @@ class LicensesController extends Controller
|
||||||
$license = License::findOrFail($id);
|
$license = License::findOrFail($id);
|
||||||
$this->authorize('delete', $license);
|
$this->authorize('delete', $license);
|
||||||
|
|
||||||
if($license->assigned_seats_count == 0) {
|
if ($license->assigned_seats_count == 0) {
|
||||||
// Delete the license and the associated license seats
|
// Delete the license and the associated license seats
|
||||||
DB::table('license_seats')
|
DB::table('license_seats')
|
||||||
->where('id', $license->id)
|
->where('id', $license->id)
|
||||||
->update(array('assigned_to' => null,'asset_id' => null));
|
->update(['assigned_to' => null, 'asset_id' => null]);
|
||||||
|
|
||||||
$licenseSeats = $license->licenseseats();
|
$licenseSeats = $license->licenseseats();
|
||||||
$licenseSeats->delete();
|
$licenseSeats->delete();
|
||||||
$license->delete();
|
$license->delete();
|
||||||
|
|
||||||
// Redirect to the licenses management page
|
// Redirect to the licenses management page
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/licenses/message.delete.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/licenses/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/licenses/message.assoc_users')));
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/licenses/message.assoc_users')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a paginated collection for the select2 menus
|
* Gets a paginated collection for the select2 menus
|
||||||
*
|
*
|
||||||
|
@ -245,10 +238,9 @@ class LicensesController extends Controller
|
||||||
*/
|
*/
|
||||||
public function selectlist(Request $request)
|
public function selectlist(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$licenses = License::select([
|
$licenses = License::select([
|
||||||
'licenses.id',
|
'licenses.id',
|
||||||
'licenses.name'
|
'licenses.name',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
|
@ -257,9 +249,6 @@ class LicensesController extends Controller
|
||||||
|
|
||||||
$licenses = $licenses->orderBy('name', 'ASC')->paginate(50);
|
$licenses = $licenses->orderBy('name', 'ASC')->paginate(50);
|
||||||
|
|
||||||
|
|
||||||
return (new SelectlistTransformer)->transformSelectlist($licenses);
|
return (new SelectlistTransformer)->transformSelectlist($licenses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Api;
|
namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use App\Helpers\Helper;
|
||||||
use App\Http\Requests\ImageUploadRequest;
|
use App\Http\Requests\ImageUploadRequest;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Helpers\Helper;
|
|
||||||
use App\Models\Location;
|
|
||||||
use App\Http\Transformers\LocationsTransformer;
|
use App\Http\Transformers\LocationsTransformer;
|
||||||
use App\Http\Transformers\SelectlistTransformer;
|
use App\Http\Transformers\SelectlistTransformer;
|
||||||
|
use App\Models\Location;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
|
@ -25,9 +25,9 @@ class LocationsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Location::class);
|
$this->authorize('view', Location::class);
|
||||||
$allowed_columns = [
|
$allowed_columns = [
|
||||||
'id','name','address','address2','city','state','country','zip','created_at',
|
'id', 'name', 'address', 'address2', 'city', 'state', 'country', 'zip', 'created_at',
|
||||||
'updated_at','manager_id','image',
|
'updated_at', 'manager_id', 'image',
|
||||||
'assigned_assets_count','users_count','assets_count','currency','ldap_ou'];
|
'assigned_assets_count', 'users_count', 'assets_count', 'currency', 'ldap_ou', ];
|
||||||
|
|
||||||
$locations = Location::with('parent', 'manager', 'children')->select([
|
$locations = Location::with('parent', 'manager', 'children')->select([
|
||||||
'locations.id',
|
'locations.id',
|
||||||
|
@ -44,7 +44,7 @@ class LocationsController extends Controller
|
||||||
'locations.updated_at',
|
'locations.updated_at',
|
||||||
'locations.image',
|
'locations.image',
|
||||||
'locations.ldap_ou',
|
'locations.ldap_ou',
|
||||||
'locations.currency'
|
'locations.currency',
|
||||||
])->withCount('assignedAssets as assigned_assets_count')
|
])->withCount('assignedAssets as assigned_assets_count')
|
||||||
->withCount('assets as assets_count')
|
->withCount('assets as assets_count')
|
||||||
->withCount('users as users_count');
|
->withCount('users as users_count');
|
||||||
|
@ -53,8 +53,6 @@ class LocationsController extends Controller
|
||||||
$locations = $locations->TextSearch($request->input('search'));
|
$locations = $locations->TextSearch($request->input('search'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$offset = (($locations) && (request('offset') > $locations->count())) ? $locations->count() : request('offset', 0);
|
$offset = (($locations) && (request('offset') > $locations->count())) ? $locations->count() : request('offset', 0);
|
||||||
|
|
||||||
// Check to make sure the limit is not higher than the max allowed
|
// Check to make sure the limit is not higher than the max allowed
|
||||||
|
@ -75,9 +73,9 @@ class LocationsController extends Controller
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$total = $locations->count();
|
$total = $locations->count();
|
||||||
$locations = $locations->skip($offset)->take($limit)->get();
|
$locations = $locations->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new LocationsTransformer)->transformLocations($locations, $total);
|
return (new LocationsTransformer)->transformLocations($locations, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,6 +98,7 @@ class LocationsController extends Controller
|
||||||
if ($location->save()) {
|
if ($location->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', (new LocationsTransformer)->transformLocation($location), trans('admin/locations/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', (new LocationsTransformer)->transformLocation($location), trans('admin/locations/message.create.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $location->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $location->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,15 +128,15 @@ class LocationsController extends Controller
|
||||||
'locations.created_at',
|
'locations.created_at',
|
||||||
'locations.updated_at',
|
'locations.updated_at',
|
||||||
'locations.image',
|
'locations.image',
|
||||||
'locations.currency'
|
'locations.currency',
|
||||||
])
|
])
|
||||||
->withCount('assignedAssets as assigned_assets_count')
|
->withCount('assignedAssets as assigned_assets_count')
|
||||||
->withCount('assets as assets_count')
|
->withCount('assets as assets_count')
|
||||||
->withCount('users as users_count')->findOrFail($id);
|
->withCount('users as users_count')->findOrFail($id);
|
||||||
|
|
||||||
return (new LocationsTransformer)->transformLocation($location);
|
return (new LocationsTransformer)->transformLocation($location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -156,8 +155,8 @@ class LocationsController extends Controller
|
||||||
$location = $request->handleImages($location);
|
$location = $request->handleImages($location);
|
||||||
|
|
||||||
if ($location->isValid()) {
|
if ($location->isValid()) {
|
||||||
|
|
||||||
$location->save();
|
$location->save();
|
||||||
|
|
||||||
return response()->json(
|
return response()->json(
|
||||||
Helper::formatStandardApiResponse(
|
Helper::formatStandardApiResponse(
|
||||||
'success',
|
'success',
|
||||||
|
@ -182,12 +181,13 @@ class LocationsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('delete', Location::class);
|
$this->authorize('delete', Location::class);
|
||||||
$location = Location::findOrFail($id);
|
$location = Location::findOrFail($id);
|
||||||
if(!$location->isDeletable()) {
|
if (! $location->isDeletable()) {
|
||||||
return response()
|
return response()
|
||||||
->json(Helper::formatStandardApiResponse('error', null, trans('admin/companies/message.assoc_users')));
|
->json(Helper::formatStandardApiResponse('error', null, trans('admin/companies/message.assoc_users')));
|
||||||
}
|
}
|
||||||
$this->authorize('delete', $location);
|
$this->authorize('delete', $location);
|
||||||
$location->delete();
|
$location->delete();
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/locations/message.delete.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/locations/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,11 +218,9 @@ class LocationsController extends Controller
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v4.0.16]
|
* @since [v4.0.16]
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function selectlist(Request $request)
|
public function selectlist(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$locations = Location::select([
|
$locations = Location::select([
|
||||||
'locations.id',
|
'locations.id',
|
||||||
'locations.name',
|
'locations.name',
|
||||||
|
@ -244,26 +242,22 @@ class LocationsController extends Controller
|
||||||
$locations_with_children = [];
|
$locations_with_children = [];
|
||||||
|
|
||||||
foreach ($locations as $location) {
|
foreach ($locations as $location) {
|
||||||
if (!array_key_exists($location->parent_id, $locations_with_children)) {
|
if (! array_key_exists($location->parent_id, $locations_with_children)) {
|
||||||
$locations_with_children[$location->parent_id] = [];
|
$locations_with_children[$location->parent_id] = [];
|
||||||
}
|
}
|
||||||
$locations_with_children[$location->parent_id][] = $location;
|
$locations_with_children[$location->parent_id][] = $location;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
$locations_formatted = $locations;
|
$locations_formatted = $locations;
|
||||||
} else {
|
} else {
|
||||||
$location_options = Location::indenter($locations_with_children);
|
$location_options = Location::indenter($locations_with_children);
|
||||||
$locations_formatted = new Collection($location_options);
|
$locations_formatted = new Collection($location_options);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$paginated_results = new LengthAwarePaginator($locations_formatted->forPage($page, 500), $locations_formatted->count(), 500, $page, []);
|
$paginated_results = new LengthAwarePaginator($locations_formatted->forPage($page, 500), $locations_formatted->count(), 500, $page, []);
|
||||||
|
|
||||||
//return [];
|
//return [];
|
||||||
return (new SelectlistTransformer)->transformSelectlist($paginated_results);
|
return (new SelectlistTransformer)->transformSelectlist($paginated_results);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,13 +23,13 @@ class ManufacturersController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('view', Manufacturer::class);
|
$this->authorize('view', Manufacturer::class);
|
||||||
$allowed_columns = ['id','name','url','support_url','support_email','support_phone','created_at','updated_at','image', 'assets_count', 'consumables_count', 'components_count', 'licenses_count'];
|
$allowed_columns = ['id', 'name', 'url', 'support_url', 'support_email', 'support_phone', 'created_at', 'updated_at', 'image', 'assets_count', 'consumables_count', 'components_count', 'licenses_count'];
|
||||||
|
|
||||||
$manufacturers = Manufacturer::select(
|
$manufacturers = Manufacturer::select(
|
||||||
array('id','name','url','support_url','support_email','support_phone','created_at','updated_at','image', 'deleted_at')
|
['id', 'name', 'url', 'support_url', 'support_email', 'support_phone', 'created_at', 'updated_at', 'image', 'deleted_at']
|
||||||
)->withCount('assets as assets_count')->withCount('licenses as licenses_count')->withCount('consumables as consumables_count')->withCount('accessories as accessories_count');
|
)->withCount('assets as assets_count')->withCount('licenses as licenses_count')->withCount('consumables as consumables_count')->withCount('accessories as accessories_count');
|
||||||
|
|
||||||
if ($request->input('deleted')=='true') {
|
if ($request->input('deleted') == 'true') {
|
||||||
$manufacturers->onlyTrashed();
|
$manufacturers->onlyTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +37,6 @@ class ManufacturersController extends Controller
|
||||||
$manufacturers = $manufacturers->TextSearch($request->input('search'));
|
$manufacturers = $manufacturers->TextSearch($request->input('search'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which
|
// Set the offset to the API call's offset, unless the offset is higher than the actual count of items in which
|
||||||
// case we override with the actual count, so we should return 0 items.
|
// case we override with the actual count, so we should return 0 items.
|
||||||
$offset = (($manufacturers) && ($request->get('offset') > $manufacturers->count())) ? $manufacturers->count() : $request->get('offset', 0);
|
$offset = (($manufacturers) && ($request->get('offset') > $manufacturers->count())) ? $manufacturers->count() : $request->get('offset', 0);
|
||||||
|
@ -51,10 +50,10 @@ class ManufacturersController extends Controller
|
||||||
|
|
||||||
$total = $manufacturers->count();
|
$total = $manufacturers->count();
|
||||||
$manufacturers = $manufacturers->skip($offset)->take($limit)->get();
|
$manufacturers = $manufacturers->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new ManufacturersTransformer)->transformManufacturers($manufacturers, $total);
|
return (new ManufacturersTransformer)->transformManufacturers($manufacturers, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -73,8 +72,8 @@ class ManufacturersController extends Controller
|
||||||
if ($manufacturer->save()) {
|
if ($manufacturer->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $manufacturer, trans('admin/manufacturers/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $manufacturer, trans('admin/manufacturers/message.create.success')));
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $manufacturer->getErrors()));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, $manufacturer->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,10 +88,10 @@ class ManufacturersController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Manufacturer::class);
|
$this->authorize('view', Manufacturer::class);
|
||||||
$manufacturer = Manufacturer::withCount('assets as assets_count')->withCount('licenses as licenses_count')->withCount('consumables as consumables_count')->withCount('accessories as accessories_count')->findOrFail($id);
|
$manufacturer = Manufacturer::withCount('assets as assets_count')->withCount('licenses as licenses_count')->withCount('consumables as consumables_count')->withCount('accessories as accessories_count')->findOrFail($id);
|
||||||
|
|
||||||
return (new ManufacturersTransformer)->transformManufacturer($manufacturer);
|
return (new ManufacturersTransformer)->transformManufacturer($manufacturer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -126,22 +125,17 @@ class ManufacturersController extends Controller
|
||||||
*/
|
*/
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->authorize('delete', Manufacturer::class);
|
$this->authorize('delete', Manufacturer::class);
|
||||||
$manufacturer = Manufacturer::findOrFail($id);
|
$manufacturer = Manufacturer::findOrFail($id);
|
||||||
$this->authorize('delete', $manufacturer);
|
$this->authorize('delete', $manufacturer);
|
||||||
|
|
||||||
if ($manufacturer->isDeletable()) {
|
if ($manufacturer->isDeletable()) {
|
||||||
$manufacturer->delete();
|
$manufacturer->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/manufacturers/message.delete.success')));
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/manufacturers/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/manufacturers/message.assoc_users')));
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/manufacturers/message.assoc_users')));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,11 +144,9 @@ class ManufacturersController extends Controller
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v4.0.16]
|
* @since [v4.0.16]
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function selectlist(Request $request)
|
public function selectlist(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$manufacturers = Manufacturer::select([
|
$manufacturers = Manufacturer::select([
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
|
@ -176,6 +168,5 @@ class ManufacturersController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new SelectlistTransformer)->transformSelectlist($manufacturers);
|
return (new SelectlistTransformer)->transformSelectlist($manufacturers);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,11 +37,10 @@ class PredefinedKitsController extends Controller
|
||||||
|
|
||||||
$total = $kits->count();
|
$total = $kits->count();
|
||||||
$kits = $kits->skip($offset)->take($limit)->get();
|
$kits = $kits->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new PredefinedKitsTransformer)->transformPredefinedKits($kits, $total);
|
return (new PredefinedKitsTransformer)->transformPredefinedKits($kits, $total);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created resource in storage.
|
* Store a newly created resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -57,8 +56,8 @@ class PredefinedKitsController extends Controller
|
||||||
if ($kit->save()) {
|
if ($kit->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, trans('admin/kits/general.create_success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, trans('admin/kits/general.create_success')));
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $kit->getErrors()));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, $kit->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,10 +70,10 @@ class PredefinedKitsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', PredefinedKit::class);
|
$this->authorize('view', PredefinedKit::class);
|
||||||
$kit = PredefinedKit::findOrFail($id);
|
$kit = PredefinedKit::findOrFail($id);
|
||||||
|
|
||||||
return (new PredefinedKitsTransformer)->transformPredefinedKit($kit);
|
return (new PredefinedKitsTransformer)->transformPredefinedKit($kit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -113,23 +112,20 @@ class PredefinedKitsController extends Controller
|
||||||
$kit->accessories()->detach();
|
$kit->accessories()->detach();
|
||||||
|
|
||||||
$kit->delete();
|
$kit->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/kits/general.delete_success'))); // TODO: trans
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/kits/general.delete_success'))); // TODO: trans
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a paginated collection for the select2 menus
|
* Gets a paginated collection for the select2 menus
|
||||||
*
|
*
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function selectlist(Request $request)
|
public function selectlist(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$kits = PredefinedKit::select([
|
$kits = PredefinedKit::select([
|
||||||
'id',
|
'id',
|
||||||
'name'
|
'name',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
|
@ -139,7 +135,6 @@ class PredefinedKitsController extends Controller
|
||||||
$kits = $kits->orderBy('name', 'ASC')->paginate(50);
|
$kits = $kits->orderBy('name', 'ASC')->paginate(50);
|
||||||
|
|
||||||
return (new SelectlistTransformer)->transformSelectlist($kits);
|
return (new SelectlistTransformer)->transformSelectlist($kits);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -148,38 +143,40 @@ class PredefinedKitsController extends Controller
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function indexLicenses($kit_id) {
|
public function indexLicenses($kit_id)
|
||||||
|
{
|
||||||
$this->authorize('view', PredefinedKit::class);
|
$this->authorize('view', PredefinedKit::class);
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
$licenses = $kit->licenses;
|
$licenses = $kit->licenses;
|
||||||
|
|
||||||
return (new PredefinedKitsTransformer)->transformElements($licenses, $licenses->count());
|
return (new PredefinedKitsTransformer)->transformElements($licenses, $licenses->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the specified resource.
|
* Store the specified resource.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function storeLicense(Request $request, $kit_id)
|
public function storeLicense(Request $request, $kit_id)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
|
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
|
||||||
$quantity = $request->input('quantity', 1);
|
|
||||||
if( $quantity < 1) {
|
|
||||||
$quantity = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$license_id = $request->get('license');
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
$relation = $kit->licenses();
|
$quantity = $request->input('quantity', 1);
|
||||||
if( $relation->find($license_id) ) {
|
if ($quantity < 1) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, ['license' => 'License already attached to kit']));
|
$quantity = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$relation->attach( $license_id, ['quantity' => $quantity]);
|
$license_id = $request->get('license');
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'License added successfull')); // TODO: trans
|
$relation = $kit->licenses();
|
||||||
|
if ($relation->find($license_id)) {
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, ['license' => 'License already attached to kit']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$relation->attach($license_id, ['quantity' => $quantity]);
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'License added successfull')); // TODO: trans
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -189,20 +186,20 @@ class PredefinedKitsController extends Controller
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function updateLicense(Request $request, $kit_id, $license_id)
|
public function updateLicense(Request $request, $kit_id, $license_id)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
$quantity = $request->input('quantity', 1);
|
$quantity = $request->input('quantity', 1);
|
||||||
if( $quantity < 1) {
|
if ($quantity < 1) {
|
||||||
$quantity = 1;
|
$quantity = 1;
|
||||||
}
|
}
|
||||||
$kit->licenses()->syncWithoutDetaching([$license_id => ['quantity' => $quantity]]);
|
$kit->licenses()->syncWithoutDetaching([$license_id => ['quantity' => $quantity]]);
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'License updated')); // TODO: trans
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'License updated')); // TODO: trans
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
|
@ -214,48 +211,49 @@ class PredefinedKitsController extends Controller
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
|
|
||||||
$kit->licenses()->detach($license_id);
|
$kit->licenses()->detach($license_id);
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, trans('admin/kits/general.delete_success')));
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, trans('admin/kits/general.delete_success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function indexModels($kit_id) {
|
public function indexModels($kit_id)
|
||||||
|
{
|
||||||
$this->authorize('view', PredefinedKit::class);
|
$this->authorize('view', PredefinedKit::class);
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
$models = $kit->models;
|
$models = $kit->models;
|
||||||
|
|
||||||
return (new PredefinedKitsTransformer)->transformElements($models, $models->count());
|
return (new PredefinedKitsTransformer)->transformElements($models, $models->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the specified resource.
|
* Store the specified resource.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function storeModel(Request $request, $kit_id)
|
public function storeModel(Request $request, $kit_id)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
|
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
|
|
||||||
$model_id = $request->get('model');
|
$model_id = $request->get('model');
|
||||||
$quantity = $request->input('quantity', 1);
|
$quantity = $request->input('quantity', 1);
|
||||||
if( $quantity < 1) {
|
if ($quantity < 1) {
|
||||||
$quantity = 1;
|
$quantity = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$relation = $kit->models();
|
$relation = $kit->models();
|
||||||
if( $relation->find($model_id) ) {
|
if ($relation->find($model_id)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, ['model' => 'Model already attached to kit']));
|
return response()->json(Helper::formatStandardApiResponse('error', null, ['model' => 'Model already attached to kit']));
|
||||||
}
|
}
|
||||||
$relation->attach($model_id, ['quantity' => $quantity]);
|
$relation->attach($model_id, ['quantity' => $quantity]);
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Model added successfull'));
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Model added successfull'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,20 +264,20 @@ class PredefinedKitsController extends Controller
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function updateModel(Request $request, $kit_id, $model_id)
|
public function updateModel(Request $request, $kit_id, $model_id)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
$quantity = $request->input('quantity', 1);
|
$quantity = $request->input('quantity', 1);
|
||||||
if( $quantity < 1) {
|
if ($quantity < 1) {
|
||||||
$quantity = 1;
|
$quantity = 1;
|
||||||
}
|
}
|
||||||
$kit->models()->syncWithoutDetaching([$model_id => ['quantity' => $quantity]]);
|
$kit->models()->syncWithoutDetaching([$model_id => ['quantity' => $quantity]]);
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'License updated')); // TODO: trans
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'License updated')); // TODO: trans
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
|
@ -291,49 +289,50 @@ class PredefinedKitsController extends Controller
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
|
|
||||||
$kit->models()->detach($model_id);
|
$kit->models()->detach($model_id);
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, trans('admin/kits/general.model_removed_success')));
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, trans('admin/kits/general.model_removed_success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function indexConsumables($kit_id) {
|
public function indexConsumables($kit_id)
|
||||||
|
{
|
||||||
$this->authorize('view', PredefinedKit::class);
|
$this->authorize('view', PredefinedKit::class);
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
$consumables = $kit->consumables;
|
$consumables = $kit->consumables;
|
||||||
|
|
||||||
return (new PredefinedKitsTransformer)->transformElements($consumables, $consumables->count());
|
return (new PredefinedKitsTransformer)->transformElements($consumables, $consumables->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the specified resource.
|
* Store the specified resource.
|
||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function storeConsumable(Request $request, $kit_id)
|
public function storeConsumable(Request $request, $kit_id)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
|
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
|
||||||
$quantity = $request->input('quantity', 1);
|
|
||||||
if( $quantity < 1) {
|
|
||||||
$quantity = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$consumable_id = $request->get('consumable');
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
$relation = $kit->consumables();
|
$quantity = $request->input('quantity', 1);
|
||||||
if( $relation->find($consumable_id) ) {
|
if ($quantity < 1) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, ['consumable' => 'Consumable already attached to kit']));
|
$quantity = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$relation->attach( $consumable_id, ['quantity' => $quantity]);
|
$consumable_id = $request->get('consumable');
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Consumable added successfull')); // TODO: trans
|
$relation = $kit->consumables();
|
||||||
|
if ($relation->find($consumable_id)) {
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, ['consumable' => 'Consumable already attached to kit']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$relation->attach($consumable_id, ['quantity' => $quantity]);
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Consumable added successfull')); // TODO: trans
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -343,20 +342,20 @@ class PredefinedKitsController extends Controller
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function updateConsumable(Request $request, $kit_id, $consumable_id)
|
public function updateConsumable(Request $request, $kit_id, $consumable_id)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
$quantity = $request->input('quantity', 1);
|
$quantity = $request->input('quantity', 1);
|
||||||
if( $quantity < 1) {
|
if ($quantity < 1) {
|
||||||
$quantity = 1;
|
$quantity = 1;
|
||||||
}
|
}
|
||||||
$kit->consumables()->syncWithoutDetaching([$consumable_id => ['quantity' => $quantity]]);
|
$kit->consumables()->syncWithoutDetaching([$consumable_id => ['quantity' => $quantity]]);
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Consumable updated')); // TODO: trans
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Consumable updated')); // TODO: trans
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
|
@ -368,48 +367,50 @@ class PredefinedKitsController extends Controller
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
|
|
||||||
$kit->consumables()->detach($consumable_id);
|
$kit->consumables()->detach($consumable_id);
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Delete was successfull')); // TODO: trans
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Delete was successfull')); // TODO: trans
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*
|
*
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function indexAccessories($kit_id) {
|
public function indexAccessories($kit_id)
|
||||||
|
{
|
||||||
$this->authorize('view', PredefinedKit::class);
|
$this->authorize('view', PredefinedKit::class);
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
$accessories = $kit->accessories;
|
$accessories = $kit->accessories;
|
||||||
|
|
||||||
return (new PredefinedKitsTransformer)->transformElements($accessories, $accessories->count());
|
return (new PredefinedKitsTransformer)->transformElements($accessories, $accessories->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store the specified resource.
|
* Store the specified resource.
|
||||||
*
|
*
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function storeAccessory(Request $request, $kit_id)
|
public function storeAccessory(Request $request, $kit_id)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
|
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
|
||||||
$quantity = $request->input('quantity', 1);
|
|
||||||
if( $quantity < 1) {
|
|
||||||
$quantity = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
$accessory_id = $request->get('accessory');
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
$relation = $kit->accessories();
|
$quantity = $request->input('quantity', 1);
|
||||||
if( $relation->find($accessory_id) ) {
|
if ($quantity < 1) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, ['accessory' => 'Accessory already attached to kit']));
|
$quantity = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$relation->attach( $accessory_id, ['quantity' => $quantity]);
|
$accessory_id = $request->get('accessory');
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Accessory added successfull')); // TODO: trans
|
$relation = $kit->accessories();
|
||||||
|
if ($relation->find($accessory_id)) {
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, ['accessory' => 'Accessory already attached to kit']));
|
||||||
|
}
|
||||||
|
|
||||||
|
$relation->attach($accessory_id, ['quantity' => $quantity]);
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Accessory added successfull')); // TODO: trans
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -419,20 +420,20 @@ class PredefinedKitsController extends Controller
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
public function updateAccessory(Request $request, $kit_id, $accessory_id)
|
public function updateAccessory(Request $request, $kit_id, $accessory_id)
|
||||||
{
|
{
|
||||||
$this->authorize('update', PredefinedKit::class);
|
$this->authorize('update', PredefinedKit::class);
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
$quantity = $request->input('quantity', 1);
|
$quantity = $request->input('quantity', 1);
|
||||||
if( $quantity < 1) {
|
if ($quantity < 1) {
|
||||||
$quantity = 1;
|
$quantity = 1;
|
||||||
}
|
}
|
||||||
$kit->accessories()->syncWithoutDetaching([$accessory_id => ['quantity' => $quantity]]);
|
$kit->accessories()->syncWithoutDetaching([$accessory_id => ['quantity' => $quantity]]);
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Accessory updated')); // TODO: trans
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Accessory updated')); // TODO: trans
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
* @param int $kit_id
|
* @param int $kit_id
|
||||||
|
@ -444,6 +445,7 @@ class PredefinedKitsController extends Controller
|
||||||
$kit = PredefinedKit::findOrFail($kit_id);
|
$kit = PredefinedKit::findOrFail($kit_id);
|
||||||
|
|
||||||
$kit->accessories()->detach($accessory_id);
|
$kit->accessories()->detach($accessory_id);
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Delete was successfull')); // TODO: trans
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', $kit, 'Delete was successfull')); // TODO: trans
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ class ProfileController extends Controller
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v4.3.0]
|
* @since [v4.3.0]
|
||||||
*
|
*
|
||||||
* @return Array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function requestedAssets()
|
public function requestedAssets()
|
||||||
{
|
{
|
||||||
|
@ -24,7 +24,6 @@ class ProfileController extends Controller
|
||||||
$results = [];
|
$results = [];
|
||||||
$results['total'] = $checkoutRequests->count();
|
$results['total'] = $checkoutRequests->count();
|
||||||
|
|
||||||
|
|
||||||
foreach ($checkoutRequests as $checkoutRequest) {
|
foreach ($checkoutRequests as $checkoutRequest) {
|
||||||
|
|
||||||
// Make sure the asset and request still exist
|
// Make sure the asset and request still exist
|
||||||
|
@ -39,10 +38,8 @@ class ProfileController extends Controller
|
||||||
'request_date' => Helper::getFormattedDateObject($checkoutRequest->created_at, 'datetime'),
|
'request_date' => Helper::getFormattedDateObject($checkoutRequest->created_at, 'datetime'),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,25 +19,25 @@ class ReportsController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('reports.view');
|
$this->authorize('reports.view');
|
||||||
|
|
||||||
$actionlogs = Actionlog::with('item', 'user', 'target','location');
|
$actionlogs = Actionlog::with('item', 'user', 'target', 'location');
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
$actionlogs = $actionlogs->TextSearch(e($request->input('search')));
|
$actionlogs = $actionlogs->TextSearch(e($request->input('search')));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($request->filled('target_type')) && ($request->filled('target_id'))) {
|
if (($request->filled('target_type')) && ($request->filled('target_id'))) {
|
||||||
$actionlogs = $actionlogs->where('target_id','=',$request->input('target_id'))
|
$actionlogs = $actionlogs->where('target_id', '=', $request->input('target_id'))
|
||||||
->where('target_type','=',"App\\Models\\".ucwords($request->input('target_type')));
|
->where('target_type', '=', 'App\\Models\\'.ucwords($request->input('target_type')));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($request->filled('item_type')) && ($request->filled('item_id'))) {
|
if (($request->filled('item_type')) && ($request->filled('item_id'))) {
|
||||||
$actionlogs = $actionlogs->where('item_id','=',$request->input('item_id'))
|
$actionlogs = $actionlogs->where('item_id', '=', $request->input('item_id'))
|
||||||
->where('item_type','=',"App\\Models\\".ucwords($request->input('item_type')));
|
->where('item_type', '=', 'App\\Models\\'.ucwords($request->input('item_type')));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('action_type')) {
|
if ($request->filled('action_type')) {
|
||||||
$actionlogs = $actionlogs->where('action_type','=',$request->input('action_type'))->orderBy('created_at', 'desc');
|
$actionlogs = $actionlogs->where('action_type', '=', $request->input('action_type'))->orderBy('created_at', 'desc');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('uploads')) {
|
if ($request->filled('uploads')) {
|
||||||
|
@ -51,9 +51,9 @@ class ReportsController extends Controller
|
||||||
'user_id',
|
'user_id',
|
||||||
'accept_signature',
|
'accept_signature',
|
||||||
'action_type',
|
'action_type',
|
||||||
'note'
|
'note',
|
||||||
];
|
];
|
||||||
|
|
||||||
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
$sort = in_array($request->input('sort'), $allowed_columns) ? e($request->input('sort')) : 'created_at';
|
||||||
$order = ($request->input('order') == 'asc') ? 'asc' : 'desc';
|
$order = ($request->input('order') == 'asc') ? 'asc' : 'desc';
|
||||||
$offset = request('offset', 0);
|
$offset = request('offset', 0);
|
||||||
|
@ -62,6 +62,5 @@ class ReportsController extends Controller
|
||||||
$actionlogs = $actionlogs->orderBy($sort, $order)->skip($offset)->take($limit)->get();
|
$actionlogs = $actionlogs->orderBy($sort, $order)->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return response()->json((new ActionlogsTransformer)->transformActionlogs($actionlogs, $total), 200, ['Content-Type' => 'application/json;charset=utf8'], JSON_UNESCAPED_UNICODE);
|
return response()->json((new ActionlogsTransformer)->transformActionlogs($actionlogs, $total), 200, ['Content-Type' => 'application/json;charset=utf8'], JSON_UNESCAPED_UNICODE);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,60 +4,59 @@ namespace App\Http\Controllers\Api;
|
||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Transformers\LoginAttemptsTransformer;
|
use App\Http\Transformers\LoginAttemptsTransformer;
|
||||||
|
use App\Models\Ldap;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Notifications\MailTest;
|
use App\Notifications\MailTest;
|
||||||
use App\Services\LdapAd;
|
use App\Services\LdapAd;
|
||||||
|
use GuzzleHttp\Client;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Notification;
|
use Illuminate\Support\Facades\Notification;
|
||||||
use GuzzleHttp\Client;
|
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator; // forward-port of v4 LDAP model for Sync
|
||||||
use App\Models\Ldap; // forward-port of v4 LDAP model for Sync
|
|
||||||
|
|
||||||
|
|
||||||
class SettingsController extends Controller
|
class SettingsController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the ldap settings
|
* Test the ldap settings
|
||||||
*
|
*
|
||||||
* @author Wes Hulette <jwhulette@gmail.com>
|
* @author Wes Hulette <jwhulette@gmail.com>
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*
|
*
|
||||||
* @param App\Models\LdapAd $ldap
|
* @param App\Models\LdapAd $ldap
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Http\JsonResponse
|
* @return \Illuminate\Http\JsonResponse
|
||||||
*/
|
*/
|
||||||
public function ldapAdSettingsTest(LdapAd $ldap): JsonResponse
|
public function ldapAdSettingsTest(LdapAd $ldap): JsonResponse
|
||||||
{
|
{
|
||||||
if(!$ldap->init()) {
|
if (! $ldap->init()) {
|
||||||
Log::info('LDAP is not enabled so we cannot test.');
|
Log::info('LDAP is not enabled so we cannot test.');
|
||||||
|
|
||||||
return response()->json(['message' => 'LDAP is not enabled, cannot test.'], 400);
|
return response()->json(['message' => 'LDAP is not enabled, cannot test.'], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The connect, bind and resulting users message
|
// The connect, bind and resulting users message
|
||||||
$message = [];
|
$message = [];
|
||||||
|
|
||||||
|
|
||||||
// This is all kinda fucked right now. The connection test doesn't actually do what you think,
|
// This is all kinda fucked right now. The connection test doesn't actually do what you think,
|
||||||
// // and the way we parse the errors
|
// // and the way we parse the errors
|
||||||
// on the JS side is horrible.
|
// on the JS side is horrible.
|
||||||
Log::info('Preparing to test LDAP user login');
|
Log::info('Preparing to test LDAP user login');
|
||||||
// Test user can connect to the LDAP server
|
// Test user can connect to the LDAP server
|
||||||
try {
|
try {
|
||||||
$ldap->testLdapAdUserConnection();
|
$ldap->testLdapAdUserConnection();
|
||||||
$message['login'] = [
|
$message['login'] = [
|
||||||
'message' => 'Successfully connected to LDAP server.'
|
'message' => 'Successfully connected to LDAP server.',
|
||||||
];
|
];
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
\Log::debug('Connection to LDAP server '.Setting::getSettings()->ldap_server.' failed. Please check your LDAP settings and try again. Server Responded with error: ' . $ex->getMessage());
|
\Log::debug('Connection to LDAP server '.Setting::getSettings()->ldap_server.' failed. Please check your LDAP settings and try again. Server Responded with error: '.$ex->getMessage());
|
||||||
|
|
||||||
return response()->json(
|
return response()->json(
|
||||||
['message' => 'Connection to LDAP server '.Setting::getSettings()->ldap_server." failed. Verify that the LDAP hostname is entered correctly and that it can be reached from this web server. \n\nServer Responded with error: " . $ex->getMessage()
|
['message' => 'Connection to LDAP server '.Setting::getSettings()->ldap_server." failed. Verify that the LDAP hostname is entered correctly and that it can be reached from this web server. \n\nServer Responded with error: ".$ex->getMessage(),
|
||||||
|
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
@ -68,15 +67,15 @@ class SettingsController extends Controller
|
||||||
Log::info('Testing Bind');
|
Log::info('Testing Bind');
|
||||||
$ldap->testLdapAdBindConnection();
|
$ldap->testLdapAdBindConnection();
|
||||||
$message['bind'] = [
|
$message['bind'] = [
|
||||||
'message' => 'Successfully bound to LDAP server.'
|
'message' => 'Successfully bound to LDAP server.',
|
||||||
];
|
];
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
Log::info('LDAP Bind failed');
|
Log::info('LDAP Bind failed');
|
||||||
return response()->json(['message' => 'Connection to LDAP successful, but we were unable to Bind the LDAP user '.Setting::getSettings()->ldap_uname.". Verify your that your LDAP Bind username and password are correct. \n\nServer Responded with error: " . $ex->getMessage()
|
|
||||||
|
return response()->json(['message' => 'Connection to LDAP successful, but we were unable to Bind the LDAP user '.Setting::getSettings()->ldap_uname.". Verify your that your LDAP Bind username and password are correct. \n\nServer Responded with error: ".$ex->getMessage(),
|
||||||
], 400);
|
], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Log::info('Preparing to get sample user set from LDAP directory');
|
Log::info('Preparing to get sample user set from LDAP directory');
|
||||||
// Get a sample of 10 users so user can verify the data is correct
|
// Get a sample of 10 users so user can verify the data is correct
|
||||||
$settings = Setting::getSettings();
|
$settings = Setting::getSettings();
|
||||||
|
@ -96,21 +95,22 @@ class SettingsController extends Controller
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
if ($users->count() > 0) {
|
if ($users->count() > 0) {
|
||||||
$message['user_sync'] = [
|
$message['user_sync'] = [
|
||||||
'users' => $users
|
'users' => $users,
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
$message['user_sync'] = [
|
$message['user_sync'] = [
|
||||||
'message' => 'Connection to LDAP was successful, however there were no users returned from your query. You should confirm the Base Bind DN above.'
|
'message' => 'Connection to LDAP was successful, however there were no users returned from your query. You should confirm the Base Bind DN above.',
|
||||||
];
|
];
|
||||||
|
|
||||||
return response()->json($message, 400);
|
return response()->json($message, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
Log::info('LDAP sync failed');
|
Log::info('LDAP sync failed');
|
||||||
$message['user_sync'] = [
|
$message['user_sync'] = [
|
||||||
'message' => 'Error getting users from LDAP directory, error: ' . $ex->getMessage()
|
'message' => 'Error getting users from LDAP directory, error: '.$ex->getMessage(),
|
||||||
];
|
];
|
||||||
|
|
||||||
return response()->json($message, 400);
|
return response()->json($message, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,25 +119,24 @@ class SettingsController extends Controller
|
||||||
|
|
||||||
public function ldaptestlogin(Request $request, LdapAd $ldap)
|
public function ldaptestlogin(Request $request, LdapAd $ldap)
|
||||||
{
|
{
|
||||||
|
if (Setting::getSettings()->ldap_enabled != '1') {
|
||||||
if (Setting::getSettings()->ldap_enabled!='1') {
|
|
||||||
\Log::debug('LDAP is not enabled. Cannot test.');
|
\Log::debug('LDAP is not enabled. Cannot test.');
|
||||||
|
|
||||||
return response()->json(['message' => 'LDAP is not enabled, cannot test.'], 400);
|
return response()->json(['message' => 'LDAP is not enabled, cannot test.'], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$rules = [
|
||||||
$rules = array(
|
|
||||||
'ldaptest_user' => 'required',
|
'ldaptest_user' => 'required',
|
||||||
'ldaptest_password' => 'required'
|
'ldaptest_password' => 'required',
|
||||||
);
|
];
|
||||||
|
|
||||||
$validator = Validator::make($request->all(), $rules);
|
$validator = Validator::make($request->all(), $rules);
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
\Log::debug('LDAP Validation test failed.');
|
\Log::debug('LDAP Validation test failed.');
|
||||||
$validation_errors = implode(' ',$validator->errors()->all());
|
$validation_errors = implode(' ', $validator->errors()->all());
|
||||||
|
|
||||||
return response()->json(['message' => $validator->errors()->all()], 400);
|
return response()->json(['message' => $validator->errors()->all()], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
\Log::debug('Preparing to test LDAP login');
|
\Log::debug('Preparing to test LDAP login');
|
||||||
try {
|
try {
|
||||||
|
@ -147,52 +146,48 @@ class SettingsController extends Controller
|
||||||
// can't do this because that's a protected property.
|
// can't do this because that's a protected property.
|
||||||
|
|
||||||
$results = $ldap->ldapLogin($request->input('ldaptest_user'), $request->input('ldaptest_password')); // this would normally create a user on success (if they didn't already exist), but for the transaction
|
$results = $ldap->ldapLogin($request->input('ldaptest_user'), $request->input('ldaptest_password')); // this would normally create a user on success (if they didn't already exist), but for the transaction
|
||||||
if($results) {
|
if ($results) {
|
||||||
return response()->json(['message' => 'It worked! '. $request->input('ldaptest_user').' successfully binded to LDAP.'], 200);
|
return response()->json(['message' => 'It worked! '.$request->input('ldaptest_user').' successfully binded to LDAP.'], 200);
|
||||||
} else {
|
} else {
|
||||||
return response()->json(['message' => 'Login Failed. '. $request->input('ldaptest_user').' did not successfully bind to LDAP.'], 400);
|
return response()->json(['message' => 'Login Failed. '.$request->input('ldaptest_user').' did not successfully bind to LDAP.'], 400);
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::debug('Connection failed');
|
\Log::debug('Connection failed');
|
||||||
|
|
||||||
return response()->json(['message' => $e->getMessage()], 400);
|
return response()->json(['message' => $e->getMessage()], 400);
|
||||||
} finally {
|
} finally {
|
||||||
DB::rollBack(); // ALWAYS rollback, whether success or failure
|
DB::rollBack(); // ALWAYS rollback, whether success or failure
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function slacktest(Request $request)
|
public function slacktest(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$slack = new Client([
|
$slack = new Client([
|
||||||
'base_url' => e($request->input('slack_endpoint')),
|
'base_url' => e($request->input('slack_endpoint')),
|
||||||
'defaults' => [
|
'defaults' => [
|
||||||
'exceptions' => false
|
'exceptions' => false,
|
||||||
]
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
$payload = json_encode(
|
$payload = json_encode(
|
||||||
[
|
[
|
||||||
'channel' => e($request->input('slack_channel')),
|
'channel' => e($request->input('slack_channel')),
|
||||||
'text' => trans('general.slack_test_msg'),
|
'text' => trans('general.slack_test_msg'),
|
||||||
'username' => e($request->input('slack_botname')),
|
'username' => e($request->input('slack_botname')),
|
||||||
'icon_emoji' => ':heart:'
|
'icon_emoji' => ':heart:',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$slack->post($request->input('slack_endpoint'),['body' => $payload]);
|
$slack->post($request->input('slack_endpoint'), ['body' => $payload]);
|
||||||
|
|
||||||
return response()->json(['message' => 'Success'], 200);
|
return response()->json(['message' => 'Success'], 200);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return response()->json(['message' => 'Oops! Please check the channel name and webhook endpoint URL. Slack responded with: '.$e->getMessage()], 400);
|
return response()->json(['message' => 'Oops! Please check the channel name and webhook endpoint URL. Slack responded with: '.$e->getMessage()], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['message' => 'Something went wrong :( '], 400);
|
return response()->json(['message' => 'Something went wrong :( '], 400);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the email configuration
|
* Test the email configuration
|
||||||
*
|
*
|
||||||
|
@ -202,19 +197,19 @@ class SettingsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function ajaxTestEmail()
|
public function ajaxTestEmail()
|
||||||
{
|
{
|
||||||
if (!config('app.lock_passwords')) {
|
if (! config('app.lock_passwords')) {
|
||||||
try {
|
try {
|
||||||
Notification::send(Setting::first(), new MailTest());
|
Notification::send(Setting::first(), new MailTest());
|
||||||
|
|
||||||
return response()->json(['message' => 'Mail sent to '.config('mail.reply_to.address')], 200);
|
return response()->json(['message' => 'Mail sent to '.config('mail.reply_to.address')], 200);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return response()->json(['message' => $e->getMessage()], 500);
|
return response()->json(['message' => $e->getMessage()], 500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['message' => 'Mail would have been sent, but this application is in demo mode! '], 200);
|
return response()->json(['message' => 'Mail would have been sent, but this application is in demo mode! '], 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete server-cached barcodes
|
* Delete server-cached barcodes
|
||||||
*
|
*
|
||||||
|
@ -224,23 +219,20 @@ class SettingsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function purgeBarcodes()
|
public function purgeBarcodes()
|
||||||
{
|
{
|
||||||
|
|
||||||
$file_count = 0;
|
$file_count = 0;
|
||||||
$files = Storage::disk('public')->files('barcodes');
|
$files = Storage::disk('public')->files('barcodes');
|
||||||
|
|
||||||
foreach ($files as $file) { // iterate files
|
foreach ($files as $file) { // iterate files
|
||||||
|
|
||||||
$file_parts = explode(".", $file);
|
$file_parts = explode('.', $file);
|
||||||
$extension = end($file_parts);
|
$extension = end($file_parts);
|
||||||
\Log::debug($extension);
|
\Log::debug($extension);
|
||||||
|
|
||||||
// Only generated barcodes would have a .png file extension
|
// Only generated barcodes would have a .png file extension
|
||||||
if ($extension =='png') {
|
if ($extension == 'png') {
|
||||||
|
|
||||||
\Log::debug('Deleting: '.$file);
|
\Log::debug('Deleting: '.$file);
|
||||||
|
|
||||||
|
try {
|
||||||
try {
|
|
||||||
Storage::disk('public')->delete($file);
|
Storage::disk('public')->delete($file);
|
||||||
\Log::debug('Deleting: '.$file);
|
\Log::debug('Deleting: '.$file);
|
||||||
$file_count++;
|
$file_count++;
|
||||||
|
@ -248,17 +240,11 @@ class SettingsController extends Controller
|
||||||
\Log::debug($e);
|
\Log::debug($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(['message' => 'Deleted '.$file_count.' barcodes'], 200);
|
return response()->json(['message' => 'Deleted '.$file_count.' barcodes'], 200);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of login attempts
|
* Get a list of login attempts
|
||||||
*
|
*
|
||||||
|
@ -269,20 +255,16 @@ class SettingsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function showLoginAttempts(Request $request)
|
public function showLoginAttempts(Request $request)
|
||||||
{
|
{
|
||||||
$allowed_columns = ['id', 'username', 'remote_ip', 'user_agent','successful','created_at'];
|
$allowed_columns = ['id', 'username', 'remote_ip', 'user_agent', 'successful', 'created_at'];
|
||||||
|
|
||||||
$login_attempts = DB::table('login_attempts');
|
$login_attempts = DB::table('login_attempts');
|
||||||
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
$order = $request->input('order') === 'asc' ? 'asc' : 'desc';
|
||||||
$sort = in_array($request->get('sort'), $allowed_columns) ? $request->get('sort') : 'created_at';
|
$sort = in_array($request->get('sort'), $allowed_columns) ? $request->get('sort') : 'created_at';
|
||||||
|
|
||||||
$total = $login_attempts->count();
|
$total = $login_attempts->count();
|
||||||
$login_attempts->orderBy($sort, $order);
|
$login_attempts->orderBy($sort, $order);
|
||||||
$login_attempt_results = $login_attempts->skip(request('offset', 0))->take(request('limit', 20))->get();
|
$login_attempt_results = $login_attempts->skip(request('offset', 0))->take(request('limit', 20))->get();
|
||||||
|
|
||||||
return (new LoginAttemptsTransformer)->transformLoginAttempts($login_attempt_results, $total);
|
return (new LoginAttemptsTransformer)->transformLoginAttempts($login_attempt_results, $total);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ class StatuslabelsController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('view', Statuslabel::class);
|
$this->authorize('view', Statuslabel::class);
|
||||||
$allowed_columns = ['id','name','created_at', 'assets_count','color', 'notes','default_label'];
|
$allowed_columns = ['id', 'name', 'created_at', 'assets_count', 'color', 'notes', 'default_label'];
|
||||||
|
|
||||||
$statuslabels = Statuslabel::withCount('assets as assets_count');
|
$statuslabels = Statuslabel::withCount('assets as assets_count');
|
||||||
|
|
||||||
|
@ -43,6 +43,7 @@ class StatuslabelsController extends Controller
|
||||||
|
|
||||||
$total = $statuslabels->count();
|
$total = $statuslabels->count();
|
||||||
$statuslabels = $statuslabels->skip($offset)->take($limit)->get();
|
$statuslabels = $statuslabels->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new StatuslabelsTransformer)->transformStatuslabels($statuslabels, $total);
|
return (new StatuslabelsTransformer)->transformStatuslabels($statuslabels, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,25 +59,29 @@ class StatuslabelsController extends Controller
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('create', Statuslabel::class);
|
$this->authorize('create', Statuslabel::class);
|
||||||
$request->except('deployable', 'pending','archived');
|
$request->except('deployable', 'pending', 'archived');
|
||||||
|
|
||||||
if (!$request->filled('type')) {
|
if (! $request->filled('type')) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, ["type" => ["Status label type is required."]]),500);
|
return response()->json(Helper::formatStandardApiResponse('error', null, ['type' => ['Status label type is required.']]), 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
$statuslabel = new Statuslabel;
|
$statuslabel = new Statuslabel;
|
||||||
$statuslabel->fill($request->all());
|
$statuslabel->fill($request->all());
|
||||||
|
|
||||||
$statusType = Statuslabel::getStatuslabelTypesForDB($request->input('type'));
|
$statusType = Statuslabel::getStatuslabelTypesForDB($request->input('type'));
|
||||||
$statuslabel->deployable = $statusType['deployable'];
|
$statuslabel->deployable = $statusType['deployable'];
|
||||||
$statuslabel->pending = $statusType['pending'];
|
$statuslabel->pending = $statusType['pending'];
|
||||||
$statuslabel->archived = $statusType['archived'];
|
$statuslabel->archived = $statusType['archived'];
|
||||||
|
$statuslabel->color = $request->input('color');
|
||||||
|
$statuslabel->show_in_nav = $request->input('show_in_nav', 0);
|
||||||
|
$statuslabel->default_label = $request->input('default_label', 0);
|
||||||
|
|
||||||
|
|
||||||
if ($statuslabel->save()) {
|
if ($statuslabel->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $statuslabel, trans('admin/statuslabels/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $statuslabel, trans('admin/statuslabels/message.create.success')));
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $statuslabel->getErrors()));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, $statuslabel->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -91,10 +96,10 @@ class StatuslabelsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Statuslabel::class);
|
$this->authorize('view', Statuslabel::class);
|
||||||
$statuslabel = Statuslabel::findOrFail($id);
|
$statuslabel = Statuslabel::findOrFail($id);
|
||||||
|
|
||||||
return (new StatuslabelsTransformer)->transformStatuslabel($statuslabel);
|
return (new StatuslabelsTransformer)->transformStatuslabel($statuslabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -109,18 +114,21 @@ class StatuslabelsController extends Controller
|
||||||
$this->authorize('update', Statuslabel::class);
|
$this->authorize('update', Statuslabel::class);
|
||||||
$statuslabel = Statuslabel::findOrFail($id);
|
$statuslabel = Statuslabel::findOrFail($id);
|
||||||
|
|
||||||
$request->except('deployable', 'pending','archived');
|
$request->except('deployable', 'pending', 'archived');
|
||||||
|
|
||||||
if (!$request->filled('type')) {
|
if (! $request->filled('type')) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'Status label type is required.'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'Status label type is required.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$statuslabel->fill($request->all());
|
$statuslabel->fill($request->all());
|
||||||
|
|
||||||
$statusType = Statuslabel::getStatuslabelTypesForDB($request->input('type'));
|
$statusType = Statuslabel::getStatuslabelTypesForDB($request->input('type'));
|
||||||
$statuslabel->deployable = $statusType['deployable'];
|
$statuslabel->deployable = $statusType['deployable'];
|
||||||
$statuslabel->pending = $statusType['pending'];
|
$statuslabel->pending = $statusType['pending'];
|
||||||
$statuslabel->archived = $statusType['archived'];
|
$statuslabel->archived = $statusType['archived'];
|
||||||
|
$statuslabel->color = $request->input('color');
|
||||||
|
$statuslabel->show_in_nav = $request->input('show_in_nav', 0);
|
||||||
|
$statuslabel->default_label = $request->input('default_label', 0);
|
||||||
|
|
||||||
if ($statuslabel->save()) {
|
if ($statuslabel->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $statuslabel, trans('admin/statuslabels/message.update.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $statuslabel, trans('admin/statuslabels/message.update.success')));
|
||||||
|
@ -146,15 +154,13 @@ class StatuslabelsController extends Controller
|
||||||
// Check that there are no assets associated
|
// Check that there are no assets associated
|
||||||
if ($statuslabel->assets()->count() == 0) {
|
if ($statuslabel->assets()->count() == 0) {
|
||||||
$statuslabel->delete();
|
$statuslabel->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/statuslabels/message.delete.success')));
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/statuslabels/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/statuslabels/message.assoc_assets')));
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/statuslabels/message.assoc_assets')));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show a count of assets by status label for pie chart
|
* Show a count of assets by status label for pie chart
|
||||||
*
|
*
|
||||||
|
@ -162,41 +168,40 @@ class StatuslabelsController extends Controller
|
||||||
* @since [v3.0]
|
* @since [v3.0]
|
||||||
* @return \Illuminate\Http\Response
|
* @return \Illuminate\Http\Response
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function getAssetCountByStatuslabel()
|
public function getAssetCountByStatuslabel()
|
||||||
{
|
{
|
||||||
$this->authorize('view', Statuslabel::class);
|
$this->authorize('view', Statuslabel::class);
|
||||||
|
|
||||||
$statuslabels = Statuslabel::withCount('assets')->get();
|
$statuslabels = Statuslabel::withCount('assets')->get();
|
||||||
|
|
||||||
$labels=[];
|
$labels = [];
|
||||||
$points=[];
|
$points = [];
|
||||||
$default_color_count = 0;
|
$default_color_count = 0;
|
||||||
$colors_array = array();
|
$colors_array = [];
|
||||||
|
|
||||||
foreach ($statuslabels as $statuslabel) {
|
foreach ($statuslabels as $statuslabel) {
|
||||||
if ($statuslabel->assets_count > 0) {
|
if ($statuslabel->assets_count > 0) {
|
||||||
|
$labels[] = $statuslabel->name.' ('.number_format($statuslabel->assets_count).')';
|
||||||
|
$points[] = $statuslabel->assets_count;
|
||||||
|
|
||||||
$labels[]=$statuslabel->name. ' ('.number_format($statuslabel->assets_count).')';
|
if ($statuslabel->color != '') {
|
||||||
$points[]=$statuslabel->assets_count;
|
|
||||||
|
|
||||||
if ($statuslabel->color!='') {
|
|
||||||
$colors_array[] = $statuslabel->color;
|
$colors_array[] = $statuslabel->color;
|
||||||
} else {
|
} else {
|
||||||
$colors_array[] = Helper::defaultChartColors($default_color_count);
|
$colors_array[] = Helper::defaultChartColors($default_color_count);
|
||||||
$default_color_count++;
|
|
||||||
}
|
}
|
||||||
|
$default_color_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$result= [
|
$result = [
|
||||||
"labels" => $labels,
|
'labels' => $labels,
|
||||||
"datasets" => [ [
|
'datasets' => [[
|
||||||
"data" => $points,
|
'data' => $points,
|
||||||
"backgroundColor" => $colors_array,
|
'backgroundColor' => $colors_array,
|
||||||
"hoverBackgroundColor" => $colors_array
|
'hoverBackgroundColor' => $colors_array,
|
||||||
]]
|
]],
|
||||||
];
|
];
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +217,7 @@ class StatuslabelsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Statuslabel::class);
|
$this->authorize('view', Statuslabel::class);
|
||||||
$this->authorize('index', Asset::class);
|
$this->authorize('index', Asset::class);
|
||||||
$assets = Asset::where('status_id','=',$id)->with('assignedTo');
|
$assets = Asset::where('status_id', '=', $id)->with('assignedTo');
|
||||||
|
|
||||||
$allowed_columns = [
|
$allowed_columns = [
|
||||||
'id',
|
'id',
|
||||||
|
@ -242,11 +247,12 @@ class StatuslabelsController extends Controller
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v4.0]
|
* @since [v4.0]
|
||||||
* @return Bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function checkIfDeployable($id) {
|
public function checkIfDeployable($id)
|
||||||
|
{
|
||||||
$statuslabel = Statuslabel::findOrFail($id);
|
$statuslabel = Statuslabel::findOrFail($id);
|
||||||
if ($statuslabel->getStatuslabelType()=='deployable') {
|
if ($statuslabel->getStatuslabelType() == 'deployable') {
|
||||||
return '1';
|
return '1';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,10 @@ class SuppliersController extends Controller
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$this->authorize('view', Supplier::class);
|
$this->authorize('view', Supplier::class);
|
||||||
$allowed_columns = ['id','name','address','phone','contact','fax','email','image','assets_count','licenses_count', 'accessories_count','url'];
|
$allowed_columns = ['id', 'name', 'address', 'phone', 'contact', 'fax', 'email', 'image', 'assets_count', 'licenses_count', 'accessories_count', 'url'];
|
||||||
|
|
||||||
$suppliers = Supplier::select(
|
$suppliers = Supplier::select(
|
||||||
array('id','name','address','address2','city','state','country','fax', 'phone','email','contact','created_at','updated_at','deleted_at','image','notes')
|
['id', 'name', 'address', 'address2', 'city', 'state', 'country', 'fax', 'phone', 'email', 'contact', 'created_at', 'updated_at', 'deleted_at', 'image', 'notes']
|
||||||
)->withCount('assets as assets_count')->withCount('licenses as licenses_count')->withCount('accessories as accessories_count');
|
)->withCount('assets as assets_count')->withCount('licenses as licenses_count')->withCount('accessories as accessories_count');
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,6 +47,7 @@ class SuppliersController extends Controller
|
||||||
|
|
||||||
$total = $suppliers->count();
|
$total = $suppliers->count();
|
||||||
$suppliers = $suppliers->skip($offset)->take($limit)->get();
|
$suppliers = $suppliers->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new SuppliersTransformer)->transformSuppliers($suppliers, $total);
|
return (new SuppliersTransformer)->transformSuppliers($suppliers, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,8 +70,8 @@ class SuppliersController extends Controller
|
||||||
if ($supplier->save()) {
|
if ($supplier->save()) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', $supplier, trans('admin/suppliers/message.create.success')));
|
return response()->json(Helper::formatStandardApiResponse('success', $supplier, trans('admin/suppliers/message.create.success')));
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $supplier->getErrors()));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, $supplier->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,10 +86,10 @@ class SuppliersController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Supplier::class);
|
$this->authorize('view', Supplier::class);
|
||||||
$supplier = Supplier::findOrFail($id);
|
$supplier = Supplier::findOrFail($id);
|
||||||
|
|
||||||
return (new SuppliersTransformer)->transformSupplier($supplier);
|
return (new SuppliersTransformer)->transformSupplier($supplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
@ -123,16 +124,15 @@ class SuppliersController extends Controller
|
||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
$this->authorize('delete', Supplier::class);
|
$this->authorize('delete', Supplier::class);
|
||||||
$supplier = Supplier::with('asset_maintenances', 'assets', 'licenses')->withCount('asset_maintenances as asset_maintenances_count','assets as assets_count', 'licenses as licenses_count')->findOrFail($id);
|
$supplier = Supplier::with('asset_maintenances', 'assets', 'licenses')->withCount('asset_maintenances as asset_maintenances_count', 'assets as assets_count', 'licenses as licenses_count')->findOrFail($id);
|
||||||
$this->authorize('delete', $supplier);
|
$this->authorize('delete', $supplier);
|
||||||
|
|
||||||
|
|
||||||
if ($supplier->assets_count > 0) {
|
if ($supplier->assets_count > 0) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/suppliers/message.delete.assoc_assets', ['asset_count' => (int) $supplier->assets_count])));
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/suppliers/message.delete.assoc_assets', ['asset_count' => (int) $supplier->assets_count])));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($supplier->asset_maintenances_count > 0) {
|
if ($supplier->asset_maintenances_count > 0) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/suppliers/message.delete.assoc_maintenances', ['asset_maintenances_count' => $supplier->asset_maintenances_count])));
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/suppliers/message.delete.assoc_maintenances', ['asset_maintenances_count' => $supplier->asset_maintenances_count])));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($supplier->licenses_count > 0) {
|
if ($supplier->licenses_count > 0) {
|
||||||
|
@ -140,8 +140,8 @@ class SuppliersController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$supplier->delete();
|
$supplier->delete();
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/suppliers/message.delete.success')));
|
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/suppliers/message.delete.success')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,11 +150,9 @@ class SuppliersController extends Controller
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v4.0.16]
|
* @since [v4.0.16]
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function selectlist(Request $request)
|
public function selectlist(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$suppliers = Supplier::select([
|
$suppliers = Supplier::select([
|
||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
|
@ -176,7 +174,5 @@ class SuppliersController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new SelectlistTransformer)->transformSelectlist($suppliers);
|
return (new SelectlistTransformer)->transformSelectlist($suppliers);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,17 +64,21 @@ class UsersController extends Controller
|
||||||
'users.zip',
|
'users.zip',
|
||||||
'users.ldap_import',
|
'users.ldap_import',
|
||||||
|
|
||||||
])->with('manager', 'groups', 'userloc', 'company', 'department','assets','licenses','accessories','consumables')
|
])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables')
|
||||||
->withCount('assets as assets_count','licenses as licenses_count','accessories as accessories_count','consumables as consumables_count');
|
->withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count');
|
||||||
$users = Company::scopeCompanyables($users);
|
$users = Company::scopeCompanyables($users);
|
||||||
|
|
||||||
|
|
||||||
if (($request->filled('deleted')) && ($request->input('deleted')=='true')) {
|
if (($request->filled('deleted')) && ($request->input('deleted') == 'true')) {
|
||||||
$users = $users->onlyTrashed();
|
$users = $users->onlyTrashed();
|
||||||
} elseif (($request->filled('all')) && ($request->input('all')=='true')) {
|
} elseif (($request->filled('all')) && ($request->input('all') == 'true')) {
|
||||||
$users = $users->withTrashed();
|
$users = $users->withTrashed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->filled('activated')) {
|
||||||
|
$users = $users->where('users.activated', '=', $request->input('activated'));
|
||||||
|
}
|
||||||
|
|
||||||
if ($request->filled('company_id')) {
|
if ($request->filled('company_id')) {
|
||||||
$users = $users->where('users.company_id', '=', $request->input('company_id'));
|
$users = $users->where('users.company_id', '=', $request->input('company_id'));
|
||||||
}
|
}
|
||||||
|
@ -91,12 +95,40 @@ class UsersController extends Controller
|
||||||
$users = $users->where('users.username', '=', $request->input('username'));
|
$users = $users->where('users.username', '=', $request->input('username'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->filled('first_name')) {
|
||||||
|
$users = $users->where('users.first_name', '=', $request->input('first_name'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->filled('last_name')) {
|
||||||
|
$users = $users->where('users.last_name', '=', $request->input('last_name'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->filled('employee_num')) {
|
||||||
|
$users = $users->where('users.employee_num', '=', $request->input('employee_num'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->filled('state')) {
|
||||||
|
$users = $users->where('users.state', '=', $request->input('state'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->filled('country')) {
|
||||||
|
$users = $users->where('users.country', '=', $request->input('country'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->filled('zip')) {
|
||||||
|
$users = $users->where('users.zip', '=', $request->input('zip'));
|
||||||
|
}
|
||||||
|
|
||||||
if ($request->filled('group_id')) {
|
if ($request->filled('group_id')) {
|
||||||
$users = $users->ByGroup($request->get('group_id'));
|
$users = $users->ByGroup($request->get('group_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('department_id')) {
|
if ($request->filled('department_id')) {
|
||||||
$users = $users->where('users.department_id','=',$request->input('department_id'));
|
$users = $users->where('users.department_id', '=', $request->input('department_id'));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->filled('manager_id')) {
|
||||||
|
$users = $users->where('users.manager_id','=',$request->input('manager_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('search')) {
|
if ($request->filled('search')) {
|
||||||
|
@ -130,11 +162,11 @@ class UsersController extends Controller
|
||||||
default:
|
default:
|
||||||
$allowed_columns =
|
$allowed_columns =
|
||||||
[
|
[
|
||||||
'last_name','first_name','email','jobtitle','username','employee_num',
|
'last_name', 'first_name', 'email', 'jobtitle', 'username', 'employee_num',
|
||||||
'assets','accessories', 'consumables','licenses','groups','activated','created_at',
|
'assets', 'accessories', 'consumables', 'licenses', 'groups', 'activated', 'created_at',
|
||||||
'two_factor_enrolled','two_factor_optin','last_login', 'assets_count', 'licenses_count',
|
'two_factor_enrolled', 'two_factor_optin', 'last_login', 'assets_count', 'licenses_count',
|
||||||
'consumables_count', 'accessories_count', 'phone', 'address', 'city', 'state',
|
'consumables_count', 'accessories_count', 'phone', 'address', 'city', 'state',
|
||||||
'country', 'zip', 'id', 'ldap_import'
|
'country', 'zip', 'id', 'ldap_import',
|
||||||
];
|
];
|
||||||
|
|
||||||
$sort = in_array($request->get('sort'), $allowed_columns) ? $request->get('sort') : 'first_name';
|
$sort = in_array($request->get('sort'), $allowed_columns) ? $request->get('sort') : 'first_name';
|
||||||
|
@ -142,24 +174,21 @@ class UsersController extends Controller
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$total = $users->count();
|
$total = $users->count();
|
||||||
$users = $users->skip($offset)->take($limit)->get();
|
$users = $users->skip($offset)->take($limit)->get();
|
||||||
|
|
||||||
return (new UsersTransformer)->transformUsers($users, $total);
|
return (new UsersTransformer)->transformUsers($users, $total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a paginated collection for the select2 menus
|
* Gets a paginated collection for the select2 menus
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v4.0.16]
|
* @since [v4.0.16]
|
||||||
* @see \App\Http\Transformers\SelectlistTransformer
|
* @see \App\Http\Transformers\SelectlistTransformer
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public function selectlist(Request $request)
|
public function selectlist(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$users = User::select(
|
$users = User::select(
|
||||||
[
|
[
|
||||||
'users.id',
|
'users.id',
|
||||||
|
@ -186,16 +215,16 @@ class UsersController extends Controller
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$name_str = '';
|
$name_str = '';
|
||||||
if ($user->last_name!='') {
|
if ($user->last_name != '') {
|
||||||
$name_str .= $user->last_name.', ';
|
$name_str .= $user->last_name.', ';
|
||||||
}
|
}
|
||||||
$name_str .= $user->first_name;
|
$name_str .= $user->first_name;
|
||||||
|
|
||||||
if ($user->username!='') {
|
if ($user->username != '') {
|
||||||
$name_str .= ' ('.$user->username.')';
|
$name_str .= ' ('.$user->username.')';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user->employee_num!='') {
|
if ($user->employee_num != '') {
|
||||||
$name_str .= ' - #'.$user->employee_num;
|
$name_str .= ' - #'.$user->employee_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +233,6 @@ class UsersController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return (new SelectlistTransformer)->transformSelectlist($users);
|
return (new SelectlistTransformer)->transformSelectlist($users);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -225,17 +253,16 @@ class UsersController extends Controller
|
||||||
$user->fill($request->all());
|
$user->fill($request->all());
|
||||||
|
|
||||||
if ($request->has('permissions')) {
|
if ($request->has('permissions')) {
|
||||||
|
|
||||||
$permissions_array = $request->input('permissions');
|
$permissions_array = $request->input('permissions');
|
||||||
|
|
||||||
// Strip out the superuser permission if the API user isn't a superadmin
|
// Strip out the superuser permission if the API user isn't a superadmin
|
||||||
if (!Auth::user()->isSuperUser()) {
|
if (! Auth::user()->isSuperUser()) {
|
||||||
unset($permissions_array['superuser']);
|
unset($permissions_array['superuser']);
|
||||||
}
|
}
|
||||||
$user->permissions = $permissions_array;
|
$user->permissions = $permissions_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
$tmp_pass = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20);
|
$tmp_pass = substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 20);
|
||||||
$user->password = bcrypt($request->get('password', $tmp_pass));
|
$user->password = bcrypt($request->get('password', $tmp_pass));
|
||||||
|
|
||||||
app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar');
|
app('App\Http\Requests\ImageUploadRequest')->handleImages($user, 600, 'image', 'avatars', 'avatar');
|
||||||
|
@ -244,11 +271,12 @@ class UsersController extends Controller
|
||||||
if ($request->filled('groups')) {
|
if ($request->filled('groups')) {
|
||||||
$user->groups()->sync($request->input('groups'));
|
$user->groups()->sync($request->input('groups'));
|
||||||
} else {
|
} else {
|
||||||
$user->groups()->sync(array());
|
$user->groups()->sync([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', (new UsersTransformer)->transformUser($user), trans('admin/users/message.success.create')));
|
return response()->json(Helper::formatStandardApiResponse('success', (new UsersTransformer)->transformUser($user), trans('admin/users/message.success.create')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, $user->getErrors()));
|
return response()->json(Helper::formatStandardApiResponse('error', null, $user->getErrors()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +290,8 @@ class UsersController extends Controller
|
||||||
public function show($id)
|
public function show($id)
|
||||||
{
|
{
|
||||||
$this->authorize('view', User::class);
|
$this->authorize('view', User::class);
|
||||||
$user = User::withCount('assets as assets_count','licenses as licenses_count','accessories as accessories_count','consumables as consumables_count')->findOrFail($id);
|
$user = User::withCount('assets as assets_count', 'licenses as licenses_count', 'accessories as accessories_count', 'consumables as consumables_count')->findOrFail($id);
|
||||||
|
|
||||||
return (new UsersTransformer)->transformUser($user);
|
return (new UsersTransformer)->transformUser($user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,9 +311,15 @@ class UsersController extends Controller
|
||||||
|
|
||||||
$user = User::findOrFail($id);
|
$user = User::findOrFail($id);
|
||||||
|
|
||||||
// This is a janky hack to prevent people from changing admin demo user data on the public demo.
|
/**
|
||||||
// The $ids 1 and 2 are special since they are seeded as superadmins in the demo seeder.
|
* This is a janky hack to prevent people from changing admin demo user data on the public demo.
|
||||||
// Thanks, jerks. You are why we can't have nice things. - snipe
|
*
|
||||||
|
* The $ids 1 and 2 are special since they are seeded as superadmins in the demo seeder.
|
||||||
|
*
|
||||||
|
* Thanks, jerks. You are why we can't have nice things. - snipe
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
if ((($id == 1) || ($id == 2)) && (config('app.lock_passwords'))) {
|
if ((($id == 1) || ($id == 2)) && (config('app.lock_passwords'))) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'Permission denied. You cannot update user information via API on the demo.'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'Permission denied. You cannot update user information via API on the demo.'));
|
||||||
|
@ -305,19 +340,17 @@ class UsersController extends Controller
|
||||||
// here because we need to overwrite permissions
|
// here because we need to overwrite permissions
|
||||||
// if someone needs to null them out
|
// if someone needs to null them out
|
||||||
if ($request->has('permissions')) {
|
if ($request->has('permissions')) {
|
||||||
|
|
||||||
$permissions_array = $request->input('permissions');
|
$permissions_array = $request->input('permissions');
|
||||||
|
|
||||||
// Strip out the superuser permission if the API user isn't a superadmin
|
// Strip out the superuser permission if the API user isn't a superadmin
|
||||||
if (!Auth::user()->isSuperUser()) {
|
if (! Auth::user()->isSuperUser()) {
|
||||||
unset($permissions_array['superuser']);
|
unset($permissions_array['superuser']);
|
||||||
}
|
}
|
||||||
$user->permissions = $permissions_array;
|
$user->permissions = $permissions_array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Update the location of any assets checked out to this user
|
// Update the location of any assets checked out to this user
|
||||||
Asset::where('assigned_type', User::class)
|
Asset::where('assigned_type', User::class)
|
||||||
->where('assigned_to', $user->id)->update(['location_id' => $request->input('location_id', null)]);
|
->where('assigned_to', $user->id)->update(['location_id' => $request->input('location_id', null)]);
|
||||||
|
@ -337,8 +370,8 @@ class UsersController extends Controller
|
||||||
if ($request->filled('groups')) {
|
if ($request->filled('groups')) {
|
||||||
$user->groups()->sync($request->input('groups'));
|
$user->groups()->sync($request->input('groups'));
|
||||||
// The groups field has been passed but it is null, so we should blank it out
|
// The groups field has been passed but it is null, so we should blank it out
|
||||||
} elseif ($request->has('groups')) {
|
} elseif ($request->has('groups')) {
|
||||||
$user->groups()->sync(array());
|
$user->groups()->sync([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -362,36 +395,37 @@ class UsersController extends Controller
|
||||||
$user = User::findOrFail($id);
|
$user = User::findOrFail($id);
|
||||||
$this->authorize('delete', $user);
|
$this->authorize('delete', $user);
|
||||||
|
|
||||||
|
|
||||||
if (($user->assets) && ($user->assets->count() > 0)) {
|
if (($user->assets) && ($user->assets->count() > 0)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.error.delete_has_assets')));
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.error.delete_has_assets')));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($user->licenses) && ($user->licenses->count() > 0)) {
|
if (($user->licenses) && ($user->licenses->count() > 0)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'This user still has ' . $user->licenses->count() . ' license(s) associated with them and cannot be deleted.'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'This user still has '.$user->licenses->count().' license(s) associated with them and cannot be deleted.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($user->accessories) && ($user->accessories->count() > 0)) {
|
if (($user->accessories) && ($user->accessories->count() > 0)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'This user still has ' . $user->accessories->count() . ' accessories associated with them.'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'This user still has '.$user->accessories->count().' accessories associated with them.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($user->managedLocations()) && ($user->managedLocations()->count() > 0)) {
|
if (($user->managedLocations()) && ($user->managedLocations()->count() > 0)) {
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, 'This user still has ' . $user->managedLocations()->count() . ' locations that they manage.'));
|
return response()->json(Helper::formatStandardApiResponse('error', null, 'This user still has '.$user->managedLocations()->count().' locations that they manage.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($user->delete()) {
|
if ($user->delete()) {
|
||||||
|
|
||||||
// Remove the user's avatar if they have one
|
// Remove the user's avatar if they have one
|
||||||
if (Storage::disk('public')->exists('avatars/'.$user->avatar)) {
|
if (Storage::disk('public')->exists('avatars/'.$user->avatar)) {
|
||||||
try {
|
try {
|
||||||
Storage::disk('public')->delete('avatars/'.$user->avatar);
|
Storage::disk('public')->delete('avatars/'.$user->avatar);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::debug($e);
|
\Log::debug($e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/users/message.success.delete')));
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/users/message.success.delete')));
|
||||||
}
|
}
|
||||||
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.error.delete')));
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.error.delete')));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -402,12 +436,13 @@ class UsersController extends Controller
|
||||||
* @param $userId
|
* @param $userId
|
||||||
* @return string JSON
|
* @return string JSON
|
||||||
*/
|
*/
|
||||||
public function assets($id)
|
public function assets(Request $request, $id)
|
||||||
{
|
{
|
||||||
$this->authorize('view', User::class);
|
$this->authorize('view', User::class);
|
||||||
$this->authorize('view', Asset::class);
|
$this->authorize('view', Asset::class);
|
||||||
$assets = Asset::where('assigned_to', '=', $id)->where('assigned_type', '=', User::class)->with('model')->get();
|
$assets = Asset::where('assigned_to', '=', $id)->where('assigned_type', '=', User::class)->with('model')->get();
|
||||||
return (new AssetsTransformer)->transformAssets($assets, $assets->count());
|
|
||||||
|
return (new AssetsTransformer)->transformAssets($assets, $assets->count(), $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -424,6 +459,7 @@ class UsersController extends Controller
|
||||||
$user = User::findOrFail($id);
|
$user = User::findOrFail($id);
|
||||||
$this->authorize('view', Accessory::class);
|
$this->authorize('view', Accessory::class);
|
||||||
$accessories = $user->accessories;
|
$accessories = $user->accessories;
|
||||||
|
|
||||||
return (new AccessoriesTransformer)->transformAccessories($accessories, $accessories->count());
|
return (new AccessoriesTransformer)->transformAccessories($accessories, $accessories->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -441,12 +477,11 @@ class UsersController extends Controller
|
||||||
$this->authorize('view', License::class);
|
$this->authorize('view', License::class);
|
||||||
$user = User::where('id', $id)->withTrashed()->first();
|
$user = User::where('id', $id)->withTrashed()->first();
|
||||||
$licenses = $user->licenses()->get();
|
$licenses = $user->licenses()->get();
|
||||||
|
|
||||||
return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count());
|
return (new LicensesTransformer())->transformLicenses($licenses, $licenses->count());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
|
|
||||||
* Reset the user's two-factor status
|
* Reset the user's two-factor status
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
@ -456,7 +491,6 @@ class UsersController extends Controller
|
||||||
*/
|
*/
|
||||||
public function postTwoFactorReset(Request $request)
|
public function postTwoFactorReset(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->authorize('update', User::class);
|
$this->authorize('update', User::class);
|
||||||
|
|
||||||
if ($request->filled('id')) {
|
if ($request->filled('id')) {
|
||||||
|
@ -465,6 +499,7 @@ class UsersController extends Controller
|
||||||
$user->two_factor_secret = null;
|
$user->two_factor_secret = null;
|
||||||
$user->two_factor_enrolled = 0;
|
$user->two_factor_enrolled = 0;
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
return response()->json(['message' => trans('admin/settings/general.two_factor_reset_success')], 200);
|
return response()->json(['message' => trans('admin/settings/general.two_factor_reset_success')], 200);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return response()->json(['message' => trans('admin/settings/general.two_factor_reset_error')], 500);
|
return response()->json(['message' => trans('admin/settings/general.two_factor_reset_error')], 500);
|
||||||
|
@ -472,6 +507,7 @@ class UsersController extends Controller
|
||||||
}
|
}
|
||||||
return response()->json(['message' => 'No ID provided'], 500);
|
return response()->json(['message' => 'No ID provided'], 500);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -486,4 +522,28 @@ class UsersController extends Controller
|
||||||
{
|
{
|
||||||
return (new UsersTransformer)->transformUser($request->user());
|
return (new UsersTransformer)->transformUser($request->user());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore a soft-deleted user.
|
||||||
|
*
|
||||||
|
* @author [E. Taylor] [<dev@evantaylor.name>]
|
||||||
|
* @param int $userId
|
||||||
|
* @since [v6.0.0]
|
||||||
|
* @return JsonResponse
|
||||||
|
*/
|
||||||
|
public function restore($userId = null)
|
||||||
|
{
|
||||||
|
// Get asset information
|
||||||
|
$user = User::withTrashed()->find($userId);
|
||||||
|
$this->authorize('delete', $user);
|
||||||
|
if (isset($user->id)) {
|
||||||
|
// Restore the user
|
||||||
|
User::withTrashed()->where('id', $userId)->restore();
|
||||||
|
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('success', null, trans('admin/users/message.success.restored')));
|
||||||
|
}
|
||||||
|
|
||||||
|
$id = $userId;
|
||||||
|
return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.user_not_found', compact('id'))), 200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
@ -21,7 +22,6 @@ use View;
|
||||||
*/
|
*/
|
||||||
class AssetMaintenancesController extends Controller
|
class AssetMaintenancesController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for permissions for this action.
|
* Checks for permissions for this action.
|
||||||
*
|
*
|
||||||
|
@ -53,8 +53,6 @@ class AssetMaintenancesController extends Controller
|
||||||
return view('asset_maintenances/index');
|
return view('asset_maintenances/index');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a form view to create a new asset maintenance.
|
* Returns a form view to create a new asset maintenance.
|
||||||
*
|
*
|
||||||
|
@ -100,28 +98,28 @@ class AssetMaintenancesController extends Controller
|
||||||
$assetMaintenance = new AssetMaintenance();
|
$assetMaintenance = new AssetMaintenance();
|
||||||
$assetMaintenance->supplier_id = $request->input('supplier_id');
|
$assetMaintenance->supplier_id = $request->input('supplier_id');
|
||||||
$assetMaintenance->is_warranty = $request->input('is_warranty');
|
$assetMaintenance->is_warranty = $request->input('is_warranty');
|
||||||
$assetMaintenance->cost = $request->input('cost');
|
$assetMaintenance->cost = Helper::ParseCurrency($request->input('cost'));
|
||||||
$assetMaintenance->notes = $request->input('notes');
|
$assetMaintenance->notes = $request->input('notes');
|
||||||
$asset = Asset::find($request->input('asset_id'));
|
$asset = Asset::find($request->input('asset_id'));
|
||||||
|
|
||||||
if ((!Company::isCurrentUserHasAccess($asset)) && ($asset!=null)) {
|
if ((! Company::isCurrentUserHasAccess($asset)) && ($asset != null)) {
|
||||||
return static::getInsufficientPermissionsRedirect();
|
return static::getInsufficientPermissionsRedirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the asset maintenance data
|
// Save the asset maintenance data
|
||||||
$assetMaintenance->asset_id = $request->input('asset_id');
|
$assetMaintenance->asset_id = $request->input('asset_id');
|
||||||
$assetMaintenance->asset_maintenance_type = $request->input('asset_maintenance_type');
|
$assetMaintenance->asset_maintenance_type = $request->input('asset_maintenance_type');
|
||||||
$assetMaintenance->title = $request->input('title');
|
$assetMaintenance->title = $request->input('title');
|
||||||
$assetMaintenance->start_date = $request->input('start_date');
|
$assetMaintenance->start_date = $request->input('start_date');
|
||||||
$assetMaintenance->completion_date = $request->input('completion_date');
|
$assetMaintenance->completion_date = $request->input('completion_date');
|
||||||
$assetMaintenance->user_id = Auth::id();
|
$assetMaintenance->user_id = Auth::id();
|
||||||
|
|
||||||
if (( $assetMaintenance->completion_date !== null )
|
if (($assetMaintenance->completion_date !== null)
|
||||||
&& ( $assetMaintenance->start_date !== "" )
|
&& ($assetMaintenance->start_date !== '')
|
||||||
&& ( $assetMaintenance->start_date !== "0000-00-00" )
|
&& ($assetMaintenance->start_date !== '0000-00-00')
|
||||||
) {
|
) {
|
||||||
$startDate = Carbon::parse($assetMaintenance->start_date);
|
$startDate = Carbon::parse($assetMaintenance->start_date);
|
||||||
$completionDate = Carbon::parse($assetMaintenance->completion_date);
|
$completionDate = Carbon::parse($assetMaintenance->completion_date);
|
||||||
$assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
|
$assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,7 +131,6 @@ class AssetMaintenancesController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()->withInput()->withErrors($assetMaintenance->getErrors());
|
return redirect()->back()->withInput()->withErrors($assetMaintenance->getErrors());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,11 +150,10 @@ class AssetMaintenancesController extends Controller
|
||||||
// Redirect to the improvement management page
|
// Redirect to the improvement management page
|
||||||
return redirect()->route('maintenances.index')
|
return redirect()->route('maintenances.index')
|
||||||
->with('error', trans('admin/asset_maintenances/message.not_found'));
|
->with('error', trans('admin/asset_maintenances/message.not_found'));
|
||||||
} elseif (!$assetMaintenance->asset) {
|
} elseif (! $assetMaintenance->asset) {
|
||||||
return redirect()->route('maintenances.index')
|
return redirect()->route('maintenances.index')
|
||||||
->with('error', 'The asset associated with this maintenance does not exist.');
|
->with('error', 'The asset associated with this maintenance does not exist.');
|
||||||
|
} elseif (! Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
||||||
} elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
|
||||||
return static::getInsufficientPermissionsRedirect();
|
return static::getInsufficientPermissionsRedirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +180,6 @@ class AssetMaintenancesController extends Controller
|
||||||
->with('selectedAsset', null)
|
->with('selectedAsset', null)
|
||||||
->with('assetMaintenanceType', $assetMaintenanceType)
|
->with('assetMaintenanceType', $assetMaintenanceType)
|
||||||
->with('item', $assetMaintenance);
|
->with('item', $assetMaintenance);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -205,43 +200,43 @@ class AssetMaintenancesController extends Controller
|
||||||
// Redirect to the asset maintenance management page
|
// Redirect to the asset maintenance management page
|
||||||
return redirect()->route('maintenances.index')
|
return redirect()->route('maintenances.index')
|
||||||
->with('error', trans('admin/asset_maintenances/message.not_found'));
|
->with('error', trans('admin/asset_maintenances/message.not_found'));
|
||||||
} elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
} elseif (! Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
||||||
return static::getInsufficientPermissionsRedirect();
|
return static::getInsufficientPermissionsRedirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
$assetMaintenance->supplier_id = e($request->input('supplier_id'));
|
$assetMaintenance->supplier_id = $request->input('supplier_id');
|
||||||
$assetMaintenance->is_warranty = e($request->input('is_warranty'));
|
$assetMaintenance->is_warranty = $request->input('is_warranty');
|
||||||
$assetMaintenance->cost = Helper::ParseFloat(e($request->input('cost')));
|
$assetMaintenance->cost = Helper::ParseCurrency($request->input('cost'));
|
||||||
$assetMaintenance->notes = e($request->input('notes'));
|
$assetMaintenance->notes = $request->input('notes');
|
||||||
|
|
||||||
$asset = Asset::find(request('asset_id'));
|
$asset = Asset::find(request('asset_id'));
|
||||||
|
|
||||||
if (!Company::isCurrentUserHasAccess($asset)) {
|
if (! Company::isCurrentUserHasAccess($asset)) {
|
||||||
return static::getInsufficientPermissionsRedirect();
|
return static::getInsufficientPermissionsRedirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the asset maintenance data
|
// Save the asset maintenance data
|
||||||
$assetMaintenance->asset_id = $request->input('asset_id');
|
$assetMaintenance->asset_id = $request->input('asset_id');
|
||||||
$assetMaintenance->asset_maintenance_type = $request->input('asset_maintenance_type');
|
$assetMaintenance->asset_maintenance_type = $request->input('asset_maintenance_type');
|
||||||
$assetMaintenance->title = $request->input('title');
|
$assetMaintenance->title = $request->input('title');
|
||||||
$assetMaintenance->start_date = $request->input('start_date');
|
$assetMaintenance->start_date = $request->input('start_date');
|
||||||
$assetMaintenance->completion_date = $request->input('completion_date');
|
$assetMaintenance->completion_date = $request->input('completion_date');
|
||||||
|
|
||||||
if (( $assetMaintenance->completion_date == null )
|
if (($assetMaintenance->completion_date == null)
|
||||||
) {
|
) {
|
||||||
if (( $assetMaintenance->asset_maintenance_time !== 0 )
|
if (($assetMaintenance->asset_maintenance_time !== 0)
|
||||||
|| ( !is_null($assetMaintenance->asset_maintenance_time) )
|
|| (! is_null($assetMaintenance->asset_maintenance_time))
|
||||||
) {
|
) {
|
||||||
$assetMaintenance->asset_maintenance_time = null;
|
$assetMaintenance->asset_maintenance_time = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (( $assetMaintenance->completion_date !== null )
|
if (($assetMaintenance->completion_date !== null)
|
||||||
&& ( $assetMaintenance->start_date !== "" )
|
&& ($assetMaintenance->start_date !== '')
|
||||||
&& ( $assetMaintenance->start_date !== "0000-00-00" )
|
&& ($assetMaintenance->start_date !== '0000-00-00')
|
||||||
) {
|
) {
|
||||||
$startDate = Carbon::parse($assetMaintenance->start_date);
|
$startDate = Carbon::parse($assetMaintenance->start_date);
|
||||||
$completionDate = Carbon::parse($assetMaintenance->completion_date);
|
$completionDate = Carbon::parse($assetMaintenance->completion_date);
|
||||||
$assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
|
$assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,6 +247,7 @@ class AssetMaintenancesController extends Controller
|
||||||
return redirect()->route('maintenances.index')
|
return redirect()->route('maintenances.index')
|
||||||
->with('success', trans('admin/asset_maintenances/message.edit.success'));
|
->with('success', trans('admin/asset_maintenances/message.edit.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()->withInput()->withErrors($assetMaintenance->getErrors());
|
return redirect()->back()->withInput()->withErrors($assetMaintenance->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +267,7 @@ class AssetMaintenancesController extends Controller
|
||||||
// Redirect to the asset maintenance management page
|
// Redirect to the asset maintenance management page
|
||||||
return redirect()->route('maintenances.index')
|
return redirect()->route('maintenances.index')
|
||||||
->with('error', trans('admin/asset_maintenances/message.not_found'));
|
->with('error', trans('admin/asset_maintenances/message.not_found'));
|
||||||
} elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
} elseif (! Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
||||||
return static::getInsufficientPermissionsRedirect();
|
return static::getInsufficientPermissionsRedirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +295,7 @@ class AssetMaintenancesController extends Controller
|
||||||
// Redirect to the asset maintenance management page
|
// Redirect to the asset maintenance management page
|
||||||
return redirect()->route('maintenances.index')
|
return redirect()->route('maintenances.index')
|
||||||
->with('error', trans('admin/asset_maintenances/message.not_found'));
|
->with('error', trans('admin/asset_maintenances/message.not_found'));
|
||||||
} elseif (!Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
} elseif (! Company::isCurrentUserHasAccess($assetMaintenance->asset)) {
|
||||||
return static::getInsufficientPermissionsRedirect();
|
return static::getInsufficientPermissionsRedirect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
@ -10,7 +11,6 @@ use Illuminate\Support\Facades\View;
|
||||||
use Redirect;
|
use Redirect;
|
||||||
use Request;
|
use Request;
|
||||||
use Storage;
|
use Storage;
|
||||||
|
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,6 +34,7 @@ class AssetModelsController extends Controller
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$this->authorize('index', AssetModel::class);
|
$this->authorize('index', AssetModel::class);
|
||||||
|
|
||||||
return view('models/index');
|
return view('models/index');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,12 +49,12 @@ class AssetModelsController extends Controller
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
$this->authorize('create', AssetModel::class);
|
$this->authorize('create', AssetModel::class);
|
||||||
|
|
||||||
return view('models/edit')->with('category_type', 'asset')
|
return view('models/edit')->with('category_type', 'asset')
|
||||||
->with('depreciation_list', Helper::depreciationList())
|
->with('depreciation_list', Helper::depreciationList())
|
||||||
->with('item', new AssetModel);
|
->with('item', new AssetModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate and process the new Asset Model data.
|
* Validate and process the new Asset Model data.
|
||||||
*
|
*
|
||||||
|
@ -65,7 +66,6 @@ class AssetModelsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function store(ImageUploadRequest $request)
|
public function store(ImageUploadRequest $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->authorize('create', AssetModel::class);
|
$this->authorize('create', AssetModel::class);
|
||||||
// Create a new asset model
|
// Create a new asset model
|
||||||
$model = new AssetModel;
|
$model = new AssetModel;
|
||||||
|
@ -73,29 +73,30 @@ class AssetModelsController extends Controller
|
||||||
// Save the model data
|
// Save the model data
|
||||||
$model->eol = $request->input('eol');
|
$model->eol = $request->input('eol');
|
||||||
$model->depreciation_id = $request->input('depreciation_id');
|
$model->depreciation_id = $request->input('depreciation_id');
|
||||||
$model->name = $request->input('name');
|
$model->name = $request->input('name');
|
||||||
$model->model_number = $request->input('model_number');
|
$model->model_number = $request->input('model_number');
|
||||||
$model->manufacturer_id = $request->input('manufacturer_id');
|
$model->manufacturer_id = $request->input('manufacturer_id');
|
||||||
$model->category_id = $request->input('category_id');
|
$model->category_id = $request->input('category_id');
|
||||||
$model->notes = $request->input('notes');
|
$model->notes = $request->input('notes');
|
||||||
$model->user_id = Auth::id();
|
$model->user_id = Auth::id();
|
||||||
$model->requestable = Request::has('requestable');
|
$model->requestable = Request::has('requestable');
|
||||||
|
|
||||||
if ($request->input('custom_fieldset')!='') {
|
if ($request->input('custom_fieldset') != '') {
|
||||||
$model->fieldset_id = e($request->input('custom_fieldset'));
|
$model->fieldset_id = e($request->input('custom_fieldset'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$model = $request->handleImages($model);
|
$model = $request->handleImages($model);
|
||||||
|
|
||||||
// Was it created?
|
// Was it created?
|
||||||
if ($model->save()) {
|
if ($model->save()) {
|
||||||
if ($this->shouldAddDefaultValues($request->input())) {
|
if ($this->shouldAddDefaultValues($request->input())) {
|
||||||
$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'));
|
$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect to the new model page
|
// Redirect to the new model page
|
||||||
return redirect()->route("models.index")->with('success', trans('admin/models/message.create.success'));
|
return redirect()->route('models.index')->with('success', trans('admin/models/message.create.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()->withInput()->withErrors($model->getErrors());
|
return redirect()->back()->withInput()->withErrors($model->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,16 +114,15 @@ class AssetModelsController extends Controller
|
||||||
$this->authorize('update', AssetModel::class);
|
$this->authorize('update', AssetModel::class);
|
||||||
if ($item = AssetModel::find($modelId)) {
|
if ($item = AssetModel::find($modelId)) {
|
||||||
$category_type = 'asset';
|
$category_type = 'asset';
|
||||||
$view = View::make('models/edit', compact('item','category_type'));
|
$view = View::make('models/edit', compact('item', 'category_type'));
|
||||||
$view->with('depreciation_list', Helper::depreciationList());
|
$view->with('depreciation_list', Helper::depreciationList());
|
||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist'));
|
return redirect()->route('models.index')->with('error', trans('admin/models/message.does_not_exist'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates and processes form data from the edit
|
* Validates and processes form data from the edit
|
||||||
* Asset Model form based on the model ID passed.
|
* Asset Model form based on the model ID passed.
|
||||||
|
@ -145,20 +145,18 @@ class AssetModelsController extends Controller
|
||||||
|
|
||||||
$model = $request->handleImages($model);
|
$model = $request->handleImages($model);
|
||||||
|
|
||||||
$model->depreciation_id = $request->input('depreciation_id');
|
$model->depreciation_id = $request->input('depreciation_id');
|
||||||
$model->eol = $request->input('eol');
|
$model->eol = $request->input('eol');
|
||||||
$model->name = $request->input('name');
|
$model->name = $request->input('name');
|
||||||
$model->model_number = $request->input('model_number');
|
$model->model_number = $request->input('model_number');
|
||||||
$model->manufacturer_id = $request->input('manufacturer_id');
|
$model->manufacturer_id = $request->input('manufacturer_id');
|
||||||
$model->category_id = $request->input('category_id');
|
$model->category_id = $request->input('category_id');
|
||||||
$model->notes = $request->input('notes');
|
$model->notes = $request->input('notes');
|
||||||
$model->requestable = $request->input('requestable', '0');
|
$model->requestable = $request->input('requestable', '0');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$this->removeCustomFieldsDefaultValues($model);
|
$this->removeCustomFieldsDefaultValues($model);
|
||||||
|
|
||||||
if ($request->input('custom_fieldset')=='') {
|
if ($request->input('custom_fieldset') == '') {
|
||||||
$model->fieldset_id = null;
|
$model->fieldset_id = null;
|
||||||
} else {
|
} else {
|
||||||
$model->fieldset_id = $request->input('custom_fieldset');
|
$model->fieldset_id = $request->input('custom_fieldset');
|
||||||
|
@ -168,10 +166,10 @@ class AssetModelsController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($model->save()) {
|
if ($model->save()) {
|
||||||
return redirect()->route("models.index")->with('success', trans('admin/models/message.update.success'));
|
return redirect()->route('models.index')->with('success', trans('admin/models/message.update.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()->withInput()->withErrors($model->getErrors());
|
return redirect()->back()->withInput()->withErrors($model->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +197,7 @@ class AssetModelsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($model->image) {
|
if ($model->image) {
|
||||||
try {
|
try {
|
||||||
Storage::disk('public')->delete('models/'.$model->image);
|
Storage::disk('public')->delete('models/'.$model->image);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::info($e);
|
\Log::info($e);
|
||||||
|
@ -213,7 +211,6 @@ class AssetModelsController extends Controller
|
||||||
return redirect()->route('models.index')->with('success', trans('admin/models/message.delete.success'));
|
return redirect()->route('models.index')->with('success', trans('admin/models/message.delete.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore a given Asset Model (mark as un-deleted)
|
* Restore a given Asset Model (mark as un-deleted)
|
||||||
*
|
*
|
||||||
|
@ -231,13 +228,13 @@ class AssetModelsController extends Controller
|
||||||
|
|
||||||
if (isset($model->id)) {
|
if (isset($model->id)) {
|
||||||
$model->restore();
|
$model->restore();
|
||||||
|
|
||||||
return redirect()->route('models.index')->with('success', trans('admin/models/message.restore.success'));
|
return redirect()->route('models.index')->with('success', trans('admin/models/message.restore.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()->with('error', trans('admin/models/message.not_found'));
|
return redirect()->back()->with('error', trans('admin/models/message.not_found'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the model information to present to the model view page
|
* Get the model information to present to the model view page
|
||||||
*
|
*
|
||||||
|
@ -260,13 +257,13 @@ class AssetModelsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the clone page to clone a model
|
* Get the clone page to clone a model
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v1.0]
|
* @since [v1.0]
|
||||||
* @param int $modelId
|
* @param int $modelId
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function getClone($modelId = null)
|
public function getClone($modelId = null)
|
||||||
{
|
{
|
||||||
// Check if the model exists
|
// Check if the model exists
|
||||||
|
@ -284,23 +281,19 @@ class AssetModelsController extends Controller
|
||||||
->with('clone_model', $model_to_clone);
|
->with('clone_model', $model_to_clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the custom fields form
|
* Get the custom fields form
|
||||||
*
|
*
|
||||||
* @author [B. Wetherington] [<uberbrady@gmail.com>]
|
* @author [B. Wetherington] [<uberbrady@gmail.com>]
|
||||||
* @since [v2.0]
|
* @since [v2.0]
|
||||||
* @param int $modelId
|
* @param int $modelId
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function getCustomFields($modelId)
|
public function getCustomFields($modelId)
|
||||||
{
|
{
|
||||||
return view("models.custom_fields_form")->with("model", AssetModel::find($modelId));
|
return view('models.custom_fields_form')->with('model', AssetModel::find($modelId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view that allows the user to bulk edit model attrbutes
|
* Returns a view that allows the user to bulk edit model attrbutes
|
||||||
*
|
*
|
||||||
|
@ -310,28 +303,25 @@ class AssetModelsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function postBulkEdit(Request $request)
|
public function postBulkEdit(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$models_raw_array = $request->input('ids');
|
$models_raw_array = $request->input('ids');
|
||||||
|
|
||||||
// Make sure some IDs have been selected
|
// Make sure some IDs have been selected
|
||||||
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
|
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
|
||||||
|
|
||||||
|
|
||||||
$models = AssetModel::whereIn('id', $models_raw_array)->withCount('assets as assets_count')->orderBy('assets_count', 'ASC')->get();
|
$models = AssetModel::whereIn('id', $models_raw_array)->withCount('assets as assets_count')->orderBy('assets_count', 'ASC')->get();
|
||||||
|
|
||||||
// If deleting....
|
// If deleting....
|
||||||
if ($request->input('bulk_actions')=='delete') {
|
if ($request->input('bulk_actions') == 'delete') {
|
||||||
$valid_count = 0;
|
$valid_count = 0;
|
||||||
foreach ($models as $model) {
|
foreach ($models as $model) {
|
||||||
if ($model->assets_count == 0) {
|
if ($model->assets_count == 0) {
|
||||||
$valid_count++;
|
$valid_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('models/bulk-delete', compact('models'))->with('valid_count', $valid_count);
|
return view('models/bulk-delete', compact('models'))->with('valid_count', $valid_count);
|
||||||
|
|
||||||
// Otherwise display the bulk edit screen
|
// Otherwise display the bulk edit screen
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$nochange = ['NC' => 'No Change'];
|
$nochange = ['NC' => 'No Change'];
|
||||||
$fieldset_list = $nochange + Helper::customFieldsetList();
|
$fieldset_list = $nochange + Helper::customFieldsetList();
|
||||||
$depreciation_list = $nochange + Helper::depreciationList();
|
$depreciation_list = $nochange + Helper::depreciationList();
|
||||||
|
@ -340,16 +330,12 @@ class AssetModelsController extends Controller
|
||||||
->with('fieldset_list', $fieldset_list)
|
->with('fieldset_list', $fieldset_list)
|
||||||
->with('depreciation_list', $depreciation_list);
|
->with('depreciation_list', $depreciation_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('models.index')
|
return redirect()->route('models.index')
|
||||||
->with('error', 'You must select at least one model to edit.');
|
->with('error', 'You must select at least one model to edit.');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view that allows the user to bulk edit model attrbutes
|
* Returns a view that allows the user to bulk edit model attrbutes
|
||||||
*
|
*
|
||||||
|
@ -359,35 +345,31 @@ class AssetModelsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function postBulkEditSave(Request $request)
|
public function postBulkEditSave(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$models_raw_array = $request->input('ids');
|
$models_raw_array = $request->input('ids');
|
||||||
$update_array = array();
|
$update_array = [];
|
||||||
|
|
||||||
|
if (($request->filled('manufacturer_id') && ($request->input('manufacturer_id') != 'NC'))) {
|
||||||
if (($request->filled('manufacturer_id') && ($request->input('manufacturer_id')!='NC'))) {
|
|
||||||
$update_array['manufacturer_id'] = $request->input('manufacturer_id');
|
$update_array['manufacturer_id'] = $request->input('manufacturer_id');
|
||||||
}
|
}
|
||||||
if (($request->filled('category_id') && ($request->input('category_id')!='NC'))) {
|
if (($request->filled('category_id') && ($request->input('category_id') != 'NC'))) {
|
||||||
$update_array['category_id'] = $request->input('category_id');
|
$update_array['category_id'] = $request->input('category_id');
|
||||||
}
|
}
|
||||||
if ($request->input('fieldset_id')!='NC') {
|
if ($request->input('fieldset_id') != 'NC') {
|
||||||
$update_array['fieldset_id'] = $request->input('fieldset_id');
|
$update_array['fieldset_id'] = $request->input('fieldset_id');
|
||||||
}
|
}
|
||||||
if ($request->input('depreciation_id')!='NC') {
|
if ($request->input('depreciation_id') != 'NC') {
|
||||||
$update_array['depreciation_id'] = $request->input('depreciation_id');
|
$update_array['depreciation_id'] = $request->input('depreciation_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (count($update_array) > 0) {
|
if (count($update_array) > 0) {
|
||||||
AssetModel::whereIn('id', $models_raw_array)->update($update_array);
|
AssetModel::whereIn('id', $models_raw_array)->update($update_array);
|
||||||
|
|
||||||
return redirect()->route('models.index')
|
return redirect()->route('models.index')
|
||||||
->with('success', trans('admin/models/message.bulkedit.success'));
|
->with('success', trans('admin/models/message.bulkedit.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('models.index')
|
return redirect()->route('models.index')
|
||||||
->with('warning', trans('admin/models/message.bulkedit.error'));
|
->with('warning', trans('admin/models/message.bulkedit.error'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -404,7 +386,6 @@ class AssetModelsController extends Controller
|
||||||
$models_raw_array = $request->input('ids');
|
$models_raw_array = $request->input('ids');
|
||||||
|
|
||||||
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
|
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
|
||||||
|
|
||||||
$models = AssetModel::whereIn('id', $models_raw_array)->withCount('assets as assets_count')->get();
|
$models = AssetModel::whereIn('id', $models_raw_array)->withCount('assets as assets_count')->get();
|
||||||
|
|
||||||
$del_error_count = 0;
|
$del_error_count = 0;
|
||||||
|
@ -426,7 +407,7 @@ class AssetModelsController extends Controller
|
||||||
|
|
||||||
if ($del_error_count == 0) {
|
if ($del_error_count == 0) {
|
||||||
return redirect()->route('models.index')
|
return redirect()->route('models.index')
|
||||||
->with('success', trans('admin/models/message.bulkdelete.success',['success_count'=> $del_count] ));
|
->with('success', trans('admin/models/message.bulkdelete.success', ['success_count'=> $del_count]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('models.index')
|
return redirect()->route('models.index')
|
||||||
|
@ -435,7 +416,6 @@ class AssetModelsController extends Controller
|
||||||
|
|
||||||
return redirect()->route('models.index')
|
return redirect()->route('models.index')
|
||||||
->with('error', trans('admin/models/message.bulkdelete.error'));
|
->with('error', trans('admin/models/message.bulkdelete.error'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -443,13 +423,13 @@ class AssetModelsController extends Controller
|
||||||
* any default values were entered into the form.
|
* any default values were entered into the form.
|
||||||
*
|
*
|
||||||
* @param array $input
|
* @param array $input
|
||||||
* @return boolean
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function shouldAddDefaultValues(array $input)
|
private function shouldAddDefaultValues(array $input)
|
||||||
{
|
{
|
||||||
return !empty($input['add_default_values'])
|
return ! empty($input['add_default_values'])
|
||||||
&& !empty($input['default_values'])
|
&& ! empty($input['default_values'])
|
||||||
&& !empty($input['custom_fieldset']);
|
&& ! empty($input['custom_fieldset']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,13 +7,14 @@ use App\Helpers\Helper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\AssetCheckinRequest;
|
use App\Http\Requests\AssetCheckinRequest;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
|
use App\Models\CheckoutAcceptance;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Redirect;
|
use Illuminate\Support\Facades\Redirect;
|
||||||
use Illuminate\Support\Facades\View;
|
use Illuminate\Support\Facades\View;
|
||||||
|
|
||||||
class AssetCheckinController extends Controller
|
class AssetCheckinController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view that presents a form to check an asset back into inventory.
|
* Returns a view that presents a form to check an asset back into inventory.
|
||||||
*
|
*
|
||||||
|
@ -33,6 +34,7 @@ class AssetCheckinController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->authorize('checkin', $asset);
|
$this->authorize('checkin', $asset);
|
||||||
|
|
||||||
return view('hardware/checkin', compact('asset'))->with('statusLabel_list', Helper::statusLabelList())->with('backto', $backto);
|
return view('hardware/checkin', compact('asset'))->with('statusLabel_list', Helper::statusLabelList())->with('backto', $backto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +75,7 @@ class AssetCheckinController extends Controller
|
||||||
$asset->name = $request->get('name');
|
$asset->name = $request->get('name');
|
||||||
|
|
||||||
if ($request->filled('status_id')) {
|
if ($request->filled('status_id')) {
|
||||||
$asset->status_id = e($request->get('status_id'));
|
$asset->status_id = e($request->get('status_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is just meant to correct legacy issues where some user data would have 0
|
// This is just meant to correct legacy issues where some user data would have 0
|
||||||
|
@ -81,14 +83,14 @@ class AssetCheckinController extends Controller
|
||||||
// rules, so it's necessary to fix this for long-time users. It's kinda gross, but will help
|
// rules, so it's necessary to fix this for long-time users. It's kinda gross, but will help
|
||||||
// people (and their data) in the long run
|
// people (and their data) in the long run
|
||||||
|
|
||||||
if ($asset->rtd_location_id=='0') {
|
if ($asset->rtd_location_id == '0') {
|
||||||
\Log::debug('Manually override the RTD location IDs');
|
\Log::debug('Manually override the RTD location IDs');
|
||||||
\Log::debug('Original RTD Location ID: '.$asset->rtd_location_id);
|
\Log::debug('Original RTD Location ID: '.$asset->rtd_location_id);
|
||||||
$asset->rtd_location_id = '';
|
$asset->rtd_location_id = '';
|
||||||
\Log::debug('New RTD Location ID: '.$asset->rtd_location_id);
|
\Log::debug('New RTD Location ID: '.$asset->rtd_location_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($asset->location_id=='0') {
|
if ($asset->location_id == '0') {
|
||||||
\Log::debug('Manually override the location IDs');
|
\Log::debug('Manually override the location IDs');
|
||||||
\Log::debug('Original Location ID: '.$asset->location_id);
|
\Log::debug('Original Location ID: '.$asset->location_id);
|
||||||
$asset->location_id = '';
|
$asset->location_id = '';
|
||||||
|
@ -99,27 +101,37 @@ class AssetCheckinController extends Controller
|
||||||
\Log::debug('After Location ID: '.$asset->location_id);
|
\Log::debug('After Location ID: '.$asset->location_id);
|
||||||
\Log::debug('After RTD Location ID: '.$asset->rtd_location_id);
|
\Log::debug('After RTD Location ID: '.$asset->rtd_location_id);
|
||||||
|
|
||||||
|
|
||||||
if ($request->filled('location_id')) {
|
if ($request->filled('location_id')) {
|
||||||
\Log::debug('NEW Location ID: '.$request->get('location_id'));
|
\Log::debug('NEW Location ID: '.$request->get('location_id'));
|
||||||
$asset->location_id = e($request->get('location_id'));
|
$asset->location_id = e($request->get('location_id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$checkin_at = date('Y-m-d');
|
$checkin_at = date('Y-m-d');
|
||||||
if($request->filled('checkin_at')){
|
if ($request->filled('checkin_at')) {
|
||||||
$checkin_at = $request->input('checkin_at');
|
$checkin_at = $request->input('checkin_at');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get all pending Acceptances for this asset and delete them
|
||||||
|
$acceptances = CheckoutAcceptance::pending()->whereHasMorph('checkoutable',
|
||||||
|
[Asset::class],
|
||||||
|
function (Builder $query) use ($asset) {
|
||||||
|
$query->where('id', $asset->id);
|
||||||
|
})->get();
|
||||||
|
$acceptances->map(function($acceptance) {
|
||||||
|
$acceptance->delete();
|
||||||
|
});
|
||||||
|
|
||||||
// Was the asset updated?
|
// Was the asset updated?
|
||||||
if ($asset->save()) {
|
if ($asset->save()) {
|
||||||
event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'), $checkin_at));
|
event(new CheckoutableCheckedIn($asset, $target, Auth::user(), $request->input('note'), $checkin_at));
|
||||||
|
|
||||||
if ((isset($user)) && ($backto =='user')) {
|
if ((isset($user)) && ($backto == 'user')) {
|
||||||
return redirect()->route("users.show", $user->id)->with('success', trans('admin/hardware/message.checkin.success'));
|
return redirect()->route('users.show', $user->id)->with('success', trans('admin/hardware/message.checkin.success'));
|
||||||
}
|
}
|
||||||
return redirect()->route("hardware.index")->with('success', trans('admin/hardware/message.checkin.success'));
|
|
||||||
|
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkin.success'));
|
||||||
}
|
}
|
||||||
// Redirect to the asset management page with error
|
// Redirect to the asset management page with error
|
||||||
return redirect()->route("hardware.index")->with('error', trans('admin/hardware/message.checkin.error').$asset->getErrors());
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.error').$asset->getErrors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Assets;
|
namespace App\Http\Controllers\Assets;
|
||||||
|
|
||||||
|
|
||||||
use App\Exceptions\CheckoutNotAllowed;
|
use App\Exceptions\CheckoutNotAllowed;
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
use App\Http\Controllers\CheckInOutRequest;
|
use App\Http\Controllers\CheckInOutRequest;
|
||||||
|
@ -15,15 +14,16 @@ use Illuminate\Support\Facades\Auth;
|
||||||
class AssetCheckoutController extends Controller
|
class AssetCheckoutController extends Controller
|
||||||
{
|
{
|
||||||
use CheckInOutRequest;
|
use CheckInOutRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view that presents a form to check an asset out to a
|
* Returns a view that presents a form to check an asset out to a
|
||||||
* user.
|
* user.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @param int $assetId
|
* @param int $assetId
|
||||||
* @since [v1.0]
|
* @since [v1.0]
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function create($assetId)
|
public function create($assetId)
|
||||||
{
|
{
|
||||||
// Check if the asset exists
|
// Check if the asset exists
|
||||||
|
@ -37,9 +37,8 @@ class AssetCheckoutController extends Controller
|
||||||
return view('hardware/checkout', compact('asset'))
|
return view('hardware/checkout', compact('asset'))
|
||||||
->with('statusLabel_list', Helper::deployableStatusLabelList());
|
->with('statusLabel_list', Helper::deployableStatusLabelList());
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkout.not_available'));
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkout.not_available'));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,9 +54,9 @@ class AssetCheckoutController extends Controller
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// Check if the asset exists
|
// Check if the asset exists
|
||||||
if (!$asset = Asset::find($assetId)) {
|
if (! $asset = Asset::find($assetId)) {
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
||||||
} elseif (!$asset->availableForCheckout()) {
|
} elseif (! $asset->availableForCheckout()) {
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkout.not_available'));
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkout.not_available'));
|
||||||
}
|
}
|
||||||
$this->authorize('checkout', $asset);
|
$this->authorize('checkout', $asset);
|
||||||
|
@ -67,8 +66,8 @@ class AssetCheckoutController extends Controller
|
||||||
|
|
||||||
$asset = $this->updateAssetLocation($asset, $target);
|
$asset = $this->updateAssetLocation($asset, $target);
|
||||||
|
|
||||||
$checkout_at = date("Y-m-d H:i:s");
|
$checkout_at = date('Y-m-d H:i:s');
|
||||||
if (($request->filled('checkout_at')) && ($request->get('checkout_at')!= date("Y-m-d"))) {
|
if (($request->filled('checkout_at')) && ($request->get('checkout_at') != date('Y-m-d'))) {
|
||||||
$checkout_at = $request->get('checkout_at');
|
$checkout_at = $request->get('checkout_at');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +81,7 @@ class AssetCheckoutController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, e($request->get('note')), $request->get('name'))) {
|
if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, e($request->get('note')), $request->get('name'))) {
|
||||||
return redirect()->route("hardware.index")->with('success', trans('admin/hardware/message.checkout.success'));
|
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkout.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redirect to the asset management page with error
|
// Redirect to the asset management page with error
|
||||||
|
@ -93,5 +92,4 @@ class AssetCheckoutController extends Controller
|
||||||
return redirect()->back()->with('error', $e->getMessage());
|
return redirect()->back()->with('error', $e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Assets;
|
namespace App\Http\Controllers\Assets;
|
||||||
|
|
||||||
|
use App\Helpers\StorageHelper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\AssetFileRequest;
|
use App\Http\Requests\AssetFileRequest;
|
||||||
use App\Models\Actionlog;
|
use App\Models\Actionlog;
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
use Illuminate\Support\Facades\Response;
|
use Illuminate\Support\Facades\Response;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use App\Helpers\StorageHelper;
|
use enshrined\svgSanitize\Sanitizer;
|
||||||
|
|
||||||
class AssetFilesController extends Controller
|
class AssetFilesController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -25,22 +25,44 @@ class AssetFilesController extends Controller
|
||||||
*/
|
*/
|
||||||
public function store(AssetFileRequest $request, $assetId = null)
|
public function store(AssetFileRequest $request, $assetId = null)
|
||||||
{
|
{
|
||||||
if (!$asset = Asset::find($assetId)) {
|
if (! $asset = Asset::find($assetId)) {
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->authorize('update', $asset);
|
$this->authorize('update', $asset);
|
||||||
|
|
||||||
if ($request->hasFile('file')) {
|
if ($request->hasFile('file')) {
|
||||||
|
if (! Storage::exists('private_uploads/assets')) {
|
||||||
if (!Storage::exists('private_uploads/assets')) Storage::makeDirectory('private_uploads/assets', 775);
|
Storage::makeDirectory('private_uploads/assets', 775);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($request->file('file') as $file) {
|
foreach ($request->file('file') as $file) {
|
||||||
|
|
||||||
$extension = $file->getClientOriginalExtension();
|
$extension = $file->getClientOriginalExtension();
|
||||||
$file_name = 'hardware-'.$asset->id.'-'.str_random(8).'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension;
|
$file_name = 'hardware-'.$asset->id.'-'.str_random(8).'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension;
|
||||||
|
|
||||||
|
// Check for SVG and sanitize it
|
||||||
|
if ($extension=='svg') {
|
||||||
|
\Log::debug('This is an SVG');
|
||||||
|
|
||||||
|
$sanitizer = new Sanitizer();
|
||||||
|
$dirtySVG = file_get_contents($file->getRealPath());
|
||||||
|
$cleanSVG = $sanitizer->sanitize($dirtySVG);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Storage::put('private_uploads/assets/'.$file_name, $cleanSVG);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
\Log::debug('Upload no workie :( ');
|
||||||
|
\Log::debug($e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
Storage::put('private_uploads/assets/'.$file_name, file_get_contents($file));
|
Storage::put('private_uploads/assets/'.$file_name, file_get_contents($file));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
$asset->logUpload($file_name, e($request->get('notes')));
|
$asset->logUpload($file_name, e($request->get('notes')));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()->with('success', trans('admin/hardware/message.upload.success'));
|
return redirect()->back()->with('success', trans('admin/hardware/message.upload.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +86,7 @@ class AssetFilesController extends Controller
|
||||||
if (isset($asset->id)) {
|
if (isset($asset->id)) {
|
||||||
$this->authorize('view', $asset);
|
$this->authorize('view', $asset);
|
||||||
|
|
||||||
if (!$log = Actionlog::find($fileId)) {
|
if (! $log = Actionlog::find($fileId)) {
|
||||||
return response('No matching record for that asset/file', 500)
|
return response('No matching record for that asset/file', 500)
|
||||||
->header('Content-Type', 'text/plain');
|
->header('Content-Type', 'text/plain');
|
||||||
}
|
}
|
||||||
|
@ -72,21 +94,23 @@ class AssetFilesController extends Controller
|
||||||
$file = 'private_uploads/assets/'.$log->filename;
|
$file = 'private_uploads/assets/'.$log->filename;
|
||||||
\Log::debug('Checking for '.$file);
|
\Log::debug('Checking for '.$file);
|
||||||
|
|
||||||
if ($log->action_type =='audit') {
|
if ($log->action_type == 'audit') {
|
||||||
$file = 'private_uploads/audits/'.$log->filename;
|
$file = 'private_uploads/audits/'.$log->filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Storage::exists($file)) {
|
if (! Storage::exists($file)) {
|
||||||
return response('File '.$file.' not found on server', 404)
|
return response('File '.$file.' not found on server', 404)
|
||||||
->header('Content-Type', 'text/plain');
|
->header('Content-Type', 'text/plain');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($download != 'true') {
|
if ($download != 'true') {
|
||||||
if ($contents = file_get_contents(Storage::url($file))) {
|
if ($contents = file_get_contents(Storage::url($file))) {
|
||||||
return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
|
return Response::make(Storage::url($file)->header('Content-Type', mime_content_type($file)));
|
||||||
}
|
}
|
||||||
return JsonResponse::create(["error" => "Failed validation: "], 500);
|
|
||||||
|
return JsonResponse::create(['error' => 'Failed validation: '], 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
return StorageHelper::downloader($file);
|
return StorageHelper::downloader($file);
|
||||||
}
|
}
|
||||||
// Prepare the error message
|
// Prepare the error message
|
||||||
|
@ -117,13 +141,14 @@ class AssetFilesController extends Controller
|
||||||
$this->authorize('update', $asset);
|
$this->authorize('update', $asset);
|
||||||
$log = Actionlog::find($fileId);
|
$log = Actionlog::find($fileId);
|
||||||
if ($log) {
|
if ($log) {
|
||||||
if (Storage::exists($rel_path.'/'.$log->filename)) {
|
if (Storage::exists($rel_path.'/'.$log->filename)) {
|
||||||
Storage::delete($rel_path.'/'.$log->filename);
|
Storage::delete($rel_path.'/'.$log->filename);
|
||||||
}
|
}
|
||||||
$log->delete();
|
$log->delete();
|
||||||
|
|
||||||
return redirect()->back()->with('success', trans('admin/hardware/message.deletefile.success'));
|
return redirect()->back()->with('success', trans('admin/hardware/message.deletefile.success'));
|
||||||
}
|
}
|
||||||
$log->delete();
|
|
||||||
return redirect()->back()
|
return redirect()->back()
|
||||||
->with('success', trans('admin/hardware/message.deletefile.success'));
|
->with('success', trans('admin/hardware/message.deletefile.success'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers\Assets;
|
namespace App\Http\Controllers\Assets;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
@ -14,13 +15,13 @@ use App\Models\Setting;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Auth;
|
use Auth;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Intervention\Image\Facades\Image;
|
|
||||||
use DB;
|
use DB;
|
||||||
use Gate;
|
use Gate;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Input;
|
use Input;
|
||||||
|
use Intervention\Image\Facades\Image;
|
||||||
use League\Csv\Reader;
|
use League\Csv\Reader;
|
||||||
use League\Csv\Statement;
|
use League\Csv\Statement;
|
||||||
use Paginator;
|
use Paginator;
|
||||||
|
@ -40,9 +41,8 @@ use View;
|
||||||
*/
|
*/
|
||||||
class AssetsController extends Controller
|
class AssetsController extends Controller
|
||||||
{
|
{
|
||||||
protected $qrCodeDimensions = array( 'height' => 3.5, 'width' => 3.5);
|
protected $qrCodeDimensions = ['height' => 3.5, 'width' => 3.5];
|
||||||
protected $barCodeDimensions = array( 'height' => 2, 'width' => 22);
|
protected $barCodeDimensions = ['height' => 2, 'width' => 22];
|
||||||
|
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -65,6 +65,7 @@ class AssetsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('index', Asset::class);
|
$this->authorize('index', Asset::class);
|
||||||
$company = Company::find($request->input('company_id'));
|
$company = Company::find($request->input('company_id'));
|
||||||
|
|
||||||
return view('hardware/index')->with('company', $company);
|
return view('hardware/index')->with('company', $company);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +90,7 @@ class AssetsController extends Controller
|
||||||
$selected_model = AssetModel::find($request->input('model_id'));
|
$selected_model = AssetModel::find($request->input('model_id'));
|
||||||
$view->with('selected_model', $selected_model);
|
$view->with('selected_model', $selected_model);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $view;
|
return $view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,18 +116,17 @@ class AssetsController extends Controller
|
||||||
$serials = $request->input('serials');
|
$serials = $request->input('serials');
|
||||||
|
|
||||||
for ($a = 1; $a <= count($asset_tags); $a++) {
|
for ($a = 1; $a <= count($asset_tags); $a++) {
|
||||||
|
|
||||||
$asset = new Asset();
|
$asset = new Asset();
|
||||||
$asset->model()->associate(AssetModel::find($request->input('model_id')));
|
$asset->model()->associate(AssetModel::find($request->input('model_id')));
|
||||||
$asset->name = $request->input('name');
|
$asset->name = $request->input('name');
|
||||||
|
|
||||||
// Check for a corresponding serial
|
// Check for a corresponding serial
|
||||||
if (($serials) && (array_key_exists($a, $serials))) {
|
if (($serials) && (array_key_exists($a, $serials))) {
|
||||||
$asset->serial = $serials[$a];
|
$asset->serial = $serials[$a];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($asset_tags) && (array_key_exists($a, $asset_tags))) {
|
if (($asset_tags) && (array_key_exists($a, $asset_tags))) {
|
||||||
$asset->asset_tag = $asset_tags[$a];
|
$asset->asset_tag = $asset_tags[$a];
|
||||||
}
|
}
|
||||||
|
|
||||||
$asset->company_id = Company::getIdForCurrentUser($request->input('company_id'));
|
$asset->company_id = Company::getIdForCurrentUser($request->input('company_id'));
|
||||||
|
@ -138,18 +139,18 @@ class AssetsController extends Controller
|
||||||
$asset->depreciate = '0';
|
$asset->depreciate = '0';
|
||||||
$asset->status_id = request('status_id', 0);
|
$asset->status_id = request('status_id', 0);
|
||||||
$asset->warranty_months = request('warranty_months', null);
|
$asset->warranty_months = request('warranty_months', null);
|
||||||
$asset->purchase_cost = Helper::ParseFloat($request->get('purchase_cost'));
|
$asset->purchase_cost = Helper::ParseCurrency($request->get('purchase_cost'));
|
||||||
$asset->purchase_date = request('purchase_date', null);
|
$asset->purchase_date = request('purchase_date', null);
|
||||||
$asset->assigned_to = request('assigned_to', null);
|
$asset->assigned_to = request('assigned_to', null);
|
||||||
$asset->supplier_id = request('supplier_id', 0);
|
$asset->supplier_id = request('supplier_id', 0);
|
||||||
$asset->requestable = request('requestable', 0);
|
$asset->requestable = request('requestable', 0);
|
||||||
$asset->rtd_location_id = request('rtd_location_id', null);
|
$asset->rtd_location_id = request('rtd_location_id', null);
|
||||||
|
|
||||||
if (!empty($settings->audit_interval)) {
|
if (! empty($settings->audit_interval)) {
|
||||||
$asset->next_audit_date = Carbon::now()->addMonths($settings->audit_interval)->toDateString();
|
$asset->next_audit_date = Carbon::now()->addMonths($settings->audit_interval)->toDateString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($asset->assigned_to=='') {
|
if ($asset->assigned_to == '') {
|
||||||
$asset->location_id = $request->input('rtd_location_id', null);
|
$asset->location_id = $request->input('rtd_location_id', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,17 +165,18 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
if (($model) && ($model->fieldset)) {
|
if (($model) && ($model->fieldset)) {
|
||||||
foreach ($model->fieldset->fields as $field) {
|
foreach ($model->fieldset->fields as $field) {
|
||||||
if ($field->field_encrypted=='1') {
|
if ($field->field_encrypted == '1') {
|
||||||
if (Gate::allows('admin')) {
|
if (Gate::allows('admin')) {
|
||||||
if(is_array($request->input($field->convertUnicodeDbSlug()))){
|
if (is_array($request->input($field->convertUnicodeDbSlug()))) {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e(implode(', ', $request->input($field->convertUnicodeDbSlug()))));
|
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e(implode(', ', $request->input($field->convertUnicodeDbSlug()))));
|
||||||
}else{
|
} else {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e($request->input($field->convertUnicodeDbSlug())));
|
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e($request->input($field->convertUnicodeDbSlug())));
|
||||||
} }
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if(is_array($request->input($field->convertUnicodeDbSlug()))){
|
if (is_array($request->input($field->convertUnicodeDbSlug()))) {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = implode(', ', $request->input($field->convertUnicodeDbSlug()));
|
$asset->{$field->convertUnicodeDbSlug()} = implode(', ', $request->input($field->convertUnicodeDbSlug()));
|
||||||
}else{
|
} else {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
|
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,7 +185,6 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
// Validate the asset before saving
|
// Validate the asset before saving
|
||||||
if ($asset->isValid() && $asset->save()) {
|
if ($asset->isValid() && $asset->save()) {
|
||||||
|
|
||||||
if (request('assigned_user')) {
|
if (request('assigned_user')) {
|
||||||
$target = User::find(request('assigned_user'));
|
$target = User::find(request('assigned_user'));
|
||||||
$location = $target->location_id;
|
$location = $target->location_id;
|
||||||
|
@ -200,10 +201,7 @@ class AssetsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = true;
|
$success = true;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($success) {
|
if ($success) {
|
||||||
|
@ -213,7 +211,6 @@ class AssetsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()->withInput()->withErrors($asset->getErrors());
|
return redirect()->back()->withInput()->withErrors($asset->getErrors());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -226,7 +223,7 @@ class AssetsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function edit($assetId = null)
|
public function edit($assetId = null)
|
||||||
{
|
{
|
||||||
if (!$item = Asset::find($assetId)) {
|
if (! $item = Asset::find($assetId)) {
|
||||||
// Redirect to the asset management page with error
|
// Redirect to the asset management page with error
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
||||||
}
|
}
|
||||||
|
@ -238,7 +235,6 @@ class AssetsController extends Controller
|
||||||
->with('statuslabel_types', Helper::statusTypeList());
|
->with('statuslabel_types', Helper::statusTypeList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view that presents information about an asset for detail view.
|
* Returns a view that presents information about an asset for detail view.
|
||||||
*
|
*
|
||||||
|
@ -262,17 +258,17 @@ class AssetsController extends Controller
|
||||||
if ($asset->location) {
|
if ($asset->location) {
|
||||||
$use_currency = $asset->location->currency;
|
$use_currency = $asset->location->currency;
|
||||||
} else {
|
} else {
|
||||||
if ($settings->default_currency!='') {
|
if ($settings->default_currency != '') {
|
||||||
$use_currency = $settings->default_currency;
|
$use_currency = $settings->default_currency;
|
||||||
} else {
|
} else {
|
||||||
$use_currency = trans('general.currency');
|
$use_currency = trans('general.currency');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$qr_code = (object) array(
|
$qr_code = (object) [
|
||||||
'display' => $settings->qr_code == '1',
|
'display' => $settings->qr_code == '1',
|
||||||
'url' => route('qr_code/hardware', $asset->id)
|
'url' => route('qr_code/hardware', $asset->id),
|
||||||
);
|
];
|
||||||
|
|
||||||
return view('hardware/view', compact('asset', 'qr_code', 'settings'))
|
return view('hardware/view', compact('asset', 'qr_code', 'settings'))
|
||||||
->with('use_currency', $use_currency)->with('audit_log', $audit_log);
|
->with('use_currency', $use_currency)->with('audit_log', $audit_log);
|
||||||
|
@ -281,7 +277,6 @@ class AssetsController extends Controller
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate and process asset edit form.
|
* Validate and process asset edit form.
|
||||||
*
|
*
|
||||||
|
@ -290,11 +285,10 @@ class AssetsController extends Controller
|
||||||
* @since [v1.0]
|
* @since [v1.0]
|
||||||
* @return Redirect
|
* @return Redirect
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function update(ImageUploadRequest $request, $assetId = null)
|
public function update(ImageUploadRequest $request, $assetId = null)
|
||||||
{
|
{
|
||||||
// Check if the asset exists
|
// Check if the asset exists
|
||||||
if (!$asset = Asset::find($assetId)) {
|
if (! $asset = Asset::find($assetId)) {
|
||||||
// Redirect to the asset management page with error
|
// Redirect to the asset management page with error
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
||||||
}
|
}
|
||||||
|
@ -302,7 +296,7 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
$asset->status_id = $request->input('status_id', null);
|
$asset->status_id = $request->input('status_id', null);
|
||||||
$asset->warranty_months = $request->input('warranty_months', null);
|
$asset->warranty_months = $request->input('warranty_months', null);
|
||||||
$asset->purchase_cost = Helper::ParseFloat($request->input('purchase_cost', null));
|
$asset->purchase_cost = Helper::ParseCurrency($request->input('purchase_cost', null));
|
||||||
$asset->purchase_date = $request->input('purchase_date', null);
|
$asset->purchase_date = $request->input('purchase_date', null);
|
||||||
$asset->supplier_id = $request->input('supplier_id', null);
|
$asset->supplier_id = $request->input('supplier_id', null);
|
||||||
$asset->expected_checkin = $request->input('expected_checkin', null);
|
$asset->expected_checkin = $request->input('expected_checkin', null);
|
||||||
|
@ -311,11 +305,10 @@ class AssetsController extends Controller
|
||||||
$asset->requestable = $request->filled('requestable');
|
$asset->requestable = $request->filled('requestable');
|
||||||
$asset->rtd_location_id = $request->input('rtd_location_id', null);
|
$asset->rtd_location_id = $request->input('rtd_location_id', null);
|
||||||
|
|
||||||
if ($asset->assigned_to=='') {
|
if ($asset->assigned_to == '') {
|
||||||
$asset->location_id = $request->input('rtd_location_id', null);
|
$asset->location_id = $request->input('rtd_location_id', null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($request->filled('image_delete')) {
|
if ($request->filled('image_delete')) {
|
||||||
try {
|
try {
|
||||||
unlink(public_path().'/uploads/assets/'.$asset->image);
|
unlink(public_path().'/uploads/assets/'.$asset->image);
|
||||||
|
@ -323,21 +316,19 @@ class AssetsController extends Controller
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::info($e);
|
\Log::info($e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Update the asset data
|
// Update the asset data
|
||||||
$asset_tag = $request->input('asset_tags');
|
$asset_tag = $request->input('asset_tags');
|
||||||
$serial = $request->input('serials');
|
$serial = $request->input('serials');
|
||||||
$asset->name = $request->input('name');
|
$asset->name = $request->input('name');
|
||||||
$asset->serial = $serial[1];
|
$asset->serial = $serial[1];
|
||||||
$asset->company_id = Company::getIdForCurrentUser($request->input('company_id'));
|
$asset->company_id = Company::getIdForCurrentUser($request->input('company_id'));
|
||||||
$asset->model_id = $request->input('model_id');
|
$asset->model_id = $request->input('model_id');
|
||||||
$asset->order_number = $request->input('order_number');
|
$asset->order_number = $request->input('order_number');
|
||||||
$asset->asset_tag = $asset_tag[1];
|
$asset->asset_tag = $asset_tag[1];
|
||||||
$asset->notes = $request->input('notes');
|
$asset->notes = $request->input('notes');
|
||||||
$asset->physical = '1';
|
$asset->physical = '1';
|
||||||
|
|
||||||
$asset = $request->handleImages($asset);
|
$asset = $request->handleImages($asset);
|
||||||
|
|
||||||
|
@ -348,18 +339,18 @@ class AssetsController extends Controller
|
||||||
$model = AssetModel::find($request->get('model_id'));
|
$model = AssetModel::find($request->get('model_id'));
|
||||||
if (($model) && ($model->fieldset)) {
|
if (($model) && ($model->fieldset)) {
|
||||||
foreach ($model->fieldset->fields as $field) {
|
foreach ($model->fieldset->fields as $field) {
|
||||||
if ($field->field_encrypted=='1') {
|
if ($field->field_encrypted == '1') {
|
||||||
if (Gate::allows('admin')) {
|
if (Gate::allows('admin')) {
|
||||||
if(is_array($request->input($field->convertUnicodeDbSlug()))){
|
if (is_array($request->input($field->convertUnicodeDbSlug()))) {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e(implode(', ', $request->input($field->convertUnicodeDbSlug()))));
|
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e(implode(', ', $request->input($field->convertUnicodeDbSlug()))));
|
||||||
}else{
|
} else {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e($request->input($field->convertUnicodeDbSlug())));
|
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e($request->input($field->convertUnicodeDbSlug())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(is_array($request->input($field->convertUnicodeDbSlug()))){
|
if (is_array($request->input($field->convertUnicodeDbSlug()))) {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = implode(', ', $request->input($field->convertUnicodeDbSlug()));
|
$asset->{$field->convertUnicodeDbSlug()} = implode(', ', $request->input($field->convertUnicodeDbSlug()));
|
||||||
}else{
|
} else {
|
||||||
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
|
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -368,7 +359,7 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
|
|
||||||
if ($asset->save()) {
|
if ($asset->save()) {
|
||||||
return redirect()->route("hardware.show", $assetId)
|
return redirect()->route('hardware.show', $assetId)
|
||||||
->with('success', trans('admin/hardware/message.update.success'));
|
->with('success', trans('admin/hardware/message.update.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,10 +386,10 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
DB::table('assets')
|
DB::table('assets')
|
||||||
->where('id', $asset->id)
|
->where('id', $asset->id)
|
||||||
->update(array('assigned_to' => null));
|
->update(['assigned_to' => null]);
|
||||||
|
|
||||||
if ($asset->image) {
|
if ($asset->image) {
|
||||||
try {
|
try {
|
||||||
Storage::disk('public')->delete('assets'.'/'.$asset->image);
|
Storage::disk('public')->delete('assets'.'/'.$asset->image);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::debug($e);
|
\Log::debug($e);
|
||||||
|
@ -410,8 +401,6 @@ class AssetsController extends Controller
|
||||||
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.delete.success'));
|
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.delete.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches the assets table by asset tag, and redirects if it finds one
|
* Searches the assets table by asset tag, and redirects if it finds one
|
||||||
*
|
*
|
||||||
|
@ -421,14 +410,16 @@ class AssetsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function getAssetByTag(Request $request)
|
public function getAssetByTag(Request $request)
|
||||||
{
|
{
|
||||||
$topsearch = ($request->get('topsearch')=="true");
|
$topsearch = ($request->get('topsearch') == 'true');
|
||||||
|
|
||||||
if (!$asset = Asset::where('asset_tag', '=', $request->get('assetTag'))->first()) {
|
if (! $asset = Asset::where('asset_tag', '=', $request->get('assetTag'))->first()) {
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
||||||
}
|
}
|
||||||
$this->authorize('view', $asset);
|
$this->authorize('view', $asset);
|
||||||
|
|
||||||
return redirect()->route('hardware.show', $asset->id)->with('topsearch', $topsearch);
|
return redirect()->route('hardware.show', $asset->id)->with('topsearch', $topsearch);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a QR code for the asset
|
* Return a QR code for the asset
|
||||||
*
|
*
|
||||||
|
@ -450,20 +441,22 @@ class AssetsController extends Controller
|
||||||
if (isset($asset->id, $asset->asset_tag)) {
|
if (isset($asset->id, $asset->asset_tag)) {
|
||||||
if (file_exists($qr_file)) {
|
if (file_exists($qr_file)) {
|
||||||
$header = ['Content-type' => 'image/png'];
|
$header = ['Content-type' => 'image/png'];
|
||||||
|
|
||||||
return response()->file($qr_file, $header);
|
return response()->file($qr_file, $header);
|
||||||
} else {
|
} else {
|
||||||
$barcode = new \Com\Tecnick\Barcode\Barcode();
|
$barcode = new \Com\Tecnick\Barcode\Barcode();
|
||||||
$barcode_obj = $barcode->getBarcodeObj($settings->barcode_type, route('hardware.show', $asset->id), $size['height'], $size['width'], 'black', array(-2, -2, -2, -2));
|
$barcode_obj = $barcode->getBarcodeObj($settings->barcode_type, route('hardware.show', $asset->id), $size['height'], $size['width'], 'black', [-2, -2, -2, -2]);
|
||||||
file_put_contents($qr_file, $barcode_obj->getPngData());
|
file_put_contents($qr_file, $barcode_obj->getPngData());
|
||||||
|
|
||||||
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
|
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 'That asset is invalid';
|
return 'That asset is invalid';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a 2D barcode for the asset
|
* Return a 2D barcode for the asset
|
||||||
*
|
*
|
||||||
|
@ -481,6 +474,7 @@ class AssetsController extends Controller
|
||||||
if (isset($asset->id, $asset->asset_tag)) {
|
if (isset($asset->id, $asset->asset_tag)) {
|
||||||
if (file_exists($barcode_file)) {
|
if (file_exists($barcode_file)) {
|
||||||
$header = ['Content-type' => 'image/png'];
|
$header = ['Content-type' => 'image/png'];
|
||||||
|
|
||||||
return response()->file($barcode_file, $header);
|
return response()->file($barcode_file, $header);
|
||||||
} else {
|
} else {
|
||||||
// Calculate barcode width in pixel based on label width (inch)
|
// Calculate barcode width in pixel based on label width (inch)
|
||||||
|
@ -488,20 +482,19 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
$barcode = new \Com\Tecnick\Barcode\Barcode();
|
$barcode = new \Com\Tecnick\Barcode\Barcode();
|
||||||
try {
|
try {
|
||||||
$barcode_obj = $barcode->getBarcodeObj($settings->alt_barcode,$asset->asset_tag,($barcode_width < 300 ? $barcode_width : 300),50);
|
$barcode_obj = $barcode->getBarcodeObj($settings->alt_barcode, $asset->asset_tag, ($barcode_width < 300 ? $barcode_width : 300), 50);
|
||||||
file_put_contents($barcode_file, $barcode_obj->getPngData());
|
file_put_contents($barcode_file, $barcode_obj->getPngData());
|
||||||
|
|
||||||
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
|
return response($barcode_obj->getPngData())->header('Content-type', 'image/png');
|
||||||
} catch(\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::debug('The barcode format is invalid.');
|
\Log::debug('The barcode format is invalid.');
|
||||||
|
|
||||||
return response(file_get_contents(public_path('uploads/barcodes/invalid_barcode.gif')))->header('Content-type', 'image/gif');
|
return response(file_get_contents(public_path('uploads/barcodes/invalid_barcode.gif')))->header('Content-type', 'image/gif');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a label for an individual asset.
|
* Return a label for an individual asset.
|
||||||
*
|
*
|
||||||
|
@ -523,7 +516,6 @@ class AssetsController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view that presents a form to clone an asset.
|
* Returns a view that presents a form to clone an asset.
|
||||||
*
|
*
|
||||||
|
@ -564,6 +556,7 @@ class AssetsController extends Controller
|
||||||
public function getImportHistory()
|
public function getImportHistory()
|
||||||
{
|
{
|
||||||
$this->authorize('admin');
|
$this->authorize('admin');
|
||||||
|
|
||||||
return view('hardware/history');
|
return view('hardware/history');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -572,49 +565,48 @@ class AssetsController extends Controller
|
||||||
*
|
*
|
||||||
* This needs a LOT of love. It's done very inelegantly right now, and there are
|
* This needs a LOT of love. It's done very inelegantly right now, and there are
|
||||||
* a ton of optimizations that could (and should) be done.
|
* a ton of optimizations that could (and should) be done.
|
||||||
*
|
*
|
||||||
* Updated to respect checkin dates:
|
* Updated to respect checkin dates:
|
||||||
* No checkin column, assume all items are checked in (todays date)
|
* No checkin column, assume all items are checked in (todays date)
|
||||||
* Checkin date in the past, update history.
|
* Checkin date in the past, update history.
|
||||||
* Checkin date in future or empty, check the item out to the user.
|
* Checkin date in future or empty, check the item out to the user.
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
* @since [v3.3]
|
* @since [v3.3]
|
||||||
* @return View
|
* @return View
|
||||||
*/
|
*/
|
||||||
public function postImportHistory(Request $request)
|
public function postImportHistory(Request $request)
|
||||||
{
|
{
|
||||||
|
if (! $request->hasFile('user_import_csv')) {
|
||||||
if (!$request->hasFile('user_import_csv')) {
|
|
||||||
return back()->with('error', 'No file provided. Please select a file for import and try again. ');
|
return back()->with('error', 'No file provided. Please select a file for import and try again. ');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ini_get("auto_detect_line_endings")) {
|
if (! ini_get('auto_detect_line_endings')) {
|
||||||
ini_set("auto_detect_line_endings", '1');
|
ini_set('auto_detect_line_endings', '1');
|
||||||
}
|
}
|
||||||
$csv = Reader::createFromPath($request->file('user_import_csv'));
|
$csv = Reader::createFromPath($request->file('user_import_csv'));
|
||||||
$csv->setHeaderOffset(0);
|
$csv->setHeaderOffset(0);
|
||||||
$header = $csv->getHeader();
|
$header = $csv->getHeader();
|
||||||
$isCheckinHeaderExplicit = in_array("checkin date", (array_map('strtolower', $header)));
|
$isCheckinHeaderExplicit = in_array('checkin date', (array_map('strtolower', $header)));
|
||||||
$results = $csv->getRecords();
|
$results = $csv->getRecords();
|
||||||
$item = array();
|
$item = [];
|
||||||
$status = array();
|
$status = [];
|
||||||
$status['error'] = array();
|
$status['error'] = [];
|
||||||
$status['success'] = array();
|
$status['success'] = [];
|
||||||
foreach ($results as $row) {
|
foreach ($results as $row) {
|
||||||
if (is_array($row)) {
|
if (is_array($row)) {
|
||||||
$row = array_change_key_case($row, CASE_LOWER);
|
$row = array_change_key_case($row, CASE_LOWER);
|
||||||
$asset_tag = Helper::array_smart_fetch($row, "asset tag");
|
$asset_tag = Helper::array_smart_fetch($row, 'asset tag');
|
||||||
if (!array_key_exists($asset_tag, $item)) {
|
if (! array_key_exists($asset_tag, $item)) {
|
||||||
$item[$asset_tag] = array();
|
$item[$asset_tag] = [];
|
||||||
}
|
}
|
||||||
$batch_counter = count($item[$asset_tag]);
|
$batch_counter = count($item[$asset_tag]);
|
||||||
$item[$asset_tag][$batch_counter]['checkout_date'] = Carbon::parse(Helper::array_smart_fetch($row, "checkout date"))->format('Y-m-d H:i:s');
|
$item[$asset_tag][$batch_counter]['checkout_date'] = Carbon::parse(Helper::array_smart_fetch($row, 'checkout date'))->format('Y-m-d H:i:s');
|
||||||
|
|
||||||
if ($isCheckinHeaderExplicit){
|
if ($isCheckinHeaderExplicit) {
|
||||||
//checkin date not empty, assume past transaction or future checkin date (expected)
|
//checkin date not empty, assume past transaction or future checkin date (expected)
|
||||||
if (!empty(Helper::array_smart_fetch($row, "checkin date"))) {
|
if (! empty(Helper::array_smart_fetch($row, 'checkin date'))) {
|
||||||
$item[$asset_tag][$batch_counter]['checkin_date'] = Carbon::parse(Helper::array_smart_fetch($row, "checkin date"))->format('Y-m-d H:i:s');
|
$item[$asset_tag][$batch_counter]['checkin_date'] = Carbon::parse(Helper::array_smart_fetch($row, 'checkin date'))->format('Y-m-d H:i:s');
|
||||||
} else {
|
} else {
|
||||||
$item[$asset_tag][$batch_counter]['checkin_date'] = '';
|
$item[$asset_tag][$batch_counter]['checkin_date'] = '';
|
||||||
}
|
}
|
||||||
|
@ -623,44 +615,44 @@ class AssetsController extends Controller
|
||||||
$item[$asset_tag][$batch_counter]['checkin_date'] = Carbon::parse(now())->format('Y-m-d H:i:s');
|
$item[$asset_tag][$batch_counter]['checkin_date'] = Carbon::parse(now())->format('Y-m-d H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
$item[$asset_tag][$batch_counter]['asset_tag'] = Helper::array_smart_fetch($row, "asset tag");
|
$item[$asset_tag][$batch_counter]['asset_tag'] = Helper::array_smart_fetch($row, 'asset tag');
|
||||||
$item[$asset_tag][$batch_counter]['name'] = Helper::array_smart_fetch($row, "name");
|
$item[$asset_tag][$batch_counter]['name'] = Helper::array_smart_fetch($row, 'name');
|
||||||
$item[$asset_tag][$batch_counter]['email'] = Helper::array_smart_fetch($row, "email");
|
$item[$asset_tag][$batch_counter]['email'] = Helper::array_smart_fetch($row, 'email');
|
||||||
if ($asset = Asset::where('asset_tag', '=', $asset_tag)->first()) {
|
if ($asset = Asset::where('asset_tag', '=', $asset_tag)->first()) {
|
||||||
$item[$asset_tag][$batch_counter]['asset_id'] = $asset->id;
|
$item[$asset_tag][$batch_counter]['asset_id'] = $asset->id;
|
||||||
$base_username = User::generateFormattedNameFromFullName(Setting::getSettings()->username_format, $item[$asset_tag][$batch_counter]['name']);
|
$base_username = User::generateFormattedNameFromFullName(Setting::getSettings()->username_format, $item[$asset_tag][$batch_counter]['name']);
|
||||||
$user = User::where('username', '=', $base_username['username']);
|
$user = User::where('username', '=', $base_username['username']);
|
||||||
$user_query = ' on username '.$base_username['username'];
|
$user_query = ' on username '.$base_username['username'];
|
||||||
if ($request->input('match_firstnamelastname')=='1') {
|
if ($request->input('match_firstnamelastname') == '1') {
|
||||||
$firstnamedotlastname = User::generateFormattedNameFromFullName('firstname.lastname', $item[$asset_tag][$batch_counter]['name']);
|
$firstnamedotlastname = User::generateFormattedNameFromFullName('firstname.lastname', $item[$asset_tag][$batch_counter]['name']);
|
||||||
$item[$asset_tag][$batch_counter]['username'][] = $firstnamedotlastname['username'];
|
$item[$asset_tag][$batch_counter]['username'][] = $firstnamedotlastname['username'];
|
||||||
$user->orWhere('username', '=', $firstnamedotlastname['username']);
|
$user->orWhere('username', '=', $firstnamedotlastname['username']);
|
||||||
$user_query .= ', or on username '.$firstnamedotlastname['username'];
|
$user_query .= ', or on username '.$firstnamedotlastname['username'];
|
||||||
}
|
}
|
||||||
if ($request->input('match_flastname')=='1') {
|
if ($request->input('match_flastname') == '1') {
|
||||||
$flastname = User::generateFormattedNameFromFullName('filastname', $item[$asset_tag][$batch_counter]['name']);
|
$flastname = User::generateFormattedNameFromFullName('filastname', $item[$asset_tag][$batch_counter]['name']);
|
||||||
$item[$asset_tag][$batch_counter]['username'][] = $flastname['username'];
|
$item[$asset_tag][$batch_counter]['username'][] = $flastname['username'];
|
||||||
$user->orWhere('username', '=', $flastname['username']);
|
$user->orWhere('username', '=', $flastname['username']);
|
||||||
$user_query .= ', or on username '.$flastname['username'];
|
$user_query .= ', or on username '.$flastname['username'];
|
||||||
}
|
}
|
||||||
if ($request->input('match_firstname')=='1') {
|
if ($request->input('match_firstname') == '1') {
|
||||||
$firstname = User::generateFormattedNameFromFullName('firstname', $item[$asset_tag][$batch_counter]['name']);
|
$firstname = User::generateFormattedNameFromFullName('firstname', $item[$asset_tag][$batch_counter]['name']);
|
||||||
$item[$asset_tag][$batch_counter]['username'][] = $firstname['username'];
|
$item[$asset_tag][$batch_counter]['username'][] = $firstname['username'];
|
||||||
$user->orWhere('username', '=', $firstname['username']);
|
$user->orWhere('username', '=', $firstname['username']);
|
||||||
$user_query .= ', or on username '.$firstname['username'];
|
$user_query .= ', or on username '.$firstname['username'];
|
||||||
}
|
}
|
||||||
if ($request->input('match_email')=='1') {
|
if ($request->input('match_email') == '1') {
|
||||||
if ($item[$asset_tag][$batch_counter]['name']=='') {
|
if ($item[$asset_tag][$batch_counter]['name'] == '') {
|
||||||
$item[$asset_tag][$batch_counter]['username'][] = $user_email = User::generateEmailFromFullName($item[$asset_tag][$batch_counter]['name']);
|
$item[$asset_tag][$batch_counter]['username'][] = $user_email = User::generateEmailFromFullName($item[$asset_tag][$batch_counter]['name']);
|
||||||
$user->orWhere('username', '=', $user_email);
|
$user->orWhere('username', '=', $user_email);
|
||||||
$user_query .= ', or on username '.$user_email;
|
$user_query .= ', or on username '.$user_email;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($request->input('match_username') == '1'){
|
if ($request->input('match_username') == '1') {
|
||||||
// Added #8825: add explicit username lookup
|
// Added #8825: add explicit username lookup
|
||||||
$raw_username = $item[$asset_tag][$batch_counter]['name'];
|
$raw_username = $item[$asset_tag][$batch_counter]['name'];
|
||||||
$user->orWhere('username', '=', $raw_username);
|
$user->orWhere('username', '=', $raw_username);
|
||||||
$user_query .= ', or on username ' . $raw_username;
|
$user_query .= ', or on username '.$raw_username;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A matching user was found
|
// A matching user was found
|
||||||
|
@ -668,7 +660,7 @@ class AssetsController extends Controller
|
||||||
//$user is now matched user from db
|
//$user is now matched user from db
|
||||||
$item[$asset_tag][$batch_counter]['user_id'] = $user->id;
|
$item[$asset_tag][$batch_counter]['user_id'] = $user->id;
|
||||||
|
|
||||||
Actionlog::firstOrCreate(array(
|
Actionlog::firstOrCreate([
|
||||||
'item_id' => $asset->id,
|
'item_id' => $asset->id,
|
||||||
'item_type' => Asset::class,
|
'item_type' => Asset::class,
|
||||||
'user_id' => Auth::user()->id,
|
'user_id' => Auth::user()->id,
|
||||||
|
@ -677,7 +669,7 @@ class AssetsController extends Controller
|
||||||
'target_type' => User::class,
|
'target_type' => User::class,
|
||||||
'created_at' => $item[$asset_tag][$batch_counter]['checkout_date'],
|
'created_at' => $item[$asset_tag][$batch_counter]['checkout_date'],
|
||||||
'action_type' => 'checkout',
|
'action_type' => 'checkout',
|
||||||
));
|
]);
|
||||||
|
|
||||||
$checkin_date = $item[$asset_tag][$batch_counter]['checkin_date'];
|
$checkin_date = $item[$asset_tag][$batch_counter]['checkin_date'];
|
||||||
|
|
||||||
|
@ -685,7 +677,7 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
//if checkin date header exists, assume that empty or future date is still checked out
|
//if checkin date header exists, assume that empty or future date is still checked out
|
||||||
//if checkin is before todays date, assume it's checked in and do not assign user ID, if checkin date is in the future or blank, this is the expected checkin date, items is checked out
|
//if checkin is before todays date, assume it's checked in and do not assign user ID, if checkin date is in the future or blank, this is the expected checkin date, items is checked out
|
||||||
|
|
||||||
if ((strtotime($checkin_date) > strtotime(Carbon::now())) || (empty($checkin_date))
|
if ((strtotime($checkin_date) > strtotime(Carbon::now())) || (empty($checkin_date))
|
||||||
) {
|
) {
|
||||||
//only do this if item is checked out
|
//only do this if item is checked out
|
||||||
|
@ -694,29 +686,27 @@ class AssetsController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($checkin_date)) {
|
if (! empty($checkin_date)) {
|
||||||
//only make a checkin there is a valid checkin date or we created one on import.
|
//only make a checkin there is a valid checkin date or we created one on import.
|
||||||
Actionlog::firstOrCreate(array(
|
Actionlog::firstOrCreate([
|
||||||
'item_id' =>
|
'item_id' => $item[$asset_tag][$batch_counter]['asset_id'],
|
||||||
$item[$asset_tag][$batch_counter]['asset_id'],
|
|
||||||
'item_type' => Asset::class,
|
'item_type' => Asset::class,
|
||||||
'user_id' => Auth::user()->id,
|
'user_id' => Auth::user()->id,
|
||||||
'note' => 'Checkin imported by ' . Auth::user()->present()->fullName() . ' from history importer',
|
'note' => 'Checkin imported by '.Auth::user()->present()->fullName().' from history importer',
|
||||||
'target_id' => null,
|
'target_id' => null,
|
||||||
'created_at' => $checkin_date,
|
'created_at' => $checkin_date,
|
||||||
'action_type' => 'checkin'
|
'action_type' => 'checkin',
|
||||||
));
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($asset->save()) {
|
if ($asset->save()) {
|
||||||
$status['success'][]['asset'][$asset_tag]['msg'] = 'Asset successfully matched for '.Helper::array_smart_fetch($row, "name").$user_query.' on '.$item[$asset_tag][$batch_counter]['checkout_date'];
|
$status['success'][]['asset'][$asset_tag]['msg'] = 'Asset successfully matched for '.Helper::array_smart_fetch($row, 'name').$user_query.' on '.$item[$asset_tag][$batch_counter]['checkout_date'];
|
||||||
} else {
|
} else {
|
||||||
$status['error'][]['asset'][$asset_tag]['msg'] = 'Asset and user was matched but could not be saved.';
|
$status['error'][]['asset'][$asset_tag]['msg'] = 'Asset and user was matched but could not be saved.';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$item[$asset_tag][$batch_counter]['user_id'] = null;
|
$item[$asset_tag][$batch_counter]['user_id'] = null;
|
||||||
$status['error'][]['user'][Helper::array_smart_fetch($row, "name")]['msg'] = 'User does not exist so no checkin log was created.';
|
$status['error'][]['user'][Helper::array_smart_fetch($row, 'name')]['msg'] = 'User does not exist so no checkin log was created.';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$item[$asset_tag][$batch_counter]['asset_id'] = null;
|
$item[$asset_tag][$batch_counter]['asset_id'] = null;
|
||||||
|
@ -724,6 +714,7 @@ class AssetsController extends Controller
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('hardware/history')->with('status', $status);
|
return view('hardware/history')->with('status', $status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -752,12 +743,13 @@ class AssetsController extends Controller
|
||||||
$logaction = new Actionlog();
|
$logaction = new Actionlog();
|
||||||
$logaction->item_type = Asset::class;
|
$logaction->item_type = Asset::class;
|
||||||
$logaction->item_id = $asset->id;
|
$logaction->item_id = $asset->id;
|
||||||
$logaction->created_at = date("Y-m-d H:i:s");
|
$logaction->created_at = date('Y-m-d H:i:s');
|
||||||
$logaction->user_id = Auth::user()->id;
|
$logaction->user_id = Auth::user()->id;
|
||||||
$logaction->logaction('restored');
|
$logaction->logaction('restored');
|
||||||
|
|
||||||
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.restore.success'));
|
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.restore.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -765,41 +757,42 @@ class AssetsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('audit', Asset::class);
|
$this->authorize('audit', Asset::class);
|
||||||
$dt = Carbon::now()->addMonths(12)->toDateString();
|
$dt = Carbon::now()->addMonths(12)->toDateString();
|
||||||
|
|
||||||
return view('hardware/quickscan')->with('next_audit_date', $dt);
|
return view('hardware/quickscan')->with('next_audit_date', $dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function audit($id)
|
public function audit($id)
|
||||||
{
|
{
|
||||||
$settings = Setting::getSettings();
|
$settings = Setting::getSettings();
|
||||||
$this->authorize('audit', Asset::class);
|
$this->authorize('audit', Asset::class);
|
||||||
$dt = Carbon::now()->addMonths($settings->audit_interval)->toDateString();
|
$dt = Carbon::now()->addMonths($settings->audit_interval)->toDateString();
|
||||||
$asset = Asset::findOrFail($id);
|
$asset = Asset::findOrFail($id);
|
||||||
|
|
||||||
return view('hardware/audit')->with('asset', $asset)->with('next_audit_date', $dt)->with('locations_list');
|
return view('hardware/audit')->with('asset', $asset)->with('next_audit_date', $dt)->with('locations_list');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dueForAudit()
|
public function dueForAudit()
|
||||||
{
|
{
|
||||||
$this->authorize('audit', Asset::class);
|
$this->authorize('audit', Asset::class);
|
||||||
|
|
||||||
return view('hardware/audit-due');
|
return view('hardware/audit-due');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function overdueForAudit()
|
public function overdueForAudit()
|
||||||
{
|
{
|
||||||
$this->authorize('audit', Asset::class);
|
$this->authorize('audit', Asset::class);
|
||||||
|
|
||||||
return view('hardware/audit-overdue');
|
return view('hardware/audit-overdue');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function auditStore(Request $request, $id)
|
public function auditStore(Request $request, $id)
|
||||||
{
|
{
|
||||||
$this->authorize('audit', Asset::class);
|
$this->authorize('audit', Asset::class);
|
||||||
|
|
||||||
$rules = array(
|
$rules = [
|
||||||
'location_id' => 'exists:locations,id|nullable|numeric',
|
'location_id' => 'exists:locations,id|nullable|numeric',
|
||||||
'next_audit_date' => 'date|nullable'
|
'next_audit_date' => 'date|nullable',
|
||||||
);
|
];
|
||||||
|
|
||||||
$validator = \Validator::make($request->all(), $rules);
|
$validator = \Validator::make($request->all(), $rules);
|
||||||
|
|
||||||
|
@ -817,18 +810,19 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
// Check to see if they checked the box to update the physical location,
|
// Check to see if they checked the box to update the physical location,
|
||||||
// not just note it in the audit notes
|
// not just note it in the audit notes
|
||||||
if ($request->input('update_location')=='1') {
|
if ($request->input('update_location') == '1') {
|
||||||
\Log::debug('update location in audit');
|
\Log::debug('update location in audit');
|
||||||
$asset->location_id = $request->input('location_id');
|
$asset->location_id = $request->input('location_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ($asset->save()) {
|
if ($asset->save()) {
|
||||||
$file_name = '';
|
$file_name = '';
|
||||||
// Upload an image, if attached
|
// Upload an image, if attached
|
||||||
if ($request->hasFile('image')) {
|
if ($request->hasFile('image')) {
|
||||||
$path = 'private_uploads/audits';
|
$path = 'private_uploads/audits';
|
||||||
if (!Storage::exists($path)) Storage::makeDirectory($path, 775);
|
if (! Storage::exists($path)) {
|
||||||
|
Storage::makeDirectory($path, 775);
|
||||||
|
}
|
||||||
$upload = $image = $request->file('image');
|
$upload = $image = $request->file('image');
|
||||||
$ext = $image->getClientOriginalExtension();
|
$ext = $image->getClientOriginalExtension();
|
||||||
$file_name = 'audit-'.str_random(18).'.'.$ext;
|
$file_name = 'audit-'.str_random(18).'.'.$ext;
|
||||||
|
@ -837,7 +831,7 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
|
|
||||||
$asset->logAudit($request->input('note'), $request->input('location_id'), $file_name);
|
$asset->logAudit($request->input('note'), $request->input('location_id'), $file_name);
|
||||||
return redirect()->to("hardware")->with('success', trans('admin/hardware/message.audit.success'));
|
return redirect()->to('hardware')->with('success', trans('admin/hardware/message.audit.success'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -853,5 +847,4 @@ class AssetsController extends Controller
|
||||||
|
|
||||||
return view('hardware/requested', compact('requestedItems'));
|
return view('hardware/requested', compact('requestedItems'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,14 +28,15 @@ class BulkAssetsController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('update', Asset::class);
|
$this->authorize('update', Asset::class);
|
||||||
|
|
||||||
if (!$request->filled('ids')) {
|
if (! $request->filled('ids')) {
|
||||||
return redirect()->back()->with('error', 'No assets selected');
|
return redirect()->back()->with('error', 'No assets selected');
|
||||||
}
|
}
|
||||||
|
|
||||||
$asset_ids = array_keys($request->input('ids'));
|
|
||||||
|
$asset_ids = array_values(array_unique($request->input('ids')));
|
||||||
|
|
||||||
if ($request->filled('bulk_actions')) {
|
if ($request->filled('bulk_actions')) {
|
||||||
switch($request->input('bulk_actions')) {
|
switch ($request->input('bulk_actions')) {
|
||||||
case 'labels':
|
case 'labels':
|
||||||
return view('hardware/labels')
|
return view('hardware/labels')
|
||||||
->with('assets', Asset::find($asset_ids))
|
->with('assets', Asset::find($asset_ids))
|
||||||
|
@ -47,13 +48,15 @@ class BulkAssetsController extends Controller
|
||||||
$assets->each(function ($asset) {
|
$assets->each(function ($asset) {
|
||||||
$this->authorize('delete', $asset);
|
$this->authorize('delete', $asset);
|
||||||
});
|
});
|
||||||
|
|
||||||
return view('hardware/bulk-delete')->with('assets', $assets);
|
return view('hardware/bulk-delete')->with('assets', $assets);
|
||||||
case 'edit':
|
case 'edit':
|
||||||
return view('hardware/bulk')
|
return view('hardware/bulk')
|
||||||
->with('assets', request('ids'))
|
->with('assets', $asset_ids)
|
||||||
->with('statuslabel_list', Helper::statusLabelList());
|
->with('statuslabel_list', Helper::statusLabelList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()->with('error', 'No action selected');
|
return redirect()->back()->with('error', 'No action selected');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,8 +74,8 @@ class BulkAssetsController extends Controller
|
||||||
|
|
||||||
\Log::debug($request->input('ids'));
|
\Log::debug($request->input('ids'));
|
||||||
|
|
||||||
if(!$request->filled('ids') || count($request->input('ids')) <= 0) {
|
if (! $request->filled('ids') || count($request->input('ids')) <= 0) {
|
||||||
return redirect()->route("hardware.index")->with('warning', trans('No assets selected, so nothing was updated.'));
|
return redirect()->route('hardware.index')->with('warning', trans('No assets selected, so nothing was updated.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$assets = array_keys($request->input('ids'));
|
$assets = array_keys($request->input('ids'));
|
||||||
|
@ -90,6 +93,7 @@ class BulkAssetsController extends Controller
|
||||||
|| ($request->filled('model_id'))
|
|| ($request->filled('model_id'))
|
||||||
) {
|
) {
|
||||||
foreach ($assets as $assetId) {
|
foreach ($assets as $assetId) {
|
||||||
|
|
||||||
$this->update_array = [];
|
$this->update_array = [];
|
||||||
|
|
||||||
$this->conditionallyAddItem('purchase_date')
|
$this->conditionallyAddItem('purchase_date')
|
||||||
|
@ -102,12 +106,12 @@ class BulkAssetsController extends Controller
|
||||||
->conditionallyAddItem('warranty_months');
|
->conditionallyAddItem('warranty_months');
|
||||||
|
|
||||||
if ($request->filled('purchase_cost')) {
|
if ($request->filled('purchase_cost')) {
|
||||||
$this->update_array['purchase_cost'] = Helper::ParseFloat($request->input('purchase_cost'));
|
$this->update_array['purchase_cost'] = Helper::ParseCurrency($request->input('purchase_cost'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($request->filled('company_id')) {
|
if ($request->filled('company_id')) {
|
||||||
$this->update_array['company_id'] = $request->input('company_id');
|
$this->update_array['company_id'] = $request->input('company_id');
|
||||||
if ($request->input('company_id')=="clear") {
|
if ($request->input('company_id') == 'clear') {
|
||||||
$this->update_array['company_id'] = null;
|
$this->update_array['company_id'] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,29 +127,31 @@ class BulkAssetsController extends Controller
|
||||||
->where('id', $assetId)
|
->where('id', $assetId)
|
||||||
->update($this->update_array);
|
->update($this->update_array);
|
||||||
} // endforeach
|
} // endforeach
|
||||||
return redirect()->route("hardware.index")->with('success', trans('admin/hardware/message.update.success'));
|
|
||||||
// no values given, nothing to update
|
|
||||||
}
|
|
||||||
return redirect()->route("hardware.index")->with('warning', trans('admin/hardware/message.update.nothing_updated'));
|
|
||||||
|
|
||||||
|
return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.update.success'));
|
||||||
|
// no values given, nothing to update
|
||||||
|
}
|
||||||
|
|
||||||
|
return redirect()->route('hardware.index')->with('warning', trans('admin/hardware/message.update.nothing_updated'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array to store update data per item
|
* Array to store update data per item
|
||||||
* @var Array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $update_array;
|
private $update_array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds parameter to update array for an item if it exists in request
|
* Adds parameter to update array for an item if it exists in request
|
||||||
* @param String $field field name
|
* @param string $field field name
|
||||||
* @return BulkAssetsController Model for Chaining
|
* @return BulkAssetsController Model for Chaining
|
||||||
*/
|
*/
|
||||||
protected function conditionallyAddItem($field)
|
protected function conditionallyAddItem($field)
|
||||||
{
|
{
|
||||||
if(request()->filled($field)) {
|
if (request()->filled($field)) {
|
||||||
$this->update_array[$field] = request()->input($field);
|
$this->update_array[$field] = request()->input($field);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,10 +179,12 @@ class BulkAssetsController extends Controller
|
||||||
->where('id', $asset->id)
|
->where('id', $asset->id)
|
||||||
->update($update_array);
|
->update($update_array);
|
||||||
} // endforeach
|
} // endforeach
|
||||||
return redirect()->to("hardware")->with('success', trans('admin/hardware/message.delete.success'));
|
|
||||||
|
return redirect()->to('hardware')->with('success', trans('admin/hardware/message.delete.success'));
|
||||||
// no values given, nothing to update
|
// no values given, nothing to update
|
||||||
}
|
}
|
||||||
return redirect()->to("hardware")->with('info', trans('admin/hardware/message.delete.nothing_updated'));
|
|
||||||
|
return redirect()->to('hardware')->with('info', trans('admin/hardware/message.delete.nothing_updated'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,21 +210,21 @@ class BulkAssetsController extends Controller
|
||||||
|
|
||||||
$target = $this->determineCheckoutTarget();
|
$target = $this->determineCheckoutTarget();
|
||||||
|
|
||||||
if (!is_array($request->get('selected_assets'))) {
|
if (! is_array($request->get('selected_assets'))) {
|
||||||
return redirect()->route('hardware/bulkcheckout')->withInput()->with('error', trans('admin/hardware/message.checkout.no_assets_selected'));
|
return redirect()->route('hardware/bulkcheckout')->withInput()->with('error', trans('admin/hardware/message.checkout.no_assets_selected'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$asset_ids = array_filter($request->get('selected_assets'));
|
$asset_ids = array_filter($request->get('selected_assets'));
|
||||||
|
|
||||||
if(request('checkout_to_type') =='asset') {
|
if (request('checkout_to_type') == 'asset') {
|
||||||
foreach ($asset_ids as $asset_id) {
|
foreach ($asset_ids as $asset_id) {
|
||||||
if ($target->id == $asset_id) {
|
if ($target->id == $asset_id) {
|
||||||
return redirect()->back()->with('error', 'You cannot check an asset out to itself.');
|
return redirect()->back()->with('error', 'You cannot check an asset out to itself.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$checkout_at = date("Y-m-d H:i:s");
|
$checkout_at = date('Y-m-d H:i:s');
|
||||||
if (($request->filled('checkout_at')) && ($request->get('checkout_at')!= date("Y-m-d"))) {
|
if (($request->filled('checkout_at')) && ($request->get('checkout_at') != date('Y-m-d'))) {
|
||||||
$checkout_at = e($request->get('checkout_at'));
|
$checkout_at = e($request->get('checkout_at'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,13 +236,12 @@ class BulkAssetsController extends Controller
|
||||||
|
|
||||||
$errors = [];
|
$errors = [];
|
||||||
DB::transaction(function () use ($target, $admin, $checkout_at, $expected_checkin, $errors, $asset_ids, $request) {
|
DB::transaction(function () use ($target, $admin, $checkout_at, $expected_checkin, $errors, $asset_ids, $request) {
|
||||||
|
|
||||||
foreach ($asset_ids as $asset_id) {
|
foreach ($asset_ids as $asset_id) {
|
||||||
$asset = Asset::findOrFail($asset_id);
|
$asset = Asset::findOrFail($asset_id);
|
||||||
$this->authorize('checkout', $asset);
|
$this->authorize('checkout', $asset);
|
||||||
$error = $asset->checkOut($target, $admin, $checkout_at, $expected_checkin, e($request->get('note')), null);
|
$error = $asset->checkOut($target, $admin, $checkout_at, $expected_checkin, e($request->get('note')), null);
|
||||||
|
|
||||||
if ($target->location_id!='') {
|
if ($target->location_id != '') {
|
||||||
$asset->location_id = $target->location_id;
|
$asset->location_id = $target->location_id;
|
||||||
$asset->unsetEventDispatcher();
|
$asset->unsetEventDispatcher();
|
||||||
$asset->save();
|
$asset->save();
|
||||||
|
@ -246,14 +253,14 @@ class BulkAssetsController extends Controller
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!$errors) {
|
if (! $errors) {
|
||||||
// Redirect to the new asset page
|
// Redirect to the new asset page
|
||||||
return redirect()->to("hardware")->with('success', trans('admin/hardware/message.checkout.success'));
|
return redirect()->to('hardware')->with('success', trans('admin/hardware/message.checkout.success'));
|
||||||
}
|
}
|
||||||
// Redirect to the asset management page with error
|
// Redirect to the asset management page with error
|
||||||
return redirect()->to("hardware/bulk-checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($errors);
|
return redirect()->to('hardware/bulk-checkout')->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($errors);
|
||||||
} catch (ModelNotFoundException $e) {
|
} catch (ModelNotFoundException $e) {
|
||||||
return redirect()->to("hardware/bulk-checkout")->with('error', $e->getErrors());
|
return redirect()->to('hardware/bulk-checkout')->with('error', $e->getErrors());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ class ForgotPasswordController extends Controller
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->middleware('guest');
|
$this->middleware('guest');
|
||||||
|
$this->middleware('throttle:5,1', ['except' => 'showLinkRequestForm']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,8 +42,6 @@ class ForgotPasswordController extends Controller
|
||||||
return property_exists($this, 'subject') ? $this->subject : \Lang::get('mail.reset_link');
|
return property_exists($this, 'subject') ? $this->subject : \Lang::get('mail.reset_link');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a reset link to the given user.
|
* Send a reset link to the given user.
|
||||||
*
|
*
|
||||||
|
@ -57,13 +56,10 @@ class ForgotPasswordController extends Controller
|
||||||
* buffer overflow issues with attackers sending very large
|
* buffer overflow issues with attackers sending very large
|
||||||
* payloads through.
|
* payloads through.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'username' => ['required', 'max:255'],
|
'username' => ['required', 'max:255'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If we find a matching email with an activated user, we will
|
* If we find a matching email with an activated user, we will
|
||||||
* send the password reset link to the user.
|
* send the password reset link to the user.
|
||||||
|
@ -71,7 +67,7 @@ class ForgotPasswordController extends Controller
|
||||||
* Once we have attempted to send the link, we will examine the response
|
* Once we have attempted to send the link, we will examine the response
|
||||||
* then see the message we need to show to the user. Finally, we'll send out a proper response.
|
* then see the message we need to show to the user. Finally, we'll send out a proper response.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$response = null;
|
$response = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -93,7 +89,6 @@ class ForgotPasswordController extends Controller
|
||||||
\Log::info('Password reset attempt: User matching username '.$request->input('username').' NOT FOUND or user is inactive');
|
\Log::info('Password reset attempt: User matching username '.$request->input('username').' NOT FOUND or user is inactive');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If an error was returned by the password broker, we will get this message
|
* If an error was returned by the password broker, we will get this message
|
||||||
* translated so we can notify a user of the problem. We'll redirect back
|
* translated so we can notify a user of the problem. We'll redirect back
|
||||||
|
@ -109,8 +104,6 @@ class ForgotPasswordController extends Controller
|
||||||
|
|
||||||
// Regardless of response, we do not want to disclose the status of a user account,
|
// Regardless of response, we do not want to disclose the status of a user account,
|
||||||
// so we give them a generic "If this exists, we're TOTALLY gonna email you" response
|
// so we give them a generic "If this exists, we're TOTALLY gonna email you" response
|
||||||
return redirect()->route('login')->with('success',trans('passwords.sent'));
|
return redirect()->route('login')->with('success', trans('passwords.sent'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ use Redirect;
|
||||||
*/
|
*/
|
||||||
class LoginController extends Controller
|
class LoginController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
use ThrottlesLogins;
|
use ThrottlesLogins;
|
||||||
|
|
||||||
// This tells the auth controller to use username instead of email address
|
// This tells the auth controller to use username instead of email address
|
||||||
|
@ -61,13 +60,13 @@ class LoginController extends Controller
|
||||||
public function __construct(/*LdapAd $ldap, */ Saml $saml)
|
public function __construct(/*LdapAd $ldap, */ Saml $saml)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->middleware('guest', ['except' => ['logout','postTwoFactorAuth','getTwoFactorAuth','getTwoFactorEnroll']]);
|
$this->middleware('guest', ['except' => ['logout', 'postTwoFactorAuth', 'getTwoFactorAuth', 'getTwoFactorEnroll']]);
|
||||||
Session::put('backUrl', \URL::previous());
|
Session::put('backUrl', \URL::previous());
|
||||||
// $this->ldap = $ldap;
|
// $this->ldap = $ldap;
|
||||||
$this->saml = $saml;
|
$this->saml = $saml;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showLoginForm(Request $request)
|
public function showLoginForm(Request $request)
|
||||||
{
|
{
|
||||||
$this->loginViaRemoteUser($request);
|
$this->loginViaRemoteUser($request);
|
||||||
$this->loginViaSaml($request);
|
$this->loginViaSaml($request);
|
||||||
|
@ -75,11 +74,11 @@ class LoginController extends Controller
|
||||||
return redirect()->intended('/');
|
return redirect()->intended('/');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->saml->isEnabled() && Setting::getSettings()->saml_forcelogin == "1" && !($request->has('nosaml') || $request->session()->has('error'))) {
|
if ($this->saml->isEnabled() && Setting::getSettings()->saml_forcelogin == '1' && ! ($request->has('nosaml') || $request->session()->has('error'))) {
|
||||||
return redirect()->route('saml.login');
|
return redirect()->route('saml.login');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Setting::getSettings()->login_common_disabled == "1") {
|
if (Setting::getSettings()->login_common_disabled == '1') {
|
||||||
return view('errors.403');
|
return view('errors.403');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,26 +87,26 @@ class LoginController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log in a user by SAML
|
* Log in a user by SAML
|
||||||
*
|
*
|
||||||
* @author Johnson Yi <jyi.dev@outlook.com>
|
* @author Johnson Yi <jyi.dev@outlook.com>
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
*
|
*
|
||||||
* @return User
|
* @return User
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private function loginViaSaml(Request $request)
|
private function loginViaSaml(Request $request)
|
||||||
{
|
{
|
||||||
$saml = $this->saml;
|
$saml = $this->saml;
|
||||||
$samlData = $request->session()->get('saml_login');
|
$samlData = $request->session()->get('saml_login');
|
||||||
if ($saml->isEnabled() && !empty($samlData)) {
|
if ($saml->isEnabled() && ! empty($samlData)) {
|
||||||
try {
|
try {
|
||||||
Log::debug("Attempting to log user in by SAML authentication.");
|
Log::debug('Attempting to log user in by SAML authentication.');
|
||||||
$user = $saml->samlLogin($samlData);
|
$user = $saml->samlLogin($samlData);
|
||||||
if(!is_null($user)) {
|
if (! is_null($user)) {
|
||||||
Auth::login($user);
|
Auth::login($user);
|
||||||
} else {
|
} else {
|
||||||
$username = $saml->getUsername();
|
$username = $saml->getUsername();
|
||||||
|
@ -121,7 +120,7 @@ class LoginController extends Controller
|
||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::warning("There was an error authenticating the SAML user: " . $e->getMessage());
|
\Log::warning('There was an error authenticating the SAML user: '.$e->getMessage());
|
||||||
throw new \Exception($e->getMessage());
|
throw new \Exception($e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,24 +128,24 @@ class LoginController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log in a user by LDAP
|
* Log in a user by LDAP
|
||||||
*
|
*
|
||||||
* @author Wes Hulette <jwhulette@gmail.com>
|
* @author Wes Hulette <jwhulette@gmail.com>
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
*
|
*
|
||||||
* @return User
|
* @return User
|
||||||
*
|
*
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private function loginViaLdap(Request $request): User
|
private function loginViaLdap(Request $request): User
|
||||||
{
|
{
|
||||||
$ldap = \App::make( LdapAd::class);
|
$ldap = \App::make(LdapAd::class);
|
||||||
try {
|
try {
|
||||||
return $ldap->ldapLogin($request->input('username'), $request->input('password'));
|
return $ldap->ldapLogin($request->input('username'), $request->input('password'));
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
LOG::debug("LDAP user login: " . $ex->getMessage());
|
LOG::debug('LDAP user login: '.$ex->getMessage());
|
||||||
throw new \Exception($ex->getMessage());
|
throw new \Exception($ex->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +154,10 @@ class LoginController extends Controller
|
||||||
{
|
{
|
||||||
$header_name = Setting::getSettings()->login_remote_user_header_name ?: 'REMOTE_USER';
|
$header_name = Setting::getSettings()->login_remote_user_header_name ?: 'REMOTE_USER';
|
||||||
$remote_user = $request->server($header_name);
|
$remote_user = $request->server($header_name);
|
||||||
if (Setting::getSettings()->login_remote_user_enabled == "1" && isset($remote_user) && !empty($remote_user)) {
|
if (!isset($remote_user)) {
|
||||||
|
$remote_user = $request->server('REDIRECT_'.$header_name);
|
||||||
|
}
|
||||||
|
if (Setting::getSettings()->login_remote_user_enabled == '1' && isset($remote_user) && ! empty($remote_user)) {
|
||||||
Log::debug("Authenticating via HTTP header $header_name.");
|
Log::debug("Authenticating via HTTP header $header_name.");
|
||||||
|
|
||||||
$strip_prefixes = [
|
$strip_prefixes = [
|
||||||
|
@ -170,7 +172,7 @@ class LoginController extends Controller
|
||||||
|
|
||||||
$pos = 0;
|
$pos = 0;
|
||||||
foreach ($strip_prefixes as $needle) {
|
foreach ($strip_prefixes as $needle) {
|
||||||
if (($pos = strpos($remote_user, $needle)) !== FALSE) {
|
if (($pos = strpos($remote_user, $needle)) !== false) {
|
||||||
$pos += strlen($needle);
|
$pos += strlen($needle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -178,14 +180,16 @@ class LoginController extends Controller
|
||||||
|
|
||||||
if ($pos > 0) {
|
if ($pos > 0) {
|
||||||
$remote_user = substr($remote_user, $pos);
|
$remote_user = substr($remote_user, $pos);
|
||||||
};
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$user = User::where('username', '=', $remote_user)->whereNull('deleted_at')->where('activated', '=', '1')->first();
|
$user = User::where('username', '=', $remote_user)->whereNull('deleted_at')->where('activated', '=', '1')->first();
|
||||||
Log::debug("Remote user auth lookup complete");
|
Log::debug('Remote user auth lookup complete');
|
||||||
if(!is_null($user)) Auth::login($user, $request->input('remember'));
|
if (! is_null($user)) {
|
||||||
} catch(Exception $e) {
|
Auth::login($user, $request->input('remember'));
|
||||||
Log::debug("There was an error authenticating the Remote user: " . $e->getMessage());
|
}
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::debug('There was an error authenticating the Remote user: '.$e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -197,7 +201,7 @@ class LoginController extends Controller
|
||||||
*/
|
*/
|
||||||
public function login(Request $request)
|
public function login(Request $request)
|
||||||
{
|
{
|
||||||
if (Setting::getSettings()->login_common_disabled == "1") {
|
if (Setting::getSettings()->login_common_disabled == '1') {
|
||||||
return view('errors.403');
|
return view('errors.403');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,6 +216,7 @@ class LoginController extends Controller
|
||||||
|
|
||||||
if ($lockedOut = $this->hasTooManyLoginAttempts($request)) {
|
if ($lockedOut = $this->hasTooManyLoginAttempts($request)) {
|
||||||
$this->fireLockoutEvent($request);
|
$this->fireLockoutEvent($request);
|
||||||
|
|
||||||
return $this->sendLockoutResponse($request);
|
return $this->sendLockoutResponse($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,34 +224,33 @@ class LoginController extends Controller
|
||||||
|
|
||||||
// Should we even check for LDAP users?
|
// Should we even check for LDAP users?
|
||||||
if (Setting::getSettings()->ldap_enabled) { // avoid hitting the $this->ldap
|
if (Setting::getSettings()->ldap_enabled) { // avoid hitting the $this->ldap
|
||||||
LOG::debug("LDAP is enabled.");
|
LOG::debug('LDAP is enabled.');
|
||||||
try {
|
try {
|
||||||
LOG::debug("Attempting to log user in by LDAP authentication.");
|
LOG::debug('Attempting to log user in by LDAP authentication.');
|
||||||
$user = $this->loginViaLdap($request);
|
$user = $this->loginViaLdap($request);
|
||||||
Auth::login($user, $request->input('remember'));
|
Auth::login($user, $request->input('remember'));
|
||||||
|
|
||||||
// If the user was unable to login via LDAP, log the error and let them fall through to
|
// If the user was unable to login via LDAP, log the error and let them fall through to
|
||||||
// local authentication.
|
// local authentication.
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Log::debug("There was an error authenticating the LDAP user: ".$e->getMessage());
|
Log::debug('There was an error authenticating the LDAP user: '.$e->getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user wasn't authenticated via LDAP, skip to local auth
|
// If the user wasn't authenticated via LDAP, skip to local auth
|
||||||
if (!$user) {
|
if (! $user) {
|
||||||
Log::debug("Authenticating user against database.");
|
Log::debug('Authenticating user against database.');
|
||||||
// Try to log the user in
|
// Try to log the user in
|
||||||
if (!Auth::attempt(['username' => $request->input('username'), 'password' => $request->input('password'), 'activated' => 1], $request->input('remember'))) {
|
if (! Auth::attempt(['username' => $request->input('username'), 'password' => $request->input('password'), 'activated' => 1], $request->input('remember'))) {
|
||||||
|
if (! $lockedOut) {
|
||||||
if (!$lockedOut) {
|
|
||||||
$this->incrementLoginAttempts($request);
|
$this->incrementLoginAttempts($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
Log::debug("Local authentication failed.");
|
Log::debug('Local authentication failed.');
|
||||||
|
|
||||||
return redirect()->back()->withInput()->with('error', trans('auth/message.account_not_found'));
|
return redirect()->back()->withInput()->with('error', trans('auth/message.account_not_found'));
|
||||||
} else {
|
} else {
|
||||||
|
$this->clearLoginAttempts($request);
|
||||||
$this->clearLoginAttempts($request);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -259,7 +263,6 @@ class LoginController extends Controller
|
||||||
return redirect()->intended()->with('success', trans('auth/message.signin.success'));
|
return redirect()->intended()->with('success', trans('auth/message.signin.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Two factor enrollment page
|
* Two factor enrollment page
|
||||||
*
|
*
|
||||||
|
@ -269,11 +272,10 @@ class LoginController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
// Make sure the user is logged in
|
// Make sure the user is logged in
|
||||||
if (!Auth::check()) {
|
if (! Auth::check()) {
|
||||||
return redirect()->route('login')->with('error', trans('auth/general.login_prompt'));
|
return redirect()->route('login')->with('error', trans('auth/general.login_prompt'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$settings = Setting::getSettings();
|
$settings = Setting::getSettings();
|
||||||
$user = Auth::user();
|
$user = Auth::user();
|
||||||
|
|
||||||
|
@ -283,7 +285,7 @@ class LoginController extends Controller
|
||||||
// While you can access this page directly, enrolling a device when 2FA isn't enforced
|
// While you can access this page directly, enrolling a device when 2FA isn't enforced
|
||||||
// won't cause any harm.
|
// won't cause any harm.
|
||||||
|
|
||||||
if (($user->two_factor_secret!='') && ($user->two_factor_enrolled==1)) {
|
if (($user->two_factor_secret != '') && ($user->two_factor_enrolled == 1)) {
|
||||||
return redirect()->route('two-factor')->with('error', trans('auth/message.two_factor.already_enrolled'));
|
return redirect()->route('two-factor')->with('error', trans('auth/message.two_factor.already_enrolled'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,7 +312,6 @@ class LoginController extends Controller
|
||||||
return view('auth.two_factor_enroll')->with('barcode_obj', $barcode_obj);
|
return view('auth.two_factor_enroll')->with('barcode_obj', $barcode_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Two factor code form page
|
* Two factor code form page
|
||||||
*
|
*
|
||||||
|
@ -319,7 +320,7 @@ class LoginController extends Controller
|
||||||
public function getTwoFactorAuth()
|
public function getTwoFactorAuth()
|
||||||
{
|
{
|
||||||
// Check that the user is logged in
|
// Check that the user is logged in
|
||||||
if (!Auth::check()) {
|
if (! Auth::check()) {
|
||||||
return redirect()->route('login')->with('error', trans('auth/general.login_prompt'));
|
return redirect()->route('login')->with('error', trans('auth/general.login_prompt'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +329,7 @@ class LoginController extends Controller
|
||||||
// Check whether there is a device enrolled.
|
// Check whether there is a device enrolled.
|
||||||
// This *should* be handled via the \App\Http\Middleware\CheckForTwoFactor middleware
|
// This *should* be handled via the \App\Http\Middleware\CheckForTwoFactor middleware
|
||||||
// but we're just making sure (in case someone edited the database directly, etc)
|
// but we're just making sure (in case someone edited the database directly, etc)
|
||||||
if (($user->two_factor_secret=='') || ($user->two_factor_enrolled!=1)) {
|
if (($user->two_factor_secret == '') || ($user->two_factor_enrolled != 1)) {
|
||||||
return redirect()->route('two-factor-enroll');
|
return redirect()->route('two-factor-enroll');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,16 +345,15 @@ class LoginController extends Controller
|
||||||
*/
|
*/
|
||||||
public function postTwoFactorAuth(Request $request)
|
public function postTwoFactorAuth(Request $request)
|
||||||
{
|
{
|
||||||
|
if (! Auth::check()) {
|
||||||
if (!Auth::check()) {
|
|
||||||
return redirect()->route('login')->with('error', trans('auth/general.login_prompt'));
|
return redirect()->route('login')->with('error', trans('auth/general.login_prompt'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$request->filled('two_factor_secret')) {
|
if (! $request->filled('two_factor_secret')) {
|
||||||
return redirect()->route('two-factor')->with('error', trans('auth/message.two_factor.code_required'));
|
return redirect()->route('two-factor')->with('error', trans('auth/message.two_factor.code_required'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$request->has('two_factor_secret')) {
|
if (! $request->has('two_factor_secret')) {
|
||||||
return redirect()->route('two-factor')->with('error', 'Two-factor code is required.');
|
return redirect()->route('two-factor')->with('error', 'Two-factor code is required.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -364,15 +364,13 @@ class LoginController extends Controller
|
||||||
$user->two_factor_enrolled = 1;
|
$user->two_factor_enrolled = 1;
|
||||||
$user->save();
|
$user->save();
|
||||||
$request->session()->put('2fa_authed', 'true');
|
$request->session()->put('2fa_authed', 'true');
|
||||||
|
|
||||||
return redirect()->route('home')->with('success', 'You are logged in!');
|
return redirect()->route('home')->with('success', 'You are logged in!');
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('two-factor')->with('error', trans('auth/message.two_factor.invalid_code'));
|
return redirect()->route('two-factor')->with('error', trans('auth/message.two_factor.invalid_code'));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logout page.
|
* Logout page.
|
||||||
*
|
*
|
||||||
|
@ -390,15 +388,15 @@ class LoginController extends Controller
|
||||||
if ($saml->isEnabled()) {
|
if ($saml->isEnabled()) {
|
||||||
$auth = $saml->getAuth();
|
$auth = $saml->getAuth();
|
||||||
$sloRedirectUrl = $request->session()->get('saml_slo_redirect_url');
|
$sloRedirectUrl = $request->session()->get('saml_slo_redirect_url');
|
||||||
|
|
||||||
if (!empty($auth->getSLOurl()) && $settings->saml_slo == '1' && $saml->isAuthenticated() && empty($sloRedirectUrl)) {
|
if (! empty($auth->getSLOurl()) && $settings->saml_slo == '1' && $saml->isAuthenticated() && empty($sloRedirectUrl)) {
|
||||||
$sloRequestUrl = $auth->logout(null, array(), $saml->getNameId(), $saml->getSessionIndex(), true, $saml->getNameIdFormat(), $saml->getNameIdNameQualifier(), $saml->getNameIdSPNameQualifier());
|
$sloRequestUrl = $auth->logout(null, [], $saml->getNameId(), $saml->getSessionIndex(), true, $saml->getNameIdFormat(), $saml->getNameIdNameQualifier(), $saml->getNameIdSPNameQualifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
$saml->clearData();
|
$saml->clearData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($sloRequestUrl)) {
|
if (! empty($sloRequestUrl)) {
|
||||||
return redirect()->away($sloRequestUrl);
|
return redirect()->away($sloRequestUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,11 +405,11 @@ class LoginController extends Controller
|
||||||
$request->session()->regenerate(true);
|
$request->session()->regenerate(true);
|
||||||
Auth::logout();
|
Auth::logout();
|
||||||
|
|
||||||
if (!empty($sloRedirectUrl)) {
|
if (! empty($sloRedirectUrl)) {
|
||||||
return redirect()->away($sloRedirectUrl);
|
return redirect()->away($sloRedirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
$customLogoutUrl = $settings->login_remote_user_custom_logout_url ;
|
$customLogoutUrl = $settings->login_remote_user_custom_logout_url;
|
||||||
if ($settings->login_remote_user_enabled == '1' && $customLogoutUrl != '') {
|
if ($settings->login_remote_user_enabled == '1' && $customLogoutUrl != '') {
|
||||||
return redirect()->away($customLogoutUrl);
|
return redirect()->away($customLogoutUrl);
|
||||||
}
|
}
|
||||||
|
@ -419,7 +417,6 @@ class LoginController extends Controller
|
||||||
return redirect()->route('login')->with(['success' => trans('auth/message.logout.success'), 'loggedout' => true]);
|
return redirect()->route('login')->with(['success' => trans('auth/message.logout.success'), 'loggedout' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a validator for an incoming registration request.
|
* Get a validator for an incoming registration request.
|
||||||
*
|
*
|
||||||
|
@ -434,7 +431,6 @@ class LoginController extends Controller
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function username()
|
public function username()
|
||||||
{
|
{
|
||||||
return 'username';
|
return 'username';
|
||||||
|
@ -461,7 +457,6 @@ class LoginController extends Controller
|
||||||
->withErrors([$this->username() => $message]);
|
->withErrors([$this->username() => $message]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override the lockout time and duration
|
* Override the lockout time and duration
|
||||||
*
|
*
|
||||||
|
@ -480,13 +475,13 @@ class LoginController extends Controller
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function legacyAuthRedirect() {
|
public function legacyAuthRedirect()
|
||||||
|
{
|
||||||
return redirect()->route('login');
|
return redirect()->route('login');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function redirectTo()
|
public function redirectTo()
|
||||||
{
|
{
|
||||||
return Session::get('backUrl') ? Session::get('backUrl') : $this->redirectTo;
|
return Session::get('backUrl') ? Session::get('backUrl') : $this->redirectTo;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,17 +6,18 @@ use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
class RegisterController extends Controller
|
class RegisterController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->middleware('guest');
|
$this->middleware('guest');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showRegistrationForm() {
|
public function showRegistrationForm()
|
||||||
abort(404,'Page not found');
|
{
|
||||||
|
abort(404, 'Page not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register() {
|
public function register()
|
||||||
abort(404,'Page not found');
|
{
|
||||||
|
abort(404, 'Page not found');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,29 +54,25 @@ class ResetPasswordController extends Controller
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function credentials(Request $request)
|
protected function credentials(Request $request)
|
||||||
{
|
{
|
||||||
return $request->only(
|
return $request->only(
|
||||||
'username', 'password', 'password_confirmation', 'token'
|
'username', 'password', 'password_confirmation', 'token'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function showResetForm(Request $request, $token = null)
|
public function showResetForm(Request $request, $token = null)
|
||||||
{
|
{
|
||||||
return view('auth.passwords.reset')->with(
|
return view('auth.passwords.reset')->with(
|
||||||
[
|
[
|
||||||
'token' => $token,
|
'token' => $token,
|
||||||
'username' => $request->input('username')
|
'username' => $request->input('username'),
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function reset(Request $request)
|
public function reset(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$messages = [
|
$messages = [
|
||||||
'password.not_in' => trans('validation.disallow_same_pwd_as_user_fields'),
|
'password.not_in' => trans('validation.disallow_same_pwd_as_user_fields'),
|
||||||
];
|
];
|
||||||
|
@ -87,15 +83,13 @@ class ResetPasswordController extends Controller
|
||||||
$user = User::where('username', '=', $request->input('username'))->first();
|
$user = User::where('username', '=', $request->input('username'))->first();
|
||||||
|
|
||||||
$broker = $this->broker();
|
$broker = $this->broker();
|
||||||
if (strpos(Setting::passwordComplexityRulesSaving('store'), 'disallow_same_pwd_as_user_fields') !== FALSE) {
|
if (strpos(Setting::passwordComplexityRulesSaving('store'), 'disallow_same_pwd_as_user_fields') !== false) {
|
||||||
$request->validate(
|
$request->validate(
|
||||||
[
|
[
|
||||||
'password' => 'required|notIn:["'.$user->email.'","'.$user->username.'","'.$user->first_name.'","'.$user->last_name.'"'
|
'password' => 'required|notIn:["'.$user->email.'","'.$user->username.'","'.$user->first_name.'","'.$user->last_name.'"',
|
||||||
], $messages);
|
], $messages);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$response = $broker->reset(
|
$response = $broker->reset(
|
||||||
$this->credentials($request), function ($user, $password) {
|
$this->credentials($request), function ($user, $password) {
|
||||||
$this->resetPassword($user, $password);
|
$this->resetPassword($user, $password);
|
||||||
|
@ -107,14 +101,10 @@ class ResetPasswordController extends Controller
|
||||||
: $this->sendResetFailedResponse($request, $response);
|
: $this->sendResetFailedResponse($request, $response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected function sendResetFailedResponse(Request $request, $response)
|
protected function sendResetFailedResponse(Request $request, $response)
|
||||||
{
|
{
|
||||||
return redirect()->back()
|
return redirect()->back()
|
||||||
->withInput(['username'=> $request->input('username')])
|
->withInput(['username'=> $request->input('username')])
|
||||||
->withErrors(['username' => trans($response), 'password' => trans($response)]);
|
->withErrors(['username' => trans($response), 'password' => trans($response)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers\Auth;
|
namespace App\Http\Controllers\Auth;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Services\Saml;
|
use App\Services\Saml;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Log;
|
use Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,20 +30,20 @@ class SamlController extends Controller
|
||||||
{
|
{
|
||||||
$this->saml = $saml;
|
$this->saml = $saml;
|
||||||
|
|
||||||
$this->middleware('guest', ['except' => ['metadata','sls']]);
|
$this->middleware('guest', ['except' => ['metadata', 'sls']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return SAML SP metadata for Snipe-IT
|
* Return SAML SP metadata for Snipe-IT
|
||||||
*
|
*
|
||||||
* /saml/metadata
|
* /saml/metadata
|
||||||
*
|
*
|
||||||
* @author Johnson Yi <jyi.dev@outlook.com>
|
* @author Johnson Yi <jyi.dev@outlook.com>
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
*
|
*
|
||||||
* @return Response
|
* @return Response
|
||||||
*/
|
*/
|
||||||
public function metadata(Request $request)
|
public function metadata(Request $request)
|
||||||
|
@ -53,7 +53,7 @@ class SamlController extends Controller
|
||||||
if (empty($metadata)) {
|
if (empty($metadata)) {
|
||||||
return response()->view('errors.403', [], 403);
|
return response()->view('errors.403', [], 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->streamDownload(function () use ($metadata) {
|
return response()->streamDownload(function () use ($metadata) {
|
||||||
echo $metadata;
|
echo $metadata;
|
||||||
}, 'snipe-it-metadata.xml', ['Content-Type' => 'text/xml']);
|
}, 'snipe-it-metadata.xml', ['Content-Type' => 'text/xml']);
|
||||||
|
@ -61,36 +61,37 @@ class SamlController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Begin the SP-Initiated SSO by sending AuthN to the IdP.
|
* Begin the SP-Initiated SSO by sending AuthN to the IdP.
|
||||||
*
|
*
|
||||||
* /login/saml
|
* /login/saml
|
||||||
*
|
*
|
||||||
* @author Johnson Yi <jyi.dev@outlook.com>
|
* @author Johnson Yi <jyi.dev@outlook.com>
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
*
|
*
|
||||||
* @return Redirect
|
* @return Redirect
|
||||||
*/
|
*/
|
||||||
public function login(Request $request)
|
public function login(Request $request)
|
||||||
{
|
{
|
||||||
$auth = $this->saml->getAuth();
|
$auth = $this->saml->getAuth();
|
||||||
$ssoUrl = $auth->login(null, array(), false, false, false, false);
|
$ssoUrl = $auth->login(null, [], false, false, false, false);
|
||||||
|
|
||||||
return redirect()->away($ssoUrl);
|
return redirect()->away($ssoUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives, parses the assertion from IdP and flashes SAML data
|
* Receives, parses the assertion from IdP and flashes SAML data
|
||||||
* back to the LoginController for authentication.
|
* back to the LoginController for authentication.
|
||||||
*
|
*
|
||||||
* /saml/acs
|
* /saml/acs
|
||||||
*
|
*
|
||||||
* @author Johnson Yi <jyi.dev@outlook.com>
|
* @author Johnson Yi <jyi.dev@outlook.com>
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
*
|
*
|
||||||
* @return Redirect
|
* @return Redirect
|
||||||
*/
|
*/
|
||||||
public function acs(Request $request)
|
public function acs(Request $request)
|
||||||
|
@ -100,9 +101,10 @@ class SamlController extends Controller
|
||||||
$auth->processResponse();
|
$auth->processResponse();
|
||||||
$errors = $auth->getErrors();
|
$errors = $auth->getErrors();
|
||||||
|
|
||||||
if (!empty($errors)) {
|
if (! empty($errors)) {
|
||||||
Log::error("There was an error with SAML ACS: " . implode(', ', $errors));
|
Log::error('There was an error with SAML ACS: '.implode(', ', $errors));
|
||||||
Log::error("Reason: " . $auth->getLastErrorReason());
|
Log::error('Reason: '.$auth->getLastErrorReason());
|
||||||
|
|
||||||
return redirect()->route('login')->with('error', trans('auth/message.signin.error'));
|
return redirect()->route('login')->with('error', trans('auth/message.signin.error'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,15 +116,15 @@ class SamlController extends Controller
|
||||||
/**
|
/**
|
||||||
* Receives LogoutRequest/LogoutResponse from IdP and flashes
|
* Receives LogoutRequest/LogoutResponse from IdP and flashes
|
||||||
* back to the LoginController for logging out.
|
* back to the LoginController for logging out.
|
||||||
*
|
*
|
||||||
* /saml/sls
|
* /saml/sls
|
||||||
*
|
*
|
||||||
* @author Johnson Yi <jyi.dev@outlook.com>
|
* @author Johnson Yi <jyi.dev@outlook.com>
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
*
|
*
|
||||||
* @param Request $request
|
* @param Request $request
|
||||||
*
|
*
|
||||||
* @return Redirect
|
* @return Redirect
|
||||||
*/
|
*/
|
||||||
public function sls(Request $request)
|
public function sls(Request $request)
|
||||||
|
@ -131,10 +133,11 @@ class SamlController extends Controller
|
||||||
$retrieveParametersFromServer = $this->saml->getSetting('retrieveParametersFromServer', false);
|
$retrieveParametersFromServer = $this->saml->getSetting('retrieveParametersFromServer', false);
|
||||||
$sloUrl = $auth->processSLO(true, null, $retrieveParametersFromServer, null, true);
|
$sloUrl = $auth->processSLO(true, null, $retrieveParametersFromServer, null, true);
|
||||||
$errors = $auth->getErrors();
|
$errors = $auth->getErrors();
|
||||||
|
|
||||||
if (!empty($errors)) {
|
if (! empty($errors)) {
|
||||||
Log::error("There was an error with SAML SLS: " . implode(', ', $errors));
|
Log::error('There was an error with SAML SLS: '.implode(', ', $errors));
|
||||||
Log::error("Reason: " . $auth->getLastErrorReason());
|
Log::error('Reason: '.$auth->getLastErrorReason());
|
||||||
|
|
||||||
return view('errors.403');
|
return view('errors.403');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use Illuminate\Support\Facades\Redirect;
|
||||||
|
|
||||||
class BulkAssetModelsController extends Controller
|
class BulkAssetModelsController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Returns a view that allows the user to bulk edit model attrbutes
|
* Returns a view that allows the user to bulk edit model attrbutes
|
||||||
*
|
*
|
||||||
* @author [A. Gianotto] [<snipe@snipe.net>]
|
* @author [A. Gianotto] [<snipe@snipe.net>]
|
||||||
|
@ -24,26 +24,27 @@ class BulkAssetModelsController extends Controller
|
||||||
|
|
||||||
// Make sure some IDs have been selected
|
// Make sure some IDs have been selected
|
||||||
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
|
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
|
||||||
|
|
||||||
$models = AssetModel::whereIn('id', $models_raw_array)
|
$models = AssetModel::whereIn('id', $models_raw_array)
|
||||||
->withCount('assets as assets_count')
|
->withCount('assets as assets_count')
|
||||||
->orderBy('assets_count', 'ASC')
|
->orderBy('assets_count', 'ASC')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
// If deleting....
|
// If deleting....
|
||||||
if ($request->input('bulk_actions')=='delete') {
|
if ($request->input('bulk_actions') == 'delete') {
|
||||||
$valid_count = 0;
|
$valid_count = 0;
|
||||||
foreach ($models as $model) {
|
foreach ($models as $model) {
|
||||||
if ($model->assets_count == 0) {
|
if ($model->assets_count == 0) {
|
||||||
$valid_count++;
|
$valid_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('models/bulk-delete', compact('models'))->with('valid_count', $valid_count);
|
return view('models/bulk-delete', compact('models'))->with('valid_count', $valid_count);
|
||||||
|
|
||||||
// Otherwise display the bulk edit screen
|
// Otherwise display the bulk edit screen
|
||||||
}
|
}
|
||||||
|
|
||||||
$nochange = ['NC' => 'No Change'];
|
$nochange = ['NC' => 'No Change'];
|
||||||
|
|
||||||
return view('models/bulk-edit', compact('models'))
|
return view('models/bulk-edit', compact('models'))
|
||||||
->with('fieldset_list', $nochange + Helper::customFieldsetList())
|
->with('fieldset_list', $nochange + Helper::customFieldsetList())
|
||||||
->with('depreciation_list', $nochange + Helper::depreciationList());
|
->with('depreciation_list', $nochange + Helper::depreciationList());
|
||||||
|
@ -63,34 +64,36 @@ class BulkAssetModelsController extends Controller
|
||||||
*/
|
*/
|
||||||
public function update(Request $request)
|
public function update(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$models_raw_array = $request->input('ids');
|
$models_raw_array = $request->input('ids');
|
||||||
$update_array = array();
|
$update_array = [];
|
||||||
|
|
||||||
if (($request->filled('manufacturer_id') && ($request->input('manufacturer_id')!='NC'))) {
|
if (($request->filled('manufacturer_id') && ($request->input('manufacturer_id') != 'NC'))) {
|
||||||
$update_array['manufacturer_id'] = $request->input('manufacturer_id');
|
$update_array['manufacturer_id'] = $request->input('manufacturer_id');
|
||||||
}
|
}
|
||||||
if (($request->filled('category_id') && ($request->input('category_id')!='NC'))) {
|
if (($request->filled('category_id') && ($request->input('category_id') != 'NC'))) {
|
||||||
$update_array['category_id'] = $request->input('category_id');
|
$update_array['category_id'] = $request->input('category_id');
|
||||||
}
|
}
|
||||||
if ($request->input('fieldset_id')!='NC') {
|
if ($request->input('fieldset_id') != 'NC') {
|
||||||
$update_array['fieldset_id'] = $request->input('fieldset_id');
|
$update_array['fieldset_id'] = $request->input('fieldset_id');
|
||||||
}
|
}
|
||||||
if ($request->input('depreciation_id')!='NC') {
|
if ($request->input('depreciation_id') != 'NC') {
|
||||||
$update_array['depreciation_id'] = $request->input('depreciation_id');
|
$update_array['depreciation_id'] = $request->input('depreciation_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->filled('requestable') != '') {
|
||||||
|
$update_array['requestable'] = $request->input('requestable');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (count($update_array) > 0) {
|
if (count($update_array) > 0) {
|
||||||
AssetModel::whereIn('id', $models_raw_array)->update($update_array);
|
AssetModel::whereIn('id', $models_raw_array)->update($update_array);
|
||||||
|
|
||||||
return redirect()->route('models.index')
|
return redirect()->route('models.index')
|
||||||
->with('success', trans('admin/models/message.bulkedit.success'));
|
->with('success', trans('admin/models/message.bulkedit.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('models.index')
|
return redirect()->route('models.index')
|
||||||
->with('warning', trans('admin/models/message.bulkedit.error'));
|
->with('warning', trans('admin/models/message.bulkedit.error'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -106,7 +109,6 @@ class BulkAssetModelsController extends Controller
|
||||||
$models_raw_array = $request->input('ids');
|
$models_raw_array = $request->input('ids');
|
||||||
|
|
||||||
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
|
if ((is_array($models_raw_array)) && (count($models_raw_array) > 0)) {
|
||||||
|
|
||||||
$models = AssetModel::whereIn('id', $models_raw_array)->withCount('assets as assets_count')->get();
|
$models = AssetModel::whereIn('id', $models_raw_array)->withCount('assets as assets_count')->get();
|
||||||
|
|
||||||
$del_error_count = 0;
|
$del_error_count = 0;
|
||||||
|
@ -123,7 +125,7 @@ class BulkAssetModelsController extends Controller
|
||||||
|
|
||||||
if ($del_error_count == 0) {
|
if ($del_error_count == 0) {
|
||||||
return redirect()->route('models.index')
|
return redirect()->route('models.index')
|
||||||
->with('success', trans('admin/models/message.bulkdelete.success',['success_count'=> $del_count] ));
|
->with('success', trans('admin/models/message.bulkdelete.success', ['success_count'=> $del_count]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('models.index')
|
return redirect()->route('models.index')
|
||||||
|
@ -132,7 +134,5 @@ class BulkAssetModelsController extends Controller
|
||||||
|
|
||||||
return redirect()->route('models.index')
|
return redirect()->route('models.index')
|
||||||
->with('error', trans('admin/models/message.bulkdelete.error'));
|
->with('error', trans('admin/models/message.bulkdelete.error'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Helpers\Helper;
|
use App\Helpers\Helper;
|
||||||
|
@ -17,7 +18,6 @@ use Str;
|
||||||
*/
|
*/
|
||||||
class CategoriesController extends Controller
|
class CategoriesController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view that invokes the ajax tables which actually contains
|
* Returns a view that invokes the ajax tables which actually contains
|
||||||
* the content for the categories listing, which is generated in getDatatable.
|
* the content for the categories listing, which is generated in getDatatable.
|
||||||
|
@ -32,10 +32,10 @@ class CategoriesController extends Controller
|
||||||
{
|
{
|
||||||
// Show the page
|
// Show the page
|
||||||
$this->authorize('view', Category::class);
|
$this->authorize('view', Category::class);
|
||||||
|
|
||||||
return view('categories/index');
|
return view('categories/index');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a form view to create a new category.
|
* Returns a form view to create a new category.
|
||||||
*
|
*
|
||||||
|
@ -49,11 +49,11 @@ class CategoriesController extends Controller
|
||||||
{
|
{
|
||||||
// Show the page
|
// Show the page
|
||||||
$this->authorize('create', Category::class);
|
$this->authorize('create', Category::class);
|
||||||
|
|
||||||
return view('categories/edit')->with('item', new Category)
|
return view('categories/edit')->with('item', new Category)
|
||||||
->with('category_types', Helper::categoryTypeList());
|
->with('category_types', Helper::categoryTypeList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates and stores the new category data.
|
* Validates and stores the new category data.
|
||||||
*
|
*
|
||||||
|
@ -68,13 +68,13 @@ class CategoriesController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('create', Category::class);
|
$this->authorize('create', Category::class);
|
||||||
$category = new Category();
|
$category = new Category();
|
||||||
$category->name = $request->input('name');
|
$category->name = $request->input('name');
|
||||||
$category->category_type = $request->input('category_type');
|
$category->category_type = $request->input('category_type');
|
||||||
$category->eula_text = $request->input('eula_text');
|
$category->eula_text = $request->input('eula_text');
|
||||||
$category->use_default_eula = $request->input('use_default_eula', '0');
|
$category->use_default_eula = $request->input('use_default_eula', '0');
|
||||||
$category->require_acceptance = $request->input('require_acceptance', '0');
|
$category->require_acceptance = $request->input('require_acceptance', '0');
|
||||||
$category->checkin_email = $request->input('checkin_email', '0');
|
$category->checkin_email = $request->input('checkin_email', '0');
|
||||||
$category->user_id = Auth::id();
|
$category->user_id = Auth::id();
|
||||||
|
|
||||||
$category = $request->handleImages($category);
|
$category = $request->handleImages($category);
|
||||||
if ($category->save()) {
|
if ($category->save()) {
|
||||||
|
@ -100,11 +100,11 @@ class CategoriesController extends Controller
|
||||||
if (is_null($item = Category::find($categoryId))) {
|
if (is_null($item = Category::find($categoryId))) {
|
||||||
return redirect()->route('categories.index')->with('error', trans('admin/categories/message.does_not_exist'));
|
return redirect()->route('categories.index')->with('error', trans('admin/categories/message.does_not_exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('categories/edit', compact('item'))
|
return view('categories/edit', compact('item'))
|
||||||
->with('category_types', Helper::categoryTypeList());
|
->with('category_types', Helper::categoryTypeList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates and stores the updated category data.
|
* Validates and stores the updated category data.
|
||||||
*
|
*
|
||||||
|
@ -125,15 +125,14 @@ class CategoriesController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the category data
|
// Update the category data
|
||||||
$category->name = $request->input('name');
|
$category->name = $request->input('name');
|
||||||
// If the item count is > 0, we disable the category type in the edit. Disabled items
|
// If the item count is > 0, we disable the category type in the edit. Disabled items
|
||||||
// don't POST, so if the category_type is blank we just set it to the default.
|
// don't POST, so if the category_type is blank we just set it to the default.
|
||||||
$category->category_type = $request->input('category_type', $category->category_type);
|
$category->category_type = $request->input('category_type', $category->category_type);
|
||||||
$category->eula_text = $request->input('eula_text');
|
$category->eula_text = $request->input('eula_text');
|
||||||
$category->use_default_eula = $request->input('use_default_eula', '0');
|
$category->use_default_eula = $request->input('use_default_eula', '0');
|
||||||
$category->require_acceptance = $request->input('require_acceptance', '0');
|
$category->require_acceptance = $request->input('require_acceptance', '0');
|
||||||
$category->checkin_email = $request->input('checkin_email', '0');
|
$category->checkin_email = $request->input('checkin_email', '0');
|
||||||
|
|
||||||
|
|
||||||
$category = $request->handleImages($category);
|
$category = $request->handleImages($category);
|
||||||
|
|
||||||
|
@ -162,8 +161,8 @@ class CategoriesController extends Controller
|
||||||
return redirect()->route('categories.index')->with('error', trans('admin/categories/message.not_found'));
|
return redirect()->route('categories.index')->with('error', trans('admin/categories/message.not_found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$category->isDeletable()) {
|
if (! $category->isDeletable()) {
|
||||||
return redirect()->route('categories.index')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=> $category->category_type ]));
|
return redirect()->route('categories.index')->with('error', trans('admin/categories/message.assoc_items', ['asset_type'=> $category->category_type]));
|
||||||
}
|
}
|
||||||
|
|
||||||
Storage::disk('public')->delete('categories'.'/'.$category->image);
|
Storage::disk('public')->delete('categories'.'/'.$category->image);
|
||||||
|
@ -172,7 +171,6 @@ class CategoriesController extends Controller
|
||||||
return redirect()->route('categories.index')->with('success', trans('admin/categories/message.delete.success'));
|
return redirect()->route('categories.index')->with('success', trans('admin/categories/message.delete.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view that invokes the ajax tables which actually contains
|
* Returns a view that invokes the ajax tables which actually contains
|
||||||
* the content for the categories detail view, which is generated in getDataView.
|
* the content for the categories detail view, which is generated in getDataView.
|
||||||
|
@ -188,20 +186,20 @@ class CategoriesController extends Controller
|
||||||
{
|
{
|
||||||
$this->authorize('view', Category::class);
|
$this->authorize('view', Category::class);
|
||||||
if ($category = Category::find($id)) {
|
if ($category = Category::find($id)) {
|
||||||
|
if ($category->category_type == 'asset') {
|
||||||
if ($category->category_type=='asset') {
|
|
||||||
$category_type = 'hardware';
|
$category_type = 'hardware';
|
||||||
$category_type_route = 'assets';
|
$category_type_route = 'assets';
|
||||||
} elseif ($category->category_type=='accessory') {
|
} elseif ($category->category_type == 'accessory') {
|
||||||
$category_type = 'accessories';
|
$category_type = 'accessories';
|
||||||
$category_type_route = 'accessories';
|
$category_type_route = 'accessories';
|
||||||
} else {
|
} else {
|
||||||
$category_type = $category->category_type;
|
$category_type = $category->category_type;
|
||||||
$category_type_route = $category->category_type.'s';
|
$category_type_route = $category->category_type.'s';
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('categories/view', compact('category'))
|
return view('categories/view', compact('category'))
|
||||||
->with('category_type',$category_type)
|
->with('category_type', $category_type)
|
||||||
->with('category_type_route',$category_type_route);
|
->with('category_type_route', $category_type_route);
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('categories.index')->with('error', trans('admin/categories/message.does_not_exist'));
|
return redirect()->route('categories.index')->with('error', trans('admin/categories/message.does_not_exist'));
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Asset;
|
use App\Models\Asset;
|
||||||
|
@ -14,9 +15,8 @@ trait CheckInOutRequest
|
||||||
*/
|
*/
|
||||||
protected function determineCheckoutTarget()
|
protected function determineCheckoutTarget()
|
||||||
{
|
{
|
||||||
// This item is checked out to a location
|
// This item is checked out to a location
|
||||||
switch(request('checkout_to_type'))
|
switch (request('checkout_to_type')) {
|
||||||
{
|
|
||||||
case 'location':
|
case 'location':
|
||||||
return Location::findOrFail(request('assigned_location'));
|
return Location::findOrFail(request('assigned_location'));
|
||||||
case 'asset':
|
case 'asset':
|
||||||
|
@ -24,6 +24,7 @@ trait CheckInOutRequest
|
||||||
case 'user':
|
case 'user':
|
||||||
return User::findOrFail(request('assigned_user'));
|
return User::findOrFail(request('assigned_user'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,15 +36,14 @@ trait CheckInOutRequest
|
||||||
*/
|
*/
|
||||||
protected function updateAssetLocation($asset, $target)
|
protected function updateAssetLocation($asset, $target)
|
||||||
{
|
{
|
||||||
switch(request('checkout_to_type'))
|
switch (request('checkout_to_type')) {
|
||||||
{
|
|
||||||
case 'location':
|
case 'location':
|
||||||
$asset->location_id = $target->id;
|
$asset->location_id = $target->id;
|
||||||
break;
|
break;
|
||||||
case 'asset':
|
case 'asset':
|
||||||
$asset->location_id = $target->rtd_location_id;
|
$asset->location_id = $target->rtd_location_id;
|
||||||
// Override with the asset's location_id if it has one
|
// Override with the asset's location_id if it has one
|
||||||
if ($target->location_id!='') {
|
if ($target->location_id != '') {
|
||||||
$asset->location_id = $target->location_id;
|
$asset->location_id = $target->location_id;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -51,6 +51,7 @@ trait CheckInOutRequest
|
||||||
$asset->location_id = $target->location_id;
|
$asset->location_id = $target->location_id;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $asset;
|
return $asset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Requests\ImageUploadRequest;
|
use App\Http\Requests\ImageUploadRequest;
|
||||||
|
@ -12,10 +13,8 @@ use Illuminate\Support\Facades\Storage;
|
||||||
*
|
*
|
||||||
* @version v1.0
|
* @version v1.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
final class CompaniesController extends Controller
|
final class CompaniesController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns view to display listing of companies.
|
* Returns view to display listing of companies.
|
||||||
*
|
*
|
||||||
|
@ -68,10 +67,10 @@ final class CompaniesController extends Controller
|
||||||
return redirect()->route('companies.index')
|
return redirect()->route('companies.index')
|
||||||
->with('success', trans('admin/companies/message.create.success'));
|
->with('success', trans('admin/companies/message.create.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->back()->withInput()->withErrors($company->getErrors());
|
return redirect()->back()->withInput()->withErrors($company->getErrors());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return form to edit existing company.
|
* Return form to edit existing company.
|
||||||
*
|
*
|
||||||
|
@ -113,14 +112,13 @@ final class CompaniesController extends Controller
|
||||||
|
|
||||||
$company->name = $request->input('name');
|
$company->name = $request->input('name');
|
||||||
|
|
||||||
|
|
||||||
$company = $request->handleImages($company);
|
$company = $request->handleImages($company);
|
||||||
|
|
||||||
|
|
||||||
if ($company->save()) {
|
if ($company->save()) {
|
||||||
return redirect()->route('companies.index')
|
return redirect()->route('companies.index')
|
||||||
->with('success', trans('admin/companies/message.update.success'));
|
->with('success', trans('admin/companies/message.update.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('companies.edit', ['company' => $companyId])
|
return redirect()->route('companies.edit', ['company' => $companyId])
|
||||||
->with('error', trans('admin/companies/message.update.error'));
|
->with('error', trans('admin/companies/message.update.error'));
|
||||||
}
|
}
|
||||||
|
@ -142,13 +140,13 @@ final class CompaniesController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->authorize('delete', $company);
|
$this->authorize('delete', $company);
|
||||||
if(!$company->isDeletable()) {
|
if (! $company->isDeletable()) {
|
||||||
return redirect()->route('companies.index')
|
return redirect()->route('companies.index')
|
||||||
->with('error', trans('admin/companies/message.assoc_users'));
|
->with('error', trans('admin/companies/message.assoc_users'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($company->image) {
|
if ($company->image) {
|
||||||
try {
|
try {
|
||||||
Storage::disk('public')->delete('companies'.'/'.$company->image);
|
Storage::disk('public')->delete('companies'.'/'.$company->image);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
\Log::debug($e);
|
\Log::debug($e);
|
||||||
|
@ -156,11 +154,13 @@ final class CompaniesController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$company->delete();
|
$company->delete();
|
||||||
|
|
||||||
return redirect()->route('companies.index')
|
return redirect()->route('companies.index')
|
||||||
->with('success', trans('admin/companies/message.delete.success'));
|
->with('success', trans('admin/companies/message.delete.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function show($id) {
|
public function show($id)
|
||||||
|
{
|
||||||
$this->authorize('view', Company::class);
|
$this->authorize('view', Company::class);
|
||||||
|
|
||||||
if (is_null($company = Company::find($id))) {
|
if (is_null($company = Company::find($id))) {
|
||||||
|
@ -168,6 +168,6 @@ final class CompaniesController extends Controller
|
||||||
->with('error', trans('admin/companies/message.not_found'));
|
->with('error', trans('admin/companies/message.not_found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return view('companies/view')->with('company',$company);
|
return view('companies/view')->with('company', $company);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ use Illuminate\Support\Facades\Validator;
|
||||||
|
|
||||||
class ComponentCheckinController extends Controller
|
class ComponentCheckinController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a view that allows the checkin of a component from an asset.
|
* Returns a view that allows the checkin of a component from an asset.
|
||||||
*
|
*
|
||||||
|
@ -39,14 +38,13 @@ class ComponentCheckinController extends Controller
|
||||||
trans('admin/components/message.not_found'));
|
trans('admin/components/message.not_found'));
|
||||||
}
|
}
|
||||||
$this->authorize('checkin', $component);
|
$this->authorize('checkin', $component);
|
||||||
return view('components/checkin', compact('component_assets','component','asset'));
|
|
||||||
|
return view('components/checkin', compact('component_assets', 'component', 'asset'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('components.index')->with('error', trans('admin/components/messages.not_found'));
|
return redirect()->route('components.index')->with('error', trans('admin/components/messages.not_found'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate and store checkin data.
|
* Validate and store checkin data.
|
||||||
*
|
*
|
||||||
|
@ -66,12 +64,11 @@ class ComponentCheckinController extends Controller
|
||||||
trans('admin/components/message.not_found'));
|
trans('admin/components/message.not_found'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->authorize('checkin', $component);
|
$this->authorize('checkin', $component);
|
||||||
|
|
||||||
$max_to_checkin = $component_assets->assigned_qty;
|
$max_to_checkin = $component_assets->assigned_qty;
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
"checkin_qty" => "required|numeric|between:1,$max_to_checkin"
|
'checkin_qty' => "required|numeric|between:1,$max_to_checkin",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
|
@ -81,7 +78,7 @@ class ComponentCheckinController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validation passed, so let's figure out what we have to do here.
|
// Validation passed, so let's figure out what we have to do here.
|
||||||
$qty_remaining_in_checkout = ($component_assets->assigned_qty - (int)$request->input('checkin_qty'));
|
$qty_remaining_in_checkout = ($component_assets->assigned_qty - (int) $request->input('checkin_qty'));
|
||||||
|
|
||||||
// We have to modify the record to reflect the new qty that's
|
// We have to modify the record to reflect the new qty that's
|
||||||
// actually checked out.
|
// actually checked out.
|
||||||
|
@ -102,7 +99,7 @@ class ComponentCheckinController extends Controller
|
||||||
return redirect()->route('components.index')->with('success',
|
return redirect()->route('components.index')->with('success',
|
||||||
trans('admin/components/message.checkin.success'));
|
trans('admin/components/message.checkin.success'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist'));
|
return redirect()->route('components.index')->with('error', trans('admin/components/message.does_not_exist'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ class ComponentCheckoutController extends Controller
|
||||||
return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found'));
|
return redirect()->route('components.index')->with('error', trans('admin/components/message.not_found'));
|
||||||
}
|
}
|
||||||
$this->authorize('checkout', $component);
|
$this->authorize('checkout', $component);
|
||||||
|
|
||||||
return view('components/checkout', compact('component'));
|
return view('components/checkout', compact('component'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,8 +59,8 @@ class ComponentCheckoutController extends Controller
|
||||||
|
|
||||||
$max_to_checkout = $component->numRemaining();
|
$max_to_checkout = $component->numRemaining();
|
||||||
$validator = Validator::make($request->all(), [
|
$validator = Validator::make($request->all(), [
|
||||||
"asset_id" => "required",
|
'asset_id' => 'required',
|
||||||
"assigned_qty" => "required|numeric|between:1,$max_to_checkout"
|
'assigned_qty' => "required|numeric|between:1,$max_to_checkout",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
|
@ -78,14 +79,14 @@ class ComponentCheckoutController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the component data
|
// Update the component data
|
||||||
$component->asset_id = $asset_id;
|
$component->asset_id = $asset_id;
|
||||||
|
|
||||||
$component->assets()->attach($component->id, [
|
$component->assets()->attach($component->id, [
|
||||||
'component_id' => $component->id,
|
'component_id' => $component->id,
|
||||||
'user_id' => $admin_user->id,
|
'user_id' => $admin_user->id,
|
||||||
'created_at' => date('Y-m-d H:i:s'),
|
'created_at' => date('Y-m-d H:i:s'),
|
||||||
'assigned_qty' => $request->input('assigned_qty'),
|
'assigned_qty' => $request->input('assigned_qty'),
|
||||||
'asset_id' => $asset_id
|
'asset_id' => $asset_id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
event(new CheckoutableCheckedOut($component, $asset, Auth::user(), $request->input('note')));
|
event(new CheckoutableCheckedOut($component, $asset, Auth::user(), $request->input('note')));
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue