Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] hr_recruitment_job_share: Share a job that wasnt published in website #62

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions hr_recruitment_job_share/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
========================
Hr Recruitment Job Share
========================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:f65466fa3db1bf38827a26dc5413e069b9dfd9a720389cabcabe608918cae583
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-KMEE%2Fkmee--odoo--addons-lightgray.png?logo=github
:target: https://github.com/KMEE/kmee-odoo-addons/tree/16.0/hr_recruitment_job_share
:alt: KMEE/kmee-odoo-addons

|badge1| |badge2| |badge3|

It allows the user to share details of a job that has not been published
on the site yet

**Table of contents**

.. contents::
:local:

Usage
=====

Access the work record, click "Share" and copy the link

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/KMEE/kmee-odoo-addons/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/KMEE/kmee-odoo-addons/issues/new?body=module:%20hr_recruitment_job_share%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* KMEE

Contributors
------------

- ``KMEE <https://www.kmee.com.br>``\ \_:

- Bruno Corredato Botti

Maintainers
-----------

This module is part of the `KMEE/kmee-odoo-addons <https://github.com/KMEE/kmee-odoo-addons/tree/16.0/hr_recruitment_job_share>`_ project on GitHub.

You are welcome to contribute.
3 changes: 3 additions & 0 deletions hr_recruitment_job_share/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import controllers
from . import models
from . import wizards
21 changes: 21 additions & 0 deletions hr_recruitment_job_share/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Hr Recruitment Job Share",
"summary": """
Share job in odoo portal""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "KMEE,Odoo Community Association (OCA)",
"website": "https://github.com/KMEE/kmee-odoo-addons",
"depends": [
"website_hr_recruitment",
],
"data": [
"security/ir.model.access.csv",
"views/hr_job.xml",
"views/website_hr_recruitment_templates.xml",
"wizards/job_share.xml",
],
}
1 change: 1 addition & 0 deletions hr_recruitment_job_share/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import controllers
40 changes: 40 additions & 0 deletions hr_recruitment_job_share/controllers/controllers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from werkzeug.exceptions import NotFound

from odoo import http
from odoo.http import request


class JobShareController(http.Controller):
@http.route(
["/jobs/details/<int:hr_job_id>"], type="http", auth="public", website=True
)
def job_followup(self, hr_job_id=None, access_token=None, **kw):
hr_job_sudo = (
request.env["hr.job"].sudo().search([("id", "=", hr_job_id)], limit=1)
)

if not hr_job_sudo or hr_job_sudo.access_token != access_token:
raise NotFound()

values = {
"page_name": "hr_job",
"job": hr_job_sudo,
"access_token": access_token,
}
return request.render("website_hr_recruitment.detail", values)

@http.route(
["/jobs/apply/<int:hr_job_id>"], type="http", auth="public", website=True
)
def job_apply(self, hr_job_id=None, access_token=None, **kw):
hr_job_sudo = (
request.env["hr.job"].sudo().search([("id", "=", hr_job_id)], limit=1)
)

if not hr_job_sudo or (
hr_job_sudo.access_token != access_token and not hr_job_sudo.is_published
):
raise NotFound()

values = {"job": hr_job_sudo}
return request.render("website_hr_recruitment.apply", values)
1 change: 1 addition & 0 deletions hr_recruitment_job_share/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import hr_job
48 changes: 48 additions & 0 deletions hr_recruitment_job_share/models/hr_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import secrets

from odoo import api, fields, models


class Job(models.Model):
_inherit = "hr.job"

access_token = fields.Char(
"Token de Acesso", copy=False, default=lambda self: secrets.token_urlsafe(16)
)
is_shared = fields.Boolean("É compartilhado?", default=False)
application_url = fields.Char("URL da Vaga", compute="_compute_application_url")

def get_share_url(self):
base_url = self.env["ir.config_parameter"].sudo().get_param("web.base.url")
return f"{base_url}/jobs/details/{self.id}?access_token={self.access_token}"

@api.depends("access_token")
def _compute_application_url(self):
for job in self:
job.application_url = job.get_share_url() if job.access_token else ""

def action_share_job(self):
self.ensure_one()
# Gerar um novo token ao compartilhar o trabalho
self.access_token = secrets.token_urlsafe(16) # Garante que cada token é único
self.is_shared = True
return {
"type": "ir.actions.act_window",
"res_model": "job.share.wizard",
"view_mode": "form",
"target": "new",
"context": {"default_job_id": self.id},
}

@api.model
def create(self, vals):
# Garante que o token de acesso é gerado no momento da criação
if "access_token" not in vals:
vals["access_token"] = secrets.token_urlsafe(16)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Se duplicar o registro o que acontece?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ele cria um novo token sempre que o usuário clica em compartilhar, e os anteriores continuam funcional

return super(Job, self).create(vals)

def write(self, vals):
# Se o trabalho não estiver sendo compartilhado, não altere o token
if "is_shared" in vals and vals["is_shared"]:
self.access_token = secrets.token_urlsafe(16)
return super(Job, self).write(vals)
3 changes: 3 additions & 0 deletions hr_recruitment_job_share/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `KMEE <https://www.kmee.com.br>`_:

* Bruno Corredato Botti
1 change: 1 addition & 0 deletions hr_recruitment_job_share/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
It allows the user to share details of a job that has not been published on the site yet
1 change: 1 addition & 0 deletions hr_recruitment_job_share/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Access the work record, click "Share" and copy the link
3 changes: 3 additions & 0 deletions hr_recruitment_job_share/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_job_share_wizard,job.share.wizard,model_job_share_wizard,hr_recruitment.group_hr_recruitment_user,1,1,1,1
access_hr_job_public,access_hr_job_public,model_hr_job,base.group_public,1,0,0,0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading