Skip to content

Commit

Permalink
Merge pull request #252 from MasoniteFramework/master
Browse files Browse the repository at this point in the history
Next Minor - 2.0.20
  • Loading branch information
josephmancuso committed Sep 10, 2018
2 parents 3fa78a8 + f0e24e7 commit a093b7f
Show file tree
Hide file tree
Showing 27 changed files with 347 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ omit =
*/tests/*
masonite/commands/*
masonite/contracts/*
masonite/snippets/*
masonite/snippets/*
.travis.yml
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ python:
- '3.5'
- '3.6'

matrix:
include:
- python: 3.7
dist: xenial
sudo: true

install:
- pip install masonite_cli
- pip install -e .
Expand Down
191 changes: 191 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# Contributing Guide

## Introduction

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners or contributors of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

## Getting Started

The framework has three main parts.

This `MasoniteFramework/masonite` repository is the main repository that will install when creating new projects using the `craft new` command. Not much development will be done in this repository and won't be changed unless new releases of Masonite require changes in the default installation project.

The `MasoniteFramework/core` repository where the main `masonite` pip package lives. This is where the `from masonite ...` module lives.

The `MasoniteFramework/craft` repository where the `craft` command lives

### Getting the Masonite repository up and running to be edited

[You can read about how the framework flows, works and architectural concepts here](https://masoniteframework.gitbooks.io/docs/content/request-lifecycle.html)

This repo is simple and will be able to be installed following the installation instruction in the README.

* Fork the `MasoniteFramework/masonite` repo.
* Clone that repo into your computer:
* `git clone http://github.com/your-username/masonite.git`
* Checkout the current release branch \(example: `develop`\)
* You should now be on a `develop` local branch.
* Run `git pull origin develop` to get the current release version.
* From there simply create your feature branches \(`change-default-orm`\) and make your desired changes.
* Push to your origin repository:
* `git push origin change-default-orm`
* Open a pull request and follow the PR process below

### Editing the Masonite core repository

The trick to this is that we need it to be pip installed and then quickly editable until we like it, and then pushed back to the repo for a PR. Do this only if you want to make changes to the core Masonite package

To do this just:

* Fork the `MasoniteFramework/core` repo,
* Clone that repo into your computer:
* `git clone http://github.com/your-username/core.git`
* Activate your masonite virtual environment \(optional\)
* Go to where you installed masonite and activate the environment
* While inside the virtual environment, cd into the directory you installed core.
* Run `pip install .` from inside the masonite-core directory. This will install masonite as a pip package.
* Any changes you make to this package just push it to your feature branch on your fork and follow the PR process below.

{% hint style="warning" %}
This repository has a barebones skeleton of a sample project in order to aid in testing all the features of Masonite against a real project. If you install this as editable by passing the `--editable` flag then this may break your project because it will override the modules in this package with your application modules.
{% endhint %}

### Editing the craft repository \(`craft` commands\)

Craft commands make up a large part of the workflow for Masonite. Follow these instructions to get the masonite-cli package on your computer and editable.

* Fork the `MasoniteFramework/craft` repo,
* Clone that repo into your computer:
* `git clone http://github.com/your-username/craft.git`
* Activate your masonite virtual environment \(optional\)
* Go to where you installed masonite and activate the environment
* While inside the virtual environment, cd into the directory you installed cli
* Run `pip install --editable .` from inside the masonite-cli directory. This will install craft \(which contains the craft commands\) as a pip package but also keep a reference to the folder so you can make changes freely to craft commands while not having to worry about continuously reinstalling it.
* Any changes you make to this package just push it to your feature branch on your fork and follow the PR process below.

### Comments

Comments are a vital part of any repository and should be used where needed. It is important not to overcomment something. If you find you need to constantly add comments, you're code may be too complex. Code should be self documenting \(with clearly defined variable and method names\)

#### Types of comments to use

There are 3 main type of comments you should use when developing for Masonite:

**Module Docstrings**

All modules should have a docstring at the top of every module file and should look something like:

```python
""" This is a module to add support for Billing users """
from masonite.request import Request
...
```

**Method and Function Docstrings**

All methods and functions should also contain a docstring with a brief description of what the module does

For example:

```python
def some_function(self):
"""
This is a function that does x action.
Then give an exmaple of when to use it
"""
... code ...
```

**Code Comments**

If you're code MUST be complex enough that future developers will not understand it, add a `#` comment above it

For normal code this will look something like:

```python
# This code performs a complex task that may not be understood later on
# You can add a second line like this
complex_code = 'value'

perform_some_complex_task()
```

**Flagpole Comments**

Flag pole comments are a fantastic way to give developers an inside to what is really happening and for now should only be reserved for configuration files. A flag pole comment gets its name from how the comment looks

```text
'''
|--------------------------------------------------------------------------
| A Heading of The Setting Being Set
|--------------------------------------------------------------------------
|
| A quick description
|
'''
SETTING = 'some value'
```

It's important to note that there should have exactly 75 `-` above and below the header and have a trailing `|` at the bottom of the comment.

### Pull Request Process

1. You should open an issue before making any pull requests. Not all features will be added to the framework and some may be better off as a third party package. It wouldn't be good if you worked on a feature for several days and the pull request gets rejected for reasons that could have been discussed in an issue for several minutes.
2. Ensure any changes are well commented and any configuration files that are added have a flagpole comment on the variables it's setting.
3. Update the README.md and `MasoniteFramework/docs` repo with details of changes to the interface, this includes new environment variables, new file locations, container parameters etc.
4. You must add unit testing for any changes made. Of the three repositories listed above, only the `craft` and `core` repos require unit testing.
5. Increase the version numbers in any example files and the README.md to the new version that this Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/) for both `core` and `craft` or [RomVer](http://blog.legacyteam.info/2015/12/romver-romantic-versioning/) for the main Masonite repo.
6. The PR must pass the Travis CI build. The Pull Request can be merged in once you have a successful review from two other collaborators, or the feature maintainer for your specific feature improvement or the repo owner.

## Code of Conduct

### Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

### Our Standards

Examples of behavior that contributes to creating a positive environment include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic

address, without explicit permission

* Other conduct which could reasonably be considered inappropriate in a

professional setting

### Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

### Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

### Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at idmann509@gmail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

### Attribution

This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.4, available at [http://contributor-covenant.org/version/1/4](http://contributor-covenant.org/version/1/4/)

4 changes: 2 additions & 2 deletions masonite/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ def _find_annotated_parameter(self, parameter):
"""

for dummy, provider_class in self.providers.items():

if parameter.annotation == provider_class or parameter.annotation == provider_class.__class__:
obj = provider_class
self.fire_hook('resolve', parameter, obj)
return obj
elif inspect.isclass(provider_class) and issubclass(provider_class, parameter.annotation):
elif inspect.isclass(provider_class) and issubclass(provider_class, parameter.annotation) or issubclass(provider_class.__class__, parameter.annotation):
obj = provider_class
self.fire_hook('resolve', parameter, obj)
return obj
Expand Down
29 changes: 20 additions & 9 deletions masonite/auth/Sign.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" Cryptographic Signing Module """
import binascii

from cryptography.fernet import Fernet

from masonite.exceptions import InvalidSecretKey
Expand All @@ -10,11 +12,11 @@ class Sign:

def __init__(self, key=None):
"""Sign constructor
Keyword Arguments:
key {string} -- The secret key to use. If nothing is passed it then it will use
the secret key from the config file. (default: {None})
Raises:
InvalidSecretKey -- Thrown if the secret key does not exist.
"""
Expand All @@ -26,34 +28,43 @@ def __init__(self, key=None):
self.key = application.KEY

if not self.key:
raise InvalidSecretKey("The encryption key passed in is: None. Be sure there is a secret key present in your .env file or your config/application.py file.")
raise InvalidSecretKey(
"The encryption key passed in is: None. Be sure there is a secret key present in your .env file or your config/application.py file.")

self.encryption = None

def sign(self, value):
"""Sign a value using the secret key.
Arguments:
value {string} -- The value to be encrypted.
Returns:
string -- Returns the encrypted value.
Raises:
InvalidSecretKey -- Thrown if the secret key has incorrect padding.
"""

f = Fernet(self.key)
try:
f = Fernet(self.key)
except (binascii.Error, ValueError):
raise InvalidSecretKey(
"You have passed an invalid secret key of: {}. Make sure you have correctly added your secret key.".format(self.key))

self.encryption = f.encrypt(bytes(value, 'utf-8'))
return self.encryption.decode('utf-8')

def unsign(self, value=None):
"""Unsigns the value using the secret key.
Keyword Arguments:
value {string} -- The value to be unencrypted. (default: {None})
Returns:
string -- Returns the unencrypted value.
"""

f = Fernet(self.key)

if not value:
Expand Down
9 changes: 8 additions & 1 deletion masonite/contracts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@
from .MailContract import MailContract
from .QueueContract import QueueContract
from .SessionContract import SessionContract
from .UploadContract import UploadContract
from .UploadContract import UploadContract

from .managers.BroadcastManagerContract import BroadcastManagerContract
from .managers.CacheManagerContract import CacheManagerContract
from .managers.MailManagerContract import MailManagerContract
from .managers.QueueManagerContract import QueueManagerContract
from .managers.SessionManagerContract import SessionManagerContract
from .managers.UploadManagerContract import UploadManagerContract
5 changes: 5 additions & 0 deletions masonite/contracts/managers/BroadcastManagerContract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from abc import ABC


class BroadcastManagerContract(ABC):
pass
5 changes: 5 additions & 0 deletions masonite/contracts/managers/CacheManagerContract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from abc import ABC


class CacheManagerContract(ABC):
pass
5 changes: 5 additions & 0 deletions masonite/contracts/managers/MailManagerContract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from abc import ABC


class MailManagerContract(ABC):
pass
5 changes: 5 additions & 0 deletions masonite/contracts/managers/QueueManagerContract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from abc import ABC


class QueueManagerContract(ABC):
pass
5 changes: 5 additions & 0 deletions masonite/contracts/managers/SessionManagerContract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from abc import ABC


class SessionManagerContract(ABC):
pass
5 changes: 5 additions & 0 deletions masonite/contracts/managers/UploadManagerContract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from abc import ABC


class UploadManagerContract(ABC):
pass
15 changes: 10 additions & 5 deletions masonite/drivers/MailSmtpDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ def send(self, message_contents=None):
message.attach(message_contents)

# Send the message via our own SMTP server.
s = smtplib.SMTP('{0}:{1}'.format(config['host'], config['port']))
s.login(config['username'], config['password'])
if 'ssl' in config and config['ssl'] is True:
self.smtp = smtplib.SMTP_SSL('{0}:{1}'.format(config['host'], config['port']))
else:
self.smtp = smtplib.SMTP('{0}:{1}'.format(
config['host'], config['port']))

# s.send_message(message)
s.sendmail(self.config.FROM['name'],
self.smtp.login(config['username'], config['password'])

# self.smtp.send_message(message)
self.smtp.sendmail(self.config.FROM['name'],
self.to_address, message.as_string())
s.quit()
self.smtp.quit()
Binary file modified masonite/facades/__pycache__/Auth.cpython-36.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion masonite/info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Module for specifying the Masonite version in a central location.
"""

VERSION = '2.0.19'
VERSION = '2.0.20'
3 changes: 2 additions & 1 deletion masonite/managers/BroadcastManager.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
""" Broadcast Manager Module """

from masonite.contracts import BroadcastManagerContract
from masonite.managers import Manager


class BroadcastManager(Manager):
class BroadcastManager(Manager, BroadcastManagerContract):
"""Manages all broadcast drivers.
Arguments:
Expand Down
Loading

0 comments on commit a093b7f

Please sign in to comment.